Re: Dictionary or Array?
Re: Dictionary or Array?
- Subject: Re: Dictionary or Array?
- From: Lorenzo <email@hidden>
- Date: Sun, 15 Jun 2003 17:32:41 +0200
Yes,
that's true, but... if I need to search by the field *containing* a string?
For example, I want to retrive all the objects containing the word "Cocoa".
MAIN ARRAY
Index String
--------------------------
1 "I drink Cocoa"
2 "I Cocoa thus I am..."
3 "Cocoa is not chocolate"
Currently I make a simple (and slow) linear search...
In order to increase the speed I presume I should build an index of the
field, but sincerely I don't know how. I have only a vague idea like
building 2 new and parallel arrays like
INDEX ARRAYS
Index Word Records containing that word
------------------- ----------------------------
1 "am" record number 2
2 "chocolate" record number 3
3 "Cocoa" record number 1,2,3
4 "drink" record number 1
5 "I" record number 1,2
6 "is" record number 3
7 "not" record number 3
8 "thus" record number 2
So I make an hash lookup to the first array, I find the word "Cocoa" soon at
the index 3, then I get the values 1,2,3 from the index 3 of the second
array then I get the 1th, the 2nd and the 3rd objects from my Main Array.
Am I going on the right way? Or not?
Best Regards
------------
Lorenzo
email: email@hidden
>
From: Wade Tregaskis <email@hidden>
>
Date: Sat, 14 Jun 2003 10:13:37 +1000
>
To: zauhar <email@hidden>
>
Cc: Ben Dougall <email@hidden>, email@hidden, Lorenzo
>
<email@hidden>
>
Subject: Re: Dictionary or Array?
>
>
> You must have that reversed. A dictionary lookup requires a hash
>
> operation, an array lookup is simple arithmetic.
>
>
If you know the index of the item you want. If you don't, but do have
>
some kind of key - like a field name - then for more than 50 items (or
>
so) a hash lookup is going to be much faster than a linear search on
>
the array.
>
>
Wade Tregaskis
>
-- Sed quis custodiet ipsos custodes?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.