ã¤ãã£ãLRUHash
ç§ã¯id:fistfvckãã(ã§ããã? ãåå確èªãã¦ãªãã£ãã®ã§ã¡ã¨ä¸å®)ã¨ä¸ç·ã«ã³ã¼ããæ¸ãã¾ãããä»æ§ã¯ãããªæãã
Hashã½ãã¤ã³ã¿ã¼ãã§ã¼ã¹ã欲ããã¨ã®è¦ä»¶ã ã£ãã®ã§[]
ã¨[]=
ãã¾ãã¯å®è£
(ä¸2ã¤ã®example)ããã®å¾100åã¨ããæ大å¤ãæãã§ã®LRUçæ©è½ãå®è£
ãã¦ã¿ã¾ãããå®éã®ã¹ãã¬ã¼ã¸ã¯ããµã¤ãã®Hashã¸ã®delegateã§ãç¶æ¿ãããã¢ãå¤ãã£ããã§ãããç§ãã¡ã¯ãã³ã¬ã¯is-a Hashãããªããããã¨ãããã¨ã§å§è²ã使ã£ã¦ã¿ããã¨ã«ãã¾ãããForwardableã¯åã便å©ã
ãã®ãããã®ãã¹ããæ¸ãã¦ã¿ãã¨ãLRUã½ãæ©è½ã¯ã¨=ã§ä½ãããã°è¯ãããã ããã¨ããã®ãå°åºããã¦ãã¾ããã¾ãããã¹ããæ¸ãã¦ã¿ãã¨ãå®éã®ã¯ã©ã¤ã¢ã³ãã¨ãã¦ã¯cacheããã¦ãã¦nilãªã®ãããããããã£ãã·ã¥ããã¦ããªãã®ããè¦ãããã«has_key?ç³»ã®ã¡ã½ããã欲ãããããã¨ãããã¨ãããã£ãã®ã§ããã£ã¡ãå§è²ãã¦ãã¾ãã
ã§ããããã¯ãã³ã¼ãã¯ä»¥ä¸ã§ãããã¡ããRuby 1.9ã§ãã¹ããã¦ãã¾ãã
https://gist.github.com/133521/82178f453987fff450b9a97ac7e689e0a43e15f0
é åºãä¿æãããHashãªãã¦æ°æã¡ããããããèãã¦ããææãç§ã«ãããã¾ãããã³ã¬ã¯ãããã«ä¾¿å©ãããã§ã¦ã ãã©ã
ãã®å¾ããããã¯ããªã¼ãã¼ã§ããid:t-wadaãããããRailsã§ä½¿ãããã®ã§1.8ã§åããªãããã¨ããææãããã ãã¾ããããããããã¦1.8ç¨ã«æ¸ãç´ããã®ã以ä¸ã®ã³ã¼ãã§ããä»æ§å¤æ´ã ã¼! ã¯ã¼ã³ã
ä¾å¤ç³»ã¨ãããããçãã¦ãã¾ãããRubyã£ã¦ç°¡åã«æ¸ãã¦ããã§ããã