1. Speeding up 'dictionary' search

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

new topic     » topic index » view message » categorize

2. Re: Speeding up 'dictionary' search

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

new topic     » goto parent     » topic index » view message » categorize

3. Re: Speeding up 'dictionary' search

ghaberek said...

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

new topic     » goto parent     » topic index » view message » categorize

4. Re: Speeding up 'dictionary' search

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.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu