作者tinlans ( )
看板Programming
标题Re: [问题] 字串比较的问题
时间Fri Feb 23 09:46:49 2007
※ 引述《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:
[email protected]
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