You could have the indexer remember the starting position of each letter in the alphabet, and emit a separate require-ready file of these positions. That would indeed cut the search down. Or you could sort the index by word length, and remember those starting positions.
Note that in either case, you're building an index, and have set one foot on the slippery slope towards a using DBM or SQL. Why not go all the way?
| [reply] |
I think that I would try using the a db just for the exercise, but I was going under the impression that the size of his file was small enough that implementing a db would have more overhead, and might not be worth the effort to learn a db module.
| [reply] |