Substring search in a sorted Map

K

kirthiganarayanan

Hi,
I have a sorted map with both the keys and the values as
strings...say emp id as the key and employee name as value. Now I enter
a search key say "Smith" and I need to find out all the values in the
map which contains the word "Smith". I can use Linear Search but when
the size of the map increases the performance decreases rapidly... is
there any other way to do it.......Please let me know ASAP.......

Thanks
Kirthiga
 
S

szewong

If you need to be able to do key word search, you need to index your
original map into another sorted map with a words being the key and the
key of the original map being the value as a linked list:

Original Map:
1 : John Smith
2 : Peter Smith
3 : Jane Smith

Keyword Index:
Jane: 3
John: 1
Peter: 2
Smith: 1 -> 2 -> 3


Sze
http://www.zerionconsulting.com
 
K

kirthiganarayanan

Hi,

This is OK if I need Smith exactly.....I may type in "Sm" or "Smi"
or just "S"...How will it work then?

Thanks
Kirthiga N
 
R

Roedy Green

I can use Linear Search but when
the size of the map increases the performance decreases rapidly... is
there any other way to do it.......Please let me know ASAP...

Use subMap(K fromKey, K toKey) to get a list of just the elements you
want in a sort of miniature TreeMap View.

Then you can iterate with a for:each over .values().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top