2

I need to autocomplete the user's entries in an NSTextField and I use an NSArray to check if there is a match but the NSArray is about 100,000 objects so the matching takes a noticeable time.

The way I implemented this feature is more or less the same way like it's suggested here:

Autocomplete with twitter usernames in text field (cocoa)

Is there a way to make things faster? Does anyone know a better way?

Thanks a lot.

Community
  • 1
  • 1
uem
  • 713
  • 1
  • 7
  • 18
  • 1
    you should add example of how you are handling **completionsForPartialWordRange:indexOfSelectedItem:** This way people can make suggestions. Also, where are you reading these 100,000 names from? – Black Frog Mar 11 '13 at 21:38
  • The strings are read from a file into an array. – uem Mar 12 '13 at 08:40

2 Answers2

4

I have a class I wrote just for that called NDTrie (and NDMutableTrie), it's basicly a tree structure where the key for a node is the string all of its children begin with, it makes search for all words that begin with 'cat' for example quick because you just have to find the node for the key 'cat' and the enumerate over it and all of its children. As well as holding strings it can also hold any object.

Nathan Day
  • 5,981
  • 2
  • 24
  • 40
2

A comment on this answer linked to a Github repo for PJTernarySearchTree. You could give that a try.

Community
  • 1
  • 1
paulmelnikow
  • 16,895
  • 8
  • 63
  • 114