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
szewong@gmail.com - 27 Dec 2005 06:04 GMT
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
kirthiganarayanan@yahoo.com - 27 Dec 2005 06:28 GMT
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
> 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
[quoted text clipped - 13 lines]
> Sze
> http://www.zerionconsulting.com
Roedy Green - 27 Dec 2005 07:09 GMT
>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().

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.