Ïë·¨ÊÇÕâÑùµÄ£¬¸ù¾ÝÒ»¸öËæÊÖÊäÈëµÄÏç´åµØÃû£¬Æ¥Åä³öÆäÑϸñµÄÎ弶ÐÐÕþµØÖ·¡£ÀýÈçÊäÈëµÄ”ÎÞ¼«Ïض«ºî·»ÏçÄϳØÑô´åÖúÅ©µã“£¬±ãҪƥÅä³ö”ºÓ±±Ê¡-ʯ¼ÒׯÊÐ-ÎÞ¼«ÏØ-¶«ºî·»Ïç-ÄϳØÑô´å“¡£ºóÃæµÄÕâ¸öÎ弶µÄÐÐÕþµØÖ·ÊÇÒÑÖª´æÔÚÊý¾Ý¿âÀïµÄ¡£
´ó¸ÅµÄ˼·ÊÇÊ×ÏȽøÐзִʣ¬ÈçÉÏÃæµÄ·Ö³É”ÎÞ¼«ÏØ“£¬”¶«ºî·»Ïç“£¬”ÄϳØÑô´å“£¬È»ºóÔÙÆ¥Åä¿´ÓÐûÓаüº¬Õ⼸¸ö´ÊµÄÎ弶ÐÐÕþµØÃû¡£
µÚÒ»²¿·Ö£º·Ö´Ê
1.¹¹½¨·Ö´ÊµÄµØÃû×Öµä
Òª·Ö´ÊÊ×ÏÈÒªÓÐ×ֵ䡣ÕâÀïÎÒÃÇÒѾÃ÷È·¶¼ÊÇÐÐÕþµØÃû£¬ËùÒÔ¹¹½¨ÕâÑùµÄµØÃû×ֵ仹ÊǺܼòµ¥µÄ¡£»¹ÊÇÉÏÃæµÄÀý×Ó”ºÓ±±Ê¡-ʯ¼ÒׯÊÐ-ÎÞ¼«ÏØ-¶«ºî·»Ïç-ÄϳØÑô´å“£¬²ð·Ö³É”ºÓ±±Ê¡“£¬”ʯ¼ÒׯÊГ£¬”ÎÞ¼«ÏØ“£¬”¶«ºî·»Ïç“£¬”ÄϳØÑô´å“±ã¾Í¿É´æÈëµØÃû×ÖµäÁË¡£Õâ¸öµØÃû×ÖµäÊôÓÚÊǾ²Ì¬ÇÒ¿ÉÖظ´ÀûÓõģ¬Õⲿ·ÖÎÒ±ã¾ÍÔÚÊý¾Ý¿â¶Ë´¦ÀíÁË¡£
´´½¨µØÃû×Öµä±ínamedict
CREATE TABLE `namedict` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `name` COLLATE , PRIMARY KEY (`id`) )
Ö®ºóÍù±íÀï²åÈë¼Ç¼
` (name) ,,(substring_index(substring_index(village_name,,,(substring_index(substring_index(village_name,,,(substring_index(substring_index(village_name,,,(substring_index(substring_index(village_name,,,
ͳ¼ÆÁËһϵØÃû×Öµä±ínamedictÀï¹²¼Æ33Íò¶àÌõµÄ¼Ç¼¡£
2.·Ö´ÊÅжÏ
ÓÐÁ˵ØÃû×Öµä¾Í¿ÉÒÔ½øÐзִÊÅжÏÁË¡£±ÈÈç”ÎÞ¼«ÏØ“£¬ÄÃÕâ¸ö´Êµ½×ÖµäÀïÆ¥ÅäÒ»ÏÂÊÇ·ñ´æÔÚ£¬¾ÍÖªµÀÊÇ·ñÓÐÕâ¸öµØÃûÁË¡£¶ø”ÎÞ¼«Ïض«“ÔÚ×ÖµäÀïÊDz»´æÔڵģ¬ÄǾͿÉÒÔÖªµÀÕâ¸öµØÃûÊDz»´æÔڵģ¬¾Í²»ÄÜÕâÑù·Ö´ÊÁË¡£ÕâÀïÃæҪעÒâÆ¥ÅäʱÅжϵÄЧÂÊÎÊÌ⣬Ҫ±ÜÃâȫɨÃ裬²»ÄÜÿ´ÎÆ¥ÅäÅж϶¼°Ñ33ÍòÌõ¼Ç¼¶¼É¨ÃèÒ»±é£¬ÒòΪһ¸öÃû×ÖÊÇÒª¾¹ý¶à´ÎµÄ·Ö´ÊÅжϲÅÄܹ»µÃµ½½á¹ûµÄ¡£Ò²ÕýÊÇÕâ¸öÔÒò£¬ÎҰѵØÃû×ÖµäµÄËùÓÐÌõÄ¿¶¼¼ÓÔص½pythonµÄ±äÁ¿ÀïµÄ£¬ÕâÑùÄܹ»±ÜÃâ¶à´ÎµØºÍÊý¾Ý¿â½»»¥¡£
a.Ê×ÏÈÏȽøÐÐhashÅжÏ
°Ñ33ÍòÌõ¼Ç¼´æ·Åµ½pythonµÄ×Öµä±äÁ¿dictÀÄÇôͨ¹ýÒ»´ÎhashÅжϾÍÖªµÀÕâ¸öµØÃûÊÇ·ñ´æÔÚ¡£
b.È»ºóÔÙ½øÐз¶Î§É¨ÃèÅжÏ
ÎÒÃǶ¼ÖªµÀ”ʯ¼ÒׯÊГºÍ”ʯ¼Òׯ“ÊÇÒ»¸öÒâ˼£¬µ«ÊÇÔÚdictÀïÃæ´æ”ʯ¼ÒׯÊГ¶øÓÔʯ¼Òׯ“ȥƥÅäÊÇÆ¥Åä²»µ½µÄ£¬ÕâÀï¾ÍÐèÒªÓõ½·¶Î§É¨Ãè¡£
1)°Ñ33Íò¸öÃû×ÖÔÙ´æ·Åµ½Ò»¸ölistÀïÃ棬²¢ÒÔÒ»¶¨µÄ¹æÔò´ÓСµ½´óÅÅÐò£¬Èç[a1,a2,a3,a4,...,an],ÇÒ(a1<a2<a3<a4<...an)¡£
2)if x<a1 or x>an£¬ÄǾͱíʾx²»ÔÚlistµÄ·¶Î§ÀҲ¾Í±íʾx²»ÔÚÃû×Ö×ÖµäµÄ·¶Î§ÀÄǾͲ»Óÿ¼ÂÇÁË¡£
3)if not (x<a1 or x>an)£¬ÄÇô¿ÉÒÔÏȶÔÅÅÐòµÄÁбí½øÐзÖ×飬ÿ1000ÔªËظö×÷Ϊһ¸ö·Ö×é¡£ÒòΪÊǵÝÔöÅÅÐòµÄ£¬´Ó×îÓұߣ¨×î´óµÄ£©µÄ·Ö×鿪ʼ£¬¶Ôÿ¸ö·Ö×éµÄµÚÒ»¸öÔªËØ£¨Ã¿¸ö·Ö×éÖÐ×îСµÄÔªËØ£©½øÐбȽϡ£Èç¹ûСÓÚµÈÓÚÁËÕâ¸ö·Ö×éµÄµÚÒ»¸öÔªËØ£¬¾Í±íʾÁËÕâ¸öxÔÚÕâ¸ö·Ö×éµÄ·¶Î§Ö®ÄÚ¡£ÔÙÒÔÕâ¸ö·Ö×éµÄµÚÒ»¸öÔªËØΪ¿ªÊ¼£¬Ïòºó²éѯ¡£Èç¹ûx<=list[i]£¬ÄÇôi¾ÍÊÇÕâ¸ö·¶Î§µÄÆðµã£»Èç¹ûx>list[j],ÄÇôj¾ÍÊÇÕâ¸ö·¶Î§µÄÖյ㡣ÕâÖÖ·½Ê½Æäʵ¾ÍÊDzο¼ÁËÊý¾Ý¿âµÄË÷Òý·¶Î§²éÕÒËã·¨(B+Tree index range scan)£¬Ëä˵Ҳ²»Ëã¸ßЧ£¬µ«Ò²±ÈȫɨÃèÒªºÃºÜ¶àÁË¡£
3.·Ö´Ê
·Ö´ÊÒÔÁ½¸ö×ÖΪÆðµã¿ªÊ¼·Ö´Ê£¬ÒÔ“ÎÞ¼«Ïض«ºî·»ÏçÄϳØÑô´åÖúÅ©µã”ΪÀý£º
“ÎÞ¼«”ÊÇÒ»¸ö´Ê£¬“ÎÞ¼«ÏØ”ÊÇÒ»¸ö´Ê£¬“ÎÞ¼«Ïض«”²»ÊÇÒ»¸ö´Ê£¬ÄÇ°Ñ“ÎÞ¼«ÏØ”ÌáÈ¡³öÀ´ºóÃæµÄ“¶«ºî·»ÏçÄϳØÑô´åÖúÅ©µã”¼ÌÐø¡£Ö±µ½²ð·Ö³É“ÎÞ¼«ÏØ”£¬“¶«ºî·»Ï産¬“ÄϳØÑô´å”¡£
¶þ.¸ù¾Ý·Ö´Ê¶ÔÎ弶´åÃû½øÐÐÆ¥Åä
Õⲿ·ÖÆäʵҲºÜ¼òµ¥£¬Ö»ÒªÒ»ÌõSQLÓï¾ä¾ÍÄܸ㶨×îºóµÄÆ¥ÅäÁË£º
mysql; village_name ºÓ±±Ê¡row in set (0.62 sec)
ÕâÑùµÄÓï¾äÊDz»ÄÜ×ßË÷ÒýµÄÖ»ÄÜÈ«±íɨÃ裬²»¹ýºÃÔÚÈ«±íÒ²¾Í66Íò¶àÌõ¼Ç¼£¬×ܹ²¾Í¼¸Ê®MµÄ´óС£¬ÍêÈ«¿ÉÒÔ»º´æÔÚÊý¾Ý¿âµÄÄÚ´æÀïµÄ¡£
²»¹ý¼´±ãÈç´ËÒ²»¹ÊÇÓпÉÓÅ»¯µÄ¿Õ¼äµÄ¡£Ê×ÏÈ°ÑËùÓеÄ66Íò¸öÎ弶ÐÐÕþ´åÃû¶¼·Åµ½pythonµÄlistÀïÃ棬Æäºó¿ÉÒÔ²ÉÈ¡ÀàËÆÊý¾Ý¿âÈ«ÎÄË÷ÒýµÄ·½·¨¡£È«ÎÄË÷ÒýµÄÄѵãÔÚÓÚ·Ö´ÊÒÔ¼°stopwordµÄ¼ø¶¨£¬¶øÎÒÃÇÕâÀïµÄÌõÄ¿ÌìÈ»¾ÍÊÇÒѷִʺõģº”ºÓ±±Ê¡-ʯ¼ÒׯÊÐ-ÎÞ¼«ÏØ-¶«ºî·»Ïç-ÄϳØÑô´å“£¬Ò²²»´æÔÚstopword¡£ÕâÀïÎÒÃÇÐèÒª×öµÄÖ»ÊǼǼÏÂÿ¸ö´ÊËùÔÚÁбíµÄλÖ᣻¹ÊÇÉÏÃæÄǸöÀý×Ó£º
fullindex["ÎÞ¼«ÏØ"]=set([58414, 58415, 58416, 58417, 58418, 58419, 58420, 58421, 58422, 58423,...])
fullindex["¶«ºî·»Ïç"]=set([58445, 58446, 58447, 58448, 58449, 58450, 58451, 58452, ...])
fullindex["ÄϳØÑô´å"]=set([58460])
ÔÙ¶ÔÕ⼸¸ö¼¯ºÏ×ö½»¼¯²Ù×÷µÃµ½set([58460])£¬ÄÇlist[58460]¾ÍÊÇÎÒÃÇÒªÕҵēºÓ±±Ê¡-ʯ¼ÒׯÊÐ-ÎÞ¼«ÏØ-¶«ºî·»Ïç-ÄϳØÑô´å”¡££¨ÕâÀïµÃµ½µÄÊÇ×îºÃµÄÇé¿öÓÐÇÒ½öÓÐÒ»¸ö£¬Ò²ÓпÉÄÜ»áÓжà¸öÀýÈçֻдÁ˸ö“ºÓ±±”£¬ÄÇ»á°ÑºÓ±±Ê¡ËùÓеĴ嶼ƥÅä³öÀ´£»Ò²ÓпÉÄÜÒ»¸öҲûÓУ¬ÄǾÍÊǵØÃûдµÄ²»¶Ô£¬Ò»¸öҲƥÅä²»³öÀ´¡££©
Èý.ÔËÐÐÇé¿ö£º
1.Õ¼ÓÃÄÚ´æ
ÒòΪ¶ÔÓÚÊý¾Ý¿âµÄ²Ù×÷¾ÍÊÇ¿ªÊ¼µÄʱºò¼ÓÔØÁËÁ½·ÝÊý¾Ý£ºµØÃû×ֵ䣨33Íò£©ºÍÎ弶ÐÐÕþ´åÃû£¨66Íò£©£¬´ó²¿·ÖµÄ²Ù×÷¶¼ÊÇͨ¹ý´úÂëʵÏֵģ¬ËùÒÔ×îºóͳ¼ÆÁËϱȽÏÖØÒªµÄ¼¸¸öpython±äÁ¿ËùÕ¼ÓõÄÄڴ棺
´æ´¢µØÃû×ÖµäµÄÁÐ±í£º2678096
´æ´¢µØÃû×ÖµäµÄdict:12583184
´æ´¢Î弶´åÃûµÄÁÐ±í£º5429648
´æ´¢·Ö´ÊλÖõÄdict:12583184
×ܹ²¿´ÏÂÀ´³ÌÐòÔËÐдó¸Å»áÕ¼ÓÃ33M×óÓÒµÄÄÚ´æ¡£
2.»¨·Ñʱ¼ä
Õû¸ö³ÌÐòÔËÐÐÒ»´ÎÒª47Ãë×óÓÒ£¬ÆäÖдÓÊý¾Ý¿â¼ÓÔØÊý¾ÝµÄʱ¼ä±È½Ï³¤£¬´ó¸ÅÒª42Ã룬³ÌÐò½øÐзִÊÔÙ¶Ô´åÃû½øÐÐÆ¥Åä´ó¸ÅÓÃÁË5Ãë×óÓÒ¡£Èç¹û°Ñ³ÌÐò¸Ä³É·þÎñ¶ËµÄ£¬ÄÇÖ»ÒªÔÚÆô¶¯µÄʱºò¼ÓÔØÒ»´ÎÊý¾Ý¼´¿É¡£ÒªÊÇÔÚ·Ö´ÊÆ¥Åä´åÃû֮ǰÄܹ»È·ÈÏÊ¡·ÝµÄ»°£¬ÄÇÕâÒ»¶¯×÷¾ÍÄܽµµ½1Ãë×óÓÒ£¬¾Í»ù±¾Äܹ»Âú×ãÏßÉϲÙ×÷µÄÒªÇóÁË¡£
×îºó´óÖµĴúÂëÈçÏ£º
¡¡