Re: The best lookup/hash model?
Re: The best lookup/hash model?
- Subject: Re: The best lookup/hash model?
- From: Nat! <email@hidden>
- Date: Thu, 31 Jan 2002 21:43:56 +0100
On Donnerstag, Januar 31, 2002, at 08:50 Uhr, Svensson, Conny wrote:
I need to implement some semi-database engine. What is the best way to
represent a table? I need to be able to get a record from it fast
by ID. Is
NSDictionary the way to go? Is it fast enough? It needs to support
up to 10
000 records. How fast it objectForKey: in this situation? Is there
a faster
solution? I assume hash table is the only way to do it, and if I have
understood it right NS Dictionary is a kind of hashtable. The
relational
glue will be represented by my business logic. I would also like
to be able
to look for fields inside a record, i.e. not only access the
record by its
ID (key). I assume I need to keep separate hash tables for this, like
database indicies. This would represent joining two tables with a
foreign
key.
Do you have any suggestions or comments to my thinking? Performance is
pretty important for me as it it needs to drive a UI in "real
time". What is
your expriences with this kind of things?
The suggestion I have is that you code up the trivial program to
create a NSDictionary with 10000 entries, then pick keys at random
and look up the value. Put the random pick lookup code in a loop
flanked by two NSLog statements. Then you have an estimate how many
lookups you can do in a second.
If that's too slow check out NSHashTable or CF<whatever>. If that's
too slow, then you need to roll your own.
Otherwise the idea sounds sane, though ultimately a bit cumbersome.
I would try to abstract this set of dictionaries into a table
object that does the management (id lookup, record insertion,
indexing)
Cheers
Nat!
------------------------------------------------------
Some people drink deep from the fountains of life, and
some just gargle. -- DLR