ãã©ã¤ï¼ããã«é åï¼ç°¡æ½ãã¼ã¿æ§é ï¼ã¨ STL ã³ã³ãã
以åå®è£ ããæ§ç¯é度éè¦ã®åçããã«é å (è¡¨ä¸ dda) ã®æ§ç¯é度ã Darts, darts-clone (0.32g beta5, 0.32e5), DASTrie (1.0), doar (0.0.10)ï¼ç°¡æ½ãã¼ã¿æ§é ãå©ç¨ãããã©ã¤ (tx 0.16) ï¼STL ã³ã³ãã (std::map, std::tr1::unordered_map) 辺ãã¨æ¯ã¹ã¦ã¿ãï¼ãã¼éåã¨ãã¦ã¯ï¼ä¸è¦æ¨¡ã§çãªéåï¼Wikipedia è±èªçè¨äºã¿ã¤ãã«ï¼ã¨å°è¦æ¨¡ã§å¯ãªéåï¼éµä¾¿çªå·è¾æ¸ï¼ãç¨ããï¼
====================================================================== Wikipedia-en è¨äºã¿ã¤ãã« | Build | Search | Search* | Size [bytes] ====================================================================== sorted keys Darts 0.32 | 13.869s | 0.529s | 6.650s | 552,547,920 darts-clone 0.32g | 6.499s | 0.611s | 5.792s | 258,735,104 darts-clone 0.32g v:1 | 16.625s | 0.748s | 6.191s | 95,080,448 *darts-clone 0.32e5 | 11.334s | 0.902s | 5.852s | 113,360,140 *darts-clone 0.32e5 v:1 | 10.806s | 0.829s | 5.519s | 87,122,880 darts-clone 0.32e5 huge| 3.866s | 0.531s | 5.927s | 147,491,712 *DASTrie 1.0 -c | NA | NA | NA | NA DASTrie 1.0 | 4.090s | 0.772s | 6.140s | 157,593,742 *doar 0.0.10 static | 8.341s | 0.648s | 5.538s | 123,000,249 -------------------------------------------------------------------- *doar 0.0.10 dynamic | +4.423s | 0.648s | 5.548s | +123,000,249 dda | 3.239s | 0.603s | 6.985s | 517,091,328 --------------------------------------------------------------------- map k:char* | 2.924s | 2.174s | 17.421s |(>163,859,393) map k:string | 10.513s | 5.763s | 27.332s |(>163,859,393) unordered_map k:char* | 6.048s | 1.975s | 3.574s |(>163,859,393) unordered_map k:string | 7.003s | 2.175s | 4.524s |(>163,859,393) -------------------------------------------------------------------- tx 0.16 | 14.046s | 25.926s | 69.734s | 87,520,717 ===================================================================== randomized keys doar 0.0.10 dynamic |+26.186s | 1.901s | 5.543s | +123,000,249 dda | 9.961s | 3.619s | 8.421s | 517,091,328 -------------------------------------------------------------------- map k:char* | 16.569s | 3.603s | 21.168s |(>163,859,393) map k:string | 26.542s | 8.050s | 30.219s |(>163,859,393) unordered_map k:char* | 6.151s | 3.545s | 3.592s |(>163,859,393) unordered_map k:string | 7.100s | 4.506s | 4.583s |(>163,859,393) -------------------------------------------------------------------- tx 0.16 | 35.183s | 27,029s | 69.673s | 87,520,717 ====================================================================== ====================================================================== éµä¾¿çªå·è¾æ¸ | Build | Search | Search* | Size [bytes] ====================================================================== sorted keys Darts 0.32 | 0.036s | 0.003s | 0.011s | 2,156,576 darts-clone 0.32g | 0.037s | 0.003s | 0.010s | 1,069,056 darts-clone 0.32g v:1 | 0.023s | 0.003s | 0.007s | 106,496 *darts-clone 0.32e5 | 0.164s | 0.004s | 0.012s | 1,154,676 *darts-clone 0.32e5 v:1 | 0.157s | 0.004s | 0.011s | 650,116 darts-clone 0.32e5 huge| 0.146s | 0.004s | 0.012s | 1,363,656 *DASTrie 1.0 -c | 2.396s | 0.006s | 0.015s | 1,248,609 DASTrie 1.0 | 2.586s | 0.007s | 0.017s | 1,411,783 *doar 0.0.10 static | 0.061s | 0.004s | 0.012s | 1,204,561 -------------------------------------------------------------------- *doar 0.0.10 dynamic | +0.097s | 0.004s | 0.012s | +1,204,561 dda | 0.024s | 0.004s | 0.012s | 2,129,920 -------------------------------------------------------------------- map k:char* | 0.043s | 0.030s | 0.074s | (>1,425,852) map k:string | 0.138s | 0.066s | 0.152s | (>1,425,852) unordered_map k:char* | 0.021s | 0.010s | 0.025s | (>1,425,852) unordered_map k:string | 0.035s | 0.012s | 0.038s | (>1,425,852) -------------------------------------------------------------------- tx 0.16 | 0.079s | 0.099s | 0.134s | 222,888 ===================================================================== randomized keys *doar 0.0.10 dynamic | +0.103s | 0.009s | 0.012s | +1,204,561 dda | 0.034s | 0.010s | 0.012s | 2,129,920 -------------------------------------------------------------------- map k:char* | 0.056s | 0.036s | 0.087s | (>1,425,852) map k:string | 0.131s | 0.088s | 0.162s | (>1,425,852) unordered_map k:char* | 0.026s | 0.022s | 0.025s | (>1,425,852) unordered_map k:string | 0.043s | 0.035s | 0.038s | (>1,425,852) -------------------------------------------------------------------- tx 0.16 | 0.137s | 0.102s | 0.137s | 222,888 ====================================================================== (compiled with gcc 4.5.0, -O2 -march=core2 -m64) (3/18 00:05; è²ã ããããã£ãã®ã§åå®é¨) (3/28 13:00; darts-clone 0.32g beta5 ã«æ´æ°) (4/6 14:00; STL ã³ã³ããã®æä½å¿ è¦ã¡ã¢ãªéããµã¤ãºã¨ãã¦è¡¨è¨) (7/26 02:00; dda ãå ¬éããã®ã§åè¨æ¸¬ï¼ã©ã¤ãã©ãªãã¨ã«ãã¼éåã®åãç°ãªãå ´å ã«ï¼å ¨ã©ã¤ãã©ãªç¨ã®ãã¼éåãç¨æãã¦ãããã©ã¤ã»ã³ã³ãããæ§ç¯ã㦠ããã¨ãããï¼åã©ã¤ãã©ãªã®ãã¼éåã®ã¿ç¨æããããã«å¤æ´ãã ï¼å ¨ä½çã«ãã£ãã·ã¥å¹çãæ¹åï¼ï¼tx ã®ã©ã³ãã é 追å å®é¨ã追å ï¼ æ¤ç´¢ãã¼ã®ã·ã£ãããªã³ã°ã«ã¡ã«ã»ã³ãã»ãã¤ã¹ã¿ãå©ç¨ï¼
ãã®ä»ã®æ§è½è©ä¾¡æ å ±ã¸ã®ãã¤ã³ã¿ï¼
- Google Code Archive - Long-term storage for Google Code Project Hosting.
- DASTrie: Static Double Array Trie
ãã¼ã«ã¯ç»é²é ã§åºæã®IDãã¬ã³ã¼ãã¨ãã¦æ ¼ç´ï¼Search* ã¯ã©ã³ãã é ã®æ¤ç´¢æéï¼'*' ãã¤ãããã®ã¯ãã¼ãæ°ã大ããå¶éãããå§ç¸® (BASE 3 bytes + CHECK 1 byte ã§è¡¨ç¾) ãå©ç¨ãã¦ããã®ã§ãµã¤ãºé¢ã§æå© (é常ã®ããã«é åã® 1/2ï¼BASE 4 byte + CHECK 1 byte ã®ããã«é åã® 4/5 ã®ãµã¤ãºã§æ¸ã; darts-clone 0.32g ãããã«é åã®ä¸è¦ç´ 㯠4 bytes ã ãï¼è¦ªã®ã¢ãã¬ã¹ããã® offset 㧠BASE ã表ç¾ãããã¨ã§ãã¼ãæ°ã®å¶éãåé¿ãã¦ãã)ï¼std::map, std::tr1::unordered_map (FNV) ã¯ãã¼ã char* 㨠std::string ã®å ´åãå®é¨ (ãã ãï¼char* ã®æ¹ã¯ï¼æ§ç¯æéã«æååã®ã¡ã¢ãªç¢ºä¿ãæéãå«ã¾ãã¦ããªãããæå©; ãã¼ã®å¤§å°ã»ç価å¤å®ã«ã¯ std::strcmp ãå©ç¨)ï¼ã¾ãï¼tx ã®ã¿ API ã®é½åä¸ï¼æ§ç¯æéã«ãã¡ã¤ã«ã¸ã®ä¿åæéãå«ãã§ããï¼
æ¯è¼ãã¦ãããã®ãå¤éãã¦ï¼ä½ã«æ³¨ç®ããã°è¯ãã®ãå°ãã ãããã以ä¸ã¾ã¨ãï¼
æ§ç¯é度
- ããã«é åã§ã¯åçã«ãã¼ã追å ãã dda ãã»ã¼æéï¼STL ã³ã³ããã§ã¯ hash ã¯è¿½å é åºã«ãããå®å®ï¼map ã¯è¿½å é åºã«å¼·ãå½±é¿ãåããï¼
- TAIL ãå®è£ ããããã«é åã¯ï¼å¯ãªãã¼éåããã®ãã©ã¤ã®æ§ç¯ã¯è¦æï¼ç¹ã« DASTrie ã§é¡èï¼ï¼
- doar (dynamic) ã¯å¯è±ªçã«é次追å ã§åé·ãªããã«é åãæ§ç¯ãã¦ï¼ä¿åæã«ããã«é åãåæ§ç¯ãããã¨ã§ãµã¤ãºãå§ç¸®ãã¦ããã®ã§ï¼doar (static) ã®æ§ç¯æéï¼ã¡ã¢ãªã追å ã§ä¿åæã«å¿ è¦ (+ ã¨è¡¨è¨ãã)ï¼
- std::string ã使ã£ãå ´åã« std::map ã®æ§ç¯é度ãå¤§å¹ ã«å£åãã¦ããã®ã¯ï¼è¦ç´ ã®ã³ãã¼ã®ã³ã¹ãã®å·®ã大ããããã§ï¼std::tr1::unordered_map ãã std::map ã®æ¹ãé度ã®ä½ä¸ã®åº¦åãã大ããã®ã¯ï¼ããã·ã¥è¡¨ã¨èµ¤é»æ¨ã®æ¡å¼µã®ä»æ¹ã®éãããï¼
- 注: ä¸è¨ã®å®é¨ã¯ï¼ãã¼éåãä¸ããããæã®é£æ³é åã®æ§ç¯æéã®ã¿ãè¨æ¸¬ãã¦ãããï¼STL ã³ã³ãããåçããã«é åã§ã¯ãã¼ã®é次追å ãå¯è½ã§ããï¼ãã¼ãå¤ãä¸æçã«ã³ã³ããã«ä¿åãããã½ã¼ãããå¿ è¦ããªãããï¼ãããã®å¦çã¯ä¸è¨ã®æ§ç¯æéã«ã¯å«ã¾ãã¦ããªãï¼ï¼å®éã®æ§ç¯æéã空éå¹çã®ç¹ã§ã½ã¼ãããããã¼éåãå ¥åã¨ããã©ã¤ãã©ãªã«å¯¾ãã¦æ¬è³ªçã«æå©ï¼
æ¤ç´¢é度
- ããã«é åã¯åºæ¬çã«ã¯æååä½ã§é åã¸ã®ã©ã³ãã ã¢ã¯ã»ã¹ãçºçãããã®ã®ï¼ãã£ãã·ã¥ãå¹ãéã hash ããææã«é«éãªæ¤ç´¢ãå¯è½ (æååã®èµ°æ»ãä¸åã§æ¸ã¿ï¼ç価æ§ã»è¡çªã®ãã§ãã¯ãå¿ è¦ç¡ããã; hash ã®å ´åã¯é常ï¼ãã¼å ¨ä½ãè¦ã¦ hash é¢æ°ãè¨ç®ãï¼ããã«ãã¼ã®ç価å¤å®ãè¡ã)ï¼å¾ã£ã¦ï¼ãã¼éåãå°ããã¨ããæ¤ç´¢é åºã«åããããå ´åï¼hash ããé«éãªæ¤ç´¢ãæå¾ ã§ããï¼ã¾ãï¼ãã¼ãæªç»é²ã®å ´åã¯ãã¼å ¨ä½ãèµ°æ»ãããã¨ããªãã®ã§ï¼ãã©ã¤ã辿ããªããªã£ãæç¹ã§çµäºï¼hash ããæå©ï¼ãã®ç¹ãèæ ®ããå¿ è¦ãããï¼ãã¼ã®æ¤ç´¢é »åº¦ãåãã£ã¦ããã¨ãã¯ï¼é©åãªç¬¦å·åãè¡ãï¼åãã¼ãã®é ç½®ã工夫ãããã¨ã§ãã£ãã·ã¥å¹çãæ¹åãããã¨ãã§ããï¼
- TAILï¼å ±éé¨åæ¨ä½µåï¼å ±éæ¥å°¾è¾ä½µå (TAIL ã®å§ç¸®) ãªã©ã§ããã«é åã®ãµã¤ãºãå§ç¸®ããã¨ï¼ä¸è¬çã«ãã£ãã·ã¥å¹çãä¸ããããï¼æ¤ç´¢é度ã¯æ¹åããï¼ã¾ãï¼TAIL ãå®è£ ããããã«é åã¯ï¼TAIL é¨åã§ãã£ãã·ã¥ãå¹ããã¨ãä¿è¨¼ãããã®ã§ï¼ãã¼ãçã§é·ãå ´åãï¼ã©ã³ãã é æ¤ç´¢æã«ã¯ç¹ã«æå©ï¼ãã ãï¼è¾æ¸é æ¤ç´¢æã«ã¯ TAIL ã¸ã®ã¢ã¯ã»ã¹æã«ãã£ãã·ã¥ãã¹ãèµ·ããããããæ¤ç´¢ãé ããªããã¨ãããï¼
- ã©ã³ãã é 追å æã® doar (dynamic) ã®æ¤ç´¢æéã¯åèï¼éçã«åæ§ç¯ããããã«é åã«å¯¾ããæ¤ç´¢æéï¼
- tx, map ã¯æ¤ç´¢é度éè¦ã®æã¯è«å¤ï¼
ãµã¤ãº
- ããã«é åã§ã¯ï¼darts-clone ã®å§ç¸®çãé«ãï¼ãã¼ãçãªã 0.32eç³» (å ±éæ¥å°¾è¾ä½µå)ï¼ãã¼ãå¯ãªã 0.32gç³» (å ±éé¨åæ¨ä½µå) ã使ãï¼
- å¤ãä¸è¦ãªã tx ãã darts-clone æ¹ãè¯ã (ã¬ã³ã¼ãã®å¤ã1ã§åºå®ããçµæãè¼ãã)ï¼ãã¼ãçãªã 0.32eç³»ï¼å¯ãªã 0.32g ç³»ãæå¹ï¼
- å¤ãå¿ è¦ãªå ´åã¯ï¼tx ã taijuãªã©ã®ç°¡æ½ãã¼ã¿æ§é ãã¼ã¹ã®ãã©ã¤ãè¯ãï¼ãã ï¼æªç»é²ãã¼ãæ¤ç´¢ããªãå ´å㯠bep ã§è¯ãããï¼
- [追è¨; 2010/04/06] ããã«é åã¨ã³ã³ããã§ã©ã¡ããã¡ã¢ãªãç¯ç´ã§ãããã¯ãã¼ã®åé·æ§ã«ä¾åããï¼å¤§éæã«è¨ãã¨ï¼STL ã³ã³ããã§ã¯ï¼ãã¼ä¸ã®ä¸æåã« 1 byte 使ããã¨ã«ãªããï¼ããã«é åã ã¨ï¼ï¼ä¸ãã¼ã辺ãï¼4, 5, or 8 bytes å¿ è¦ï¼TAIL ãå®è£ ãã¦ããã°ï¼ãã¼ã®å ±ææ°ã 1 ã®ãã¼ããã³ã³ããã¨åã 1 byte ã§æ ¼ç´ã§ããï¼ï¼å¾ã£ã¦ï¼å§ç¸®ãªãï¼TAIL ç¡ãã§ãã¼éã§ãã¼ãã®å ±æããªããã¼éåã ã¨ï¼4-8åã®ã¡ã¢ãªãæ¶è²»ãã (TAIL æããªãï¼æåã®æåã®æ¯ãåãã ãã«ãªãã®ã§ unordered_map ã¨ã»ã¼åã; ãã¼ã辺ãã®ãã¼ã®éè¤æ° x ã 1 < x < 4, 5, or 8 ã®ãã¼ãã°ããã ã¨ï¼å ±éé¨åæ¨å§ç¸®ããªãéãï¼ããã·ã¥ããã¡ã¢ãªå¹çã¯æªããªã)ï¼Wikipedia è±èªçã¿ã¤ãã«ã ã¨ï¼ãã¼æ°: 6890514ï¼ãã¼ãµã¤ãº: 136297337 bytes ãªã®ã§ï¼ãã¼ã¿ã®æ ¼ç´ã«å¿ è¦ãªãµã¤ãºã¯ã¬ã³ã¼ãã 4 bytes ã¨ããå ´åã§æä½ 136297337 + 4 * 6890514 = 163859393 bytes, éµä¾¿çªå·è¾æ¸ã ã¨ï¼ãã¼æ°: 118821, ãã¼ãµã¤ãº: 950568 bytes ãªã®ã§ï¼æä½ 950568 + 4 * 118821 = 1425852 bytes 以ä¸ã®ã¡ã¢ãªãå¿ è¦ã¨ãªãï¼è¡¨ã«è¼ãã¦ã¿ãã¨ï¼TAIL 㨠CHECK ã® 1 byte 表ç¾ãä½µç¨ããéçããã«é åã§ããã°ï¼STL ã³ã³ããããå°ãªãã¡ã¢ãªæ¶è²»ã§æ¸ã¿ãããªæãï¼ãã¼ãå¢ããã°å¢ããã»ã©ï¼ãã©ã¤ã®æ ¹ã«è¿ãã¨ããã§ã¯ãã¼ããå¤æ°ã®ãã¼ã§å ±æãããã®ã§ï¼TAIL ãå®è£ ãã¦ããã°ã¡ã¢ãªå¹çã¯è¯ãã¨èãã¦ããããï¼
åçããã«é
å (dda) ã®æ§ç¯é度ãéãã£ãã®ã§å®å¿ããï¼hash ã®ä»£æ¿ã¨ãã¦ã使ããã¬ãã«ï¼å§ç¸®ã¨ããããªãã¶ãéçããã«é
åã«æ¯ã¹ãã°æ§ç¯é度ã§ã¯æå©ãªã®ã ãã©ï¼ãã¼ãæ´åããã¦ãããã¨ãå©ç¨ãã¦ããªãã®ã§å¿
ãããéããªãã¨ã¯è¨ããªãï¼ã¡ãªã¿ã«éµä¾¿çªå·ã®ã©ã³ãã é 追å ã§æªä½¿ç¨è¦ç´ 0.1% æªæºã®ããã«é
åãé«éã«ä½ãã®ã¯çµæ§å¤§å¤ãªã®ã§ï¼æããã¯ã¨æã人ã¯ãã©ã¤ãã¦ã¿ã¦æ¬²ããï¼
éçããã«é
åãªãæ§ç¯é度ã¯ãã¾ãéè¦ã§ã¯ãªãã®ã§ï¼å§ç¸®ãå¼·å㪠darts-clone ãè¯ãï¼æ¤ç´¢é度ã¯ã©ãã大差ãªãã ãã©ï¼ãµã¤ãºãå°ããæ¹ããã£ãã·ã¥ã®è¦³ç¹ããã¯æå©ï¼ï¼æ°åã«ç¾ããæ§è½ã®éãã®ä»ã«ãã¤ã³ã¿ãã§ã¼ã¹ã®ä½¿ãæããï¼å¾®å¦ãªå¶éã®éãï¼key ã« \0 ã使ããã¨ãã¬ã³ã¼ãã®åã®å¶éçï¼ãããã®ã§ï¼ï¼ããããä½ããã®å§ç¸®ããµãã¼ãããéçããã«é
åã©ã¤ãã©ãªã®éã«ã¯ç¥çµè³ªã«ãªãã»ã©ã®æ§è½å·®ã¯ç¡ããï¼å¥½ã¿ã§é¸ã¶ã®ãåï¼è¶
大è¦æ¨¡ãªãã©ã¤ãæ§æããå ´åãï¼çµã¿è¾¼ã¿ãªã©ã§ã¡ã¢ãªã®å¶éãå³ããå ´åãé¤ãï¼ç°¡æ½ãã¼ã¿æ§é ãç¨ãããã©ã¤ã¯å¿
è¦ç¡ãããï¼
åçããã«é
åã¯æ´æ°ããµãã¼ãããé¢ä¿ä¸ï¼æ§ç¯æã« CHECK ã 1 byte ã«ããå§ç¸®ãé£ããï¼è¡çªæã«å¾ãã追å ãããã¼ãã常ã«ç§»åãããªãå¯è½ã ãï¼æªä½¿ç¨è¦ç´ æ°ãå¢ãããããªãããï¼çµå±ãµã¤ãºã大ãããªã£ããããï¼ä¾ãã°ä¸è¨ã®å®é¨ãã¼ã¿ã ã¨ï¼ã©ã³ãã é 追å ã§2ååå¾æ§ç¯ãé
ããªãï¼æªä½¿ç¨è¦ç´ æ°ãï¼ç¹ã«éµä¾¿çªå·è¾æ¸ã§ã¯ï¼é¡èã«å¢ãã; DoubleArray(3-3): BASEとCHECK配列圧縮 - sileのブログåç
§ï¼ï¼åæ§ã«ï¼1 byte ã® CHECK ãå©ç¨ããå
±éé¨åæ¨ä½µåãé次追å ã§ã¯é£ããï¼ãã ï¼BASE ãéãªããªãããã«ããã«é
åãæ§ç¯ããã°ï¼ä¿åæã« CHECK ãå§ç¸®ããã®ã¯ã«ã³ã¿ã³ï¼ä¸æ¹ã§ï¼TAIL ã®å®è£
ãå
±éæ¥å°¾è¾ã®ä½µåã¯åºæ¥ããã ãï¼TAIL é¨å㯠unary ãªã®ã§ TAIL ç¡ãã§ãããããé
ç½®ã³ã¹ãã¯ä½ããï¼TAIL ãçããªããã¨ãé »ç¹ã«ããããï¼æ³¨æããªãã¨ã¡ã¢ãªç¢ºä¿ã®ãªã¼ãã¼ããããç¡è¦åºæ¥ãªããããããªãï¼
[追è¨; 2010/03/28] darts-clone 0.32g ãæ´æ°ãã㦠(beta5)ï¼å¤ã®æå®ããªãã¨ãï¼build () ã®å¼æ°ã§ value ãçç¥ãã¦ï¼å ¨ã¦ã®ãã¼ã«åºæã®å¤ãä¸ããã¨ãï¼ã®æ§ç¯é度ãéããªã£ã¦ããã®ã§å®é¨çµæãæ´æ°ããï¼ã¤ãã§ã«ï¼value ãçç¥ã§ããã©ã¤ãã©ãªã¯å ¨ã¦çç¥ããããã«åãããï¼ï¼ãã¼ãæ°ãå¶éãããå§ç¸®ãç¨ãã 0.32e5 ã® DoubleArray ã§ï¼ã¬ã³ã¼ãã«åºå®å¤ã«ããå ´åã«ã¯ãµã¤ãºã大ããåæ¸ãããã®ã§ã¤ãã§ã«è¼ãã¦ãã (HugeDoubleArray ã«ã¤ãã¦ã¯ã»ã¨ãã©åæ¸ããã)ï¼