Re: cocoa-dev digest, Vol 2 #975 - 18 msgs
Re: cocoa-dev digest, Vol 2 #975 - 18 msgs
- Subject: Re: cocoa-dev digest, Vol 2 #975 - 18 msgs
- From: Kirk Kerekes <email@hidden>
- Date: Sun, 21 Jul 2002 11:10:21 -0500
On Sunday, July 21, 2002, at 12:01 AM, email@hidden
wrote:
Date: Sun, 21 Jul 2002 02:21:57 +0200
Subject: Dificult question.
From: Aidas <email@hidden>
To: <email@hidden>
I've tried to do a search for NSTableView(actualy I searched it's
datasource). My datasource has about 10000-20000 thousands records sorted
alphabeticaly. My search was working terible. It was so slow. Anyone has
expirience in doing fast search or has some ideas?
Suggestions:
Use one or more NSDictionaries as indexes for your data. This assumes that
your searches are relatively simple ones -- no wildcards, no partial hits,
no logical operators. Each NSDictionary entry would have a search-term as
its key, and an id pointing to the data object. NSDictionaries use a
reasonably decent hashing scheme, and as a result are pretty doggone quick.
If your data has multiple fields, use multiple dictionaries.
If your data has multi-word entries, and you want to find hits on
individual words, index the words individually in the dictionary, so that
multiple dictionary entries will point to a single data object. If you want
to have "completion", you can index partial words (for "Johnson", index
"Johns" and "Joh" as well as the whole word).
If your data is such that only a brute-force search will do, be sure to use
an NSEnumerator for a linear search. As your data is sorted in alphabetical
order, consider keeping NSRange markers to each letter section, or perhaps
each two-letter section (aa... , ab..., ac...) etc. This way you can search
just that range.
One attraction of the NSDictionary scheme is that once the index is built,
it is just a line of code to save it to disk -- particularly when
referenced as a part of a composite object also saved to disk. You won't
need to have the index rebuilt every time you load your data, and a few
utility routines will handle the updating required for adding and deleting
data.
Thanks
Aidas
_______________________________________________
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.