Re: [問題] 字串比較的問題
※ 引述《abcdefghi ()》之銘言:
: 如果這 100 個指令是預定好的, 那可以事先用 hash function
: 算出這些指令的對映值, 然後放在 array 裡, 用 loop 去查,
: 或者直接寫成 switch 來加速也可以.
: 用 map 也是個不錯的方法, 不過 STL 的 map 是用 red-black tree
: 實作的, 在 travel tree 的時候, 也是直接比較原始字串, 跟一般講
: 的 associative array 並不相同, 如果指令個數真的很多的話, 還是
: 要注意一下.
這個其實已經在另一邊討論過了,
不過因為它的 query 時間是發生在跟使用者的互動期,
所以從 Amdahl's law 或 80/20 法則來看的話,
特別去改善它並不會獲得太多整體效能上的改善。
真的需要 associative array 的話,
loki lib 裡面已經有一個不錯的現成品,
叫做 AssocVector,
專門用在少量變動但大量查詢的需求上,
當然 SGI 的 hash_map 也是不錯的選擇。
--
Name: Tseng, Ling-hua E-mail Address: uranus@it.muds.net
School: National Tsing Hua University Department: Computer Science
Interesting: C++, Compiler, PL/PD, OS, VM, Large-scale software design
Researching: Software pipelining for VLIW architectures
Homepage: https://it.muds.net/~uranus
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.230.216.187
討論串 (同標題文章)
Programming 近期熱門文章
PTT數位生活區 即時熱門文章