1. Speeding up 'dictionary' search
- Posted by newphil82 Jul 20, 2016
- 1491 views
I coded a program that scanned a "dictionary" file for 100's of words. It was slow. The "dictionary" was vast, not perfectly sorted. I made a very simple copy program that "sorted" by the initial letter only. (Using 'lower' and 26 scans!) Then I set 'constants' for the start_at and stop_at bytes for each initial letter - for seek() and where(). Better!
But this seems to be of more general interest (unless I'm missing something!)?
1:- if equal(inword, dictionary_word) then ...
2:- if dictionary_word[2] = second_letter and equal(inword, dictionary_word) then ...
The added one-byte test actually IMPROVED the speed a bit! (Your speed tips, please?)
Phil
2. Re: Speeding up 'dictionary' search
- Posted by ghaberek (admin) Jul 20, 2016
- 1502 views
This is exactly what a map is for.
include std/map.e map my_dict = map:new() -- store some data map:put( my_dict, "key", "value" ) if map:has( my_dict, "key" ) then -- the key exists -- get some data object value = map:get( my_dict, "key" ) end if
-Greg
3. Re: Speeding up 'dictionary' search
- Posted by mattlewis (admin) Jul 20, 2016
- 1492 views
This is exactly what a map is for.
I would add that we updated the implementation for 4.1. It's now based on the same algorithm as python's dict object and is definitely faster than the original implementation.
Matt
4. Re: Speeding up 'dictionary' search
- Posted by jessedavis Aug 03, 2016
- 1393 views
I think maps are a very useful animal. For some applications it is useful to create a reverse map when one creates the map. This map-reverse map pair brings up the occasional need for a map type that allows for duplicate keys.