• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Using incomplete key to get a value from map.

Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a problem where I have a lookup table of about 1,000,000 key/value pairs, and the ids that I have to find are not always exactly complete. Easier to show in an example:


Lookup Table
Key/ Value
-----/ ------------
EI:1234 / Val2
cIJKL:39D9/ Val3

One thing I tried was to nix everything after the colon in the key, but as you can see on the last one there is sometimes a character before the ID. One very inefficient way is to read them into parallel arrays and search through the keys for each ID I am trying to look up and use a string.contains(). But like I said there are approx. 1 million key/value pairs and this is just to slow...ran it for about 15 minutes and still wasn't finished. BTW, just thinking about iterating through the keys and doing my lookups in my ID list, but that list is 1500+ so that is less than ideal as well.

So does anyone have any other ideas on how I could complete these lookups?
Author and all-around good cowpoke
Posts: 13078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like you need the kind of data structure which spell checkers use to suggest possible words from partial words.

Here is a link to one open sources spell checker which might help inspire you.

On my planet I'm considered quite beautiful. Thanks to the poetry in this tiny ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic