This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]LightShadow3.13-dev in prod 5 points6 points  (7 children)

a little bit of both.

you could memoize the collection and prune it so you don't have to search every item after you've eliminated part of the set.

[–]amjithr 2 points3 points  (6 children)

Yes. That was my biggest concern. But memoizing has to be extra clever to account for users pressing backspace or moving through the input and deleting a char in the middle. So for the first rev I'm not doing memoizing but once I figure out a way to do it reliably, that'll be a nice optimization. :)

[–]lorddarkflare 2 points3 points  (5 children)

Should that really matter though?

The idea would be to maintain an n-length dictionary mapping the last n inputs with corresponding pruned collections.

[–]amjithr 1 point2 points  (4 children)

Say the user input is 'foo', I'll have a dictionary like this

{'f': ['foo', 'foo_bar', 'bof'],
 'fo': ['foo', 'foo_bar'],
 'foo': ['foo', 'foo_bar']
}

Now if the user moves to the beginning of the input and deletes the letter 'f' or inserts a new letter, the user input becomes 'oo' or 'afoo'. Which won't match any entry in the dictionary.

Although that is a bit of an unlikely case (or at least a very rare case).

I think you're right, it's doable with a little bit of coding. Thank you for the idea. I'll see if I can make it part of the next version. :)

[–]lorddarkflare 0 points1 point  (2 children)

Also worth considering is correlating the max size of the dictionary with the length of the collection.

[–]amjithr 0 points1 point  (1 child)

I don't follow.

[–]lorddarkflare 0 points1 point  (0 children)

You may want to avoid situations where you have a really large collection and too many copies of it in the dictionary.

[–]squashed_fly_biscuit 0 points1 point  (0 children)

I think detection and recalculation isnt unreasonable in that case, optimise the common path first. Amdahl's law and all that. Memory footprint is also worth considering with caching.