Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

Substring search in a sorted Map

Thread view: 
kirthiganarayanan@yahoo.com - 27 Dec 2005 05:30 GMT
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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.