Next put them in a tree for faster lookups.
With a tree you'll be limited by the RAM. I advise to use a database.
Don't reinvent the wheel, put them in a SQLite table, and let the sql engine create the tree for you!
With a tree you'll be limited by the RAM. I advise to use a database.