Re: adjustable array vs hash-table
- From: vanekl <vanek@xxxxxxx>
- Date: Wed, 30 Jan 2008 15:23:45 -0800 (PST)
On Jan 30, 10:09 pm, Slobodan Blazeski <slobodan.blaze...@xxxxxxxxx>
wrote:
I could use a hash-table or an adjustable array. Considering the keys
of the hash-table are equal to indices in the array 0.1.2.3.4...
functionality is the same. So which one is more efficient at
a. Expanding when new elements are added when container can't hold
them
b. Accessing elements via index / key.
thanks
Slobodan
Adjustable arrays should prove faster, and save memory (unless a
minimal perfect hash function is used).
1. If you can preallocate the expected number of array slots when the
array is first created, you minimize memory reallocations.
2. if your keys are really 0,1,2,3,..., then it sounds like you can
get around having to call a hash function (which saves time).
3. arrays are a little more cache-friendly than hash tables because
data is more localized/dense than if a bunch of pointers are used to
create the hash table.
4. side benefit: arrays give you some sort of ordering that standard
hash tables do not provide.
Lou
.
- References:
- adjustable array vs hash-table
- From: Slobodan Blazeski
- adjustable array vs hash-table
- Prev by Date: Re: adjustable array vs hash-table
- Next by Date: Re: adjustable array vs hash-table
- Previous by thread: Re: adjustable array vs hash-table
- Next by thread: Re: adjustable array vs hash-table
- Index(es):
Relevant Pages
|
|