tiny hash table
Cã§ã³ã¼ããæ¸ãã¦ããã¨ããã·ã¥ãã¼ãã«*1ã欲ãããªããã¨ãå¤ã ããã¾ããã¨ããããã§å°ããã®ãæ¸ãã¦ã¿ã¾ããã
ããã·ã¥ãã¼ãã«ã«ã¤ãã¦
ããã·ã¥ãã¼ãã«ã¯ããããã¼ãããã·ã¥é¢æ°ã使ã£ã¦ãããã³ã°ããããã«å¯¾å¿ããå¤ãé¢é£ä»ããããã®ãã¼ã¿æ§é ã§ããé£æ³é åã¨ãã¦ä½¿ãããããããã·ã¥ãããã¨å¼ã°ãããããã¾ããããã·ã¥é¢æ°ã«ãã£ã¦ãã¼ãã¤ã³ããã¯ã¹ã«å¤æãï¼ãããããã·ã¥ã¨å¼ã¶ï¼ãããã«å¯¾å¿ããé åã®è¦ç´ ï¼ã¹ãããã¾ãã¯ãã±ãã¨å¼ã°ããï¼ã«å¤ãå ¥ãã¦ããã¾ããããããã¡ã¢ãªã使ãã¾ããããã®åé«éã«åä½ãã¾ãã
æ¢ç´¢ã«ããã¦ãæ¨æ§é ãªã©ã®äºåæ¢ç´¢ããã¼ã¹ã¨ããå®è£
ã§ã¯ããã¼ã®æ¯è¼åæ°ãlog2(N)ã¨ãªãã¾ãããããã·ã¥ãã¼ãã«ã§ã¯å¤§æµãããããå°ãããªãã¾ããæ¯è¼åæ°ããããããå¤ããªããããªç¶æ³ãã¤ã¾ãè¡çªãå¤çºããç¶æ³ã§ã¯ãè¡çªãå¤çºããªããããªããã·ã¥é¢æ°ãé¸æãããããã±ãã大ããããããæ¨æ§é ãªã©äºåæ¢ç´¢ããã¼ã¹ã¨ããå®è£
ãç¨ãããªã©ã®åé¿çãããã¾ããã»ã¼Wikipediaãªå
容ã§ãã¿ã¾ããã
thtblã®ç¹å¾´
- ããã·ã¥é¢æ°ã¯èªåã§ç¨æãã
- ãã¼ããªã¥ã¼ã¯åããã«èªåã§ç®¡çãã
- å é¨ã«ã³ãã¼ãæããã«ãã¤ã³ã¿ã«ããåç §ã®ã¿è¡ã
- ç·å½¢æ¢æ»å(linear-probing)ã®ãªã¼ãã³ã¢ãã¬ã¹æ³(open-addressing)ã«ããè¡çªåé¿ãè¡ã
- å¤åç°å¢ä¾åããªã
- ãã±ãã溢ãããã§ãèªå伸é·ããªã
- ãã±ãã®ãµã¤ãºã¯ç´ æ°ã§ã¯ãªã2ã®Nä¹
- å·¡åãåè¦ç´ åé¤ãé ã
工夫ããã¨ãã
ãªã¼ãã³ã¢ãã¬ã¹æ³ã ã¨ããã¤ã³ã¿ã®ç®¡çã¨ã¯å¥ã«ããã®å¤ãã空ããåé¤æ¸ã¿ãã使ç¨ä¸ããåºå¥ããå¿ è¦ãããã¾ãããã¤ã³ã¿ã¨ä»ã«ãã¼ãã³ã°ç¨ã®ãã¼ã¿ãç¨æããã®ã¯é¢åã ãã¡ã¢ãªã使ãããã§å«ã ã£ãã®ã§ããã¤ã³ã¿ã®ã¢ãã¬ãã·ã³ã°ã®ä»çµã¿ãå©ç¨ãã¦ãã¤ã³ã¿ã®ã¿ã§ç®¡çãããã¨ã«ãã¾ããã大æµã®OSã§ã¯ãã«ã¼ãã«ã©ã³ãã¨ã¦ã¼ã¶ã©ã³ãã§ããããã¢ãã¬ã¹ç©ºéãåããã¦ãã¾ãã以ä¸ã®ãã¼ã¸ãè¦ãã¨ã大æµã®OSã§ã¯ã«ã¼ãã«ã©ã³ãã大ããçªå°ãå ãã¦ãããã¨ãåããã¾ãã
- http://www.alde.co.jp/information/linux/memoryoflinux.html
- http://technet.microsoft.com/ja-jp/windows/ee424286
ã¨ããããã§ã以ä¸ã®ããã«åºå¥ãããã¨ã«ãã¾ãããç§ã¯ã«ã¼ãã«ã©ã³ãã§åä½ãããã®ã¯æ¸ããªãã®ã§ã
- 空 â NULL
- åé¤æ¸ã¿ â 0xffffffff ã¾ã㯠0xffffffffffffffffLLU
- 使ç¨ä¸ â ä¸è¨ä»¥å¤
GNU hashtabã¨ããããã·ã¥ãã¼ãã«ã©ã¤ãã©ãªãä¼¼ããããªãã¨ããã¦ãã¦ãmallocãªã©ã¯1ãè¿ããªãã¨ããåæã®å
ã«å®è£
ããã¦ãã¾ããå°ããçªå°ã¯å¤§æµä½ããã®ã¢ããªã®ã¹ã¿ãã¯ã使ã£ã¦ããã®ã§ã確ãã«ãã®åæã¯ããã¦ãæç«ãããã§ããããã
å®è¡çµæ
ããã¤ãã®ããã·ã¥é¢æ°ãããã¤ãã®ãã±ãã®å¤§ããã§è¡çªããã¾ããã§æ¿å ¥ã ããã³ããã¼ã¯ãã¨ã£ã¦ã¿ã¾ãããè¡çªçã®ä½ãã ããæ§è½ã®æ±ºå®çè¦ç´ ã§ã¯ãªããæ¯è¼é¢æ°ã®ã³ã¹ããéè¦ãªè¦ç´ ã ããã¨ãããã¨ãããåããçµæã«ãªã£ã¦ãã¾ããã
128
string
searches: 128, collisions: 204 (1.593750%)
0.000243 [sec]
zackw
searches: 128, collisions: 416 (3.250000%)
0.000212 [sec]
FNV-1a
searches: 128, collisions: 51 (0.398438%)
0.000214 [sec]1024
string
searches: 1024, collisions: 5048 (4.929688%)
0.001869 [sec]
zackw
searches: 1024, collisions: 1920 (1.875000%)
0.001591 [sec]
FNV-1a
searches: 1024, collisions: 503 (0.491211%)
0.001523 [sec]8192
string
searches: 8192, collisions: 43510 (5.311279%)
0.013948 [sec]
zackw
searches: 8192, collisions: 51554 (6.293213%)
0.012849 [sec]
FNV-1a
searches: 8192, collisions: 3827 (0.467163%)
0.011939 [sec]16384
string
searches: 16384, collisions: 849376 (51.841797%)
0.042020 [sec]
zackw
searches: 16384, collisions: 38040 (2.321777%)
0.024676 [sec]
FNV-1a
searches: 16384, collisions: 6266 (0.382446%)
0.024592 [sec]32768
string
searches: 32768, collisions: 1692528 (51.651855%)
0.083191 [sec]
zackw
searches: 32768, collisions: 23370 (0.713196%)
0.047768 [sec]
FNV-1a
searches: 32768, collisions: 17951 (0.547821%)
0.049201 [sec]65536
string
searches: 65536, collisions: 2047008 (31.234863%)
0.141463 [sec]
zackw
searches: 65536, collisions: 121870 (1.859589%)
0.098748 [sec]
FNV-1a
searches: 65536, collisions: 45944 (0.701050%)
0.100855 [sec]1048576
string
searches: 1048576, collisions: 30468520 (29.057045%)
2.362834 [sec]
zackw
searches: 1048576, collisions: 3814406 (3.637701%)
1.755987 [sec]
FNV-1a
searches: 1048576, collisions: 515284 (0.491413%)
1.933815 [sec]
ãã®ä»
å®è£ ã«ãããåèã«ãããã¼ã¸ãªã©ã
- http://preshing.com/20110603/hash-table-performance-tests
- http://isthe.com/chongo/tech/comp/fnv/
- http://code.google.com/p/smhasher/
- http://www.nurs.or.jp/~sug/soft/super/hash.htm
- http://www.atmarkit.co.jp/news/analysis/200803/24/semi.html
- http://gcc.gnu.org/svn/gcc/trunk/include/hashtab.h
- http://gcc.gnu.org/svn/gcc/trunk/libiberty/hashtab.c