Re: Faster datastructure for lookups wanted
- From: Robert Klemme <shortcutter@xxxxxxxxxxxxxx>
- Date: Fri, 08 Sep 2006 08:09:41 +0200
m94asr@xxxxxxxxx wrote:
Hi all,
maybe somebody can recommend me the right datastructure or
any other advice would be a big help.
My code spends most of its execution time doing lookups from
a hashtable with about 1M keys. The keys are strings and the values
are arrays of integers. Most of the time only of length 1.
I do not care how long the construction of the datastructure takes,
but the lookup should be as fast as possible.
xs.each{|x|
if found = hash[x]
#do sth. end
}
As others said already, a Hash is pretty much the fastest for the general case. How do your string keys look like? Maybe it is worth trying symbols instead of strings?
If you unveil a bit more about your application we might be able to come up with more suggestions.
Kind regards
robert
.
- References:
- Faster datastructure for lookups wanted
- From: m94asr
- Faster datastructure for lookups wanted
- Prev by Date: [CHALLENGE] better alias_method
- Next by Date: Sun hires JRuby developers.
- Previous by thread: Re: Faster datastructure for lookups wanted
- Next by thread: How to determine if a IP addresssis "local"?
- Index(es):
Relevant Pages
|
Loading