Re: adjustable array vs hash-table
- From: Joost Diepenmaat <joost@xxxxxxxxx>
- Date: Thu, 31 Jan 2008 00:44:01 +0100
Slobodan Blazeski <slobodan.blazeski@xxxxxxxxx> writes:
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...
You may consider binary trees, too, if your indeces are sparse (though
from your description, I'm assuming they're not).
functionality is the same. So which one is more efficient at
a. Expanding when new elements are added when container can't hold
them
This probably depends on the implementation, but a natural
implementation of hash tables will probably be an array with some kind
of linked list for the buckets. Which means that growing a hash table
should have about the same overhead as growing an array + the overhead
of redistributing the elements over the buckets. So hash tables are
probably slower to grow. Whether that really makes a difference depends
on how many times you're actually growing.
b. Accessing elements via index / key.
Hash tables will never be faster than arrays, and arrays are probably a
lot easier to optimize for homogenous simple values too.
Joost.
.
- Follow-Ups:
- Re: adjustable array vs hash-table
- From: Jeronimo Pellegrini
- Re: adjustable array vs hash-table
- References:
- adjustable array vs hash-table
- From: Slobodan Blazeski
- adjustable array vs hash-table
- Prev by Date: Re: Paul Graham's Arc is released today... what is the long term impact?
- 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
|