in reply to question on B-tree
If you want to keep data that's retrievable by keys in sorted order, try using Tie::Hash::Sorted. It makes use of Perl's internal hash structures, but keeps the keys sorted. If you don't need the keys sorted, just use regular hashes.
Hashes give you the better access time for storage or retrieval elements than trees or similar structures (such as skip lists), though they do take up more memory. (However, in Perl, this doesn't matter as much since most Perl implementations of trees and similar structures use more memory anyway.)
If it's a matter of keeping the data in a file rather than memory, you could still use a hash but tie it to a DBM file.
Unless you have some very particular or peculiar needs, it's best to stick with Perl's native data structures. You'll have less to worry about in terms of code maintenance, and your code will be cleaner and easier to read.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: question on B-tree
by Anonymous Monk on Dec 02, 2004 at 13:22 UTC |