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 / October 2006

Tip: Looking for answers? Try searching our database.

hashtable - select by wilecard... is it doable?

Thread view: 
tak - 27 Sep 2006 23:01 GMT
Hi,

What is a data structure out there, that you can select by wilecard,
and also have fast retrievals?

like, if i have 4 keys, JOHN, JONATHAN, JOAN, TOM., and I want to do a
getKey by, "JO*", and that would return the values for the one that
matches JO* as either array, set, collection..etc...

thanks,
T
Dan Andrews - 28 Sep 2006 01:14 GMT
> Hi,
>
[quoted text clipped - 7 lines]
> thanks,
> T

If you are only concerned about matching the first few characters
(starts with JO) then would a TreeSet<String> (that I refer to a treeSet
below) work?

    SortedSet<String> tailSet = treeSet.tailSet("JO");
    TreeSet<String> matchingSet = new TreeSet<String>();
    for (String s : tailSet) {
      if (!s.startsWith("JO")) {
        break;
      }
      matchingSet.add(s);
    }
    return matchingSet;

Just and idea and not sure if it is what you need.

Cheers,

Dan Andrews
- - - - - - - - - - - - - - - - - - - - - - - - -
Ansir Development Limited http://www.ansir.ca
- - - - - - - - - - - - - - - - - - - - - - - - -
Hendrik Maryns - 28 Sep 2006 09:10 GMT
Dan Andrews schreef:
>> Hi,
>>
[quoted text clipped - 23 lines]
>
> Just and idea and not sure if it is what you need.

He probably needs a TreeMap<String,Something>, but the principle remains
the same.

H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
Patricia Shanahan - 28 Sep 2006 16:11 GMT
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
[quoted text clipped - 30 lines]
> He probably needs a TreeMap<String,Something>, but the principle remains
> the same.

If it gets any more complicated than a TreeMap, it may be worth
separating the find-the-key-set problem from the map.

Patricia
Gordon Beaton - 28 Sep 2006 07:27 GMT
> What is a data structure out there, that you can select by wilecard,
> and also have fast retrievals?
>
> like, if i have 4 keys, JOHN, JONATHAN, JOAN, TOM., and I want to do a
> getKey by, "JO*", and that would return the values for the one that
> matches JO* as either array, set, collection..etc...

If you only need to match key prefixes, then use a radix tree (or one
of the many variants). In a radix tree, the key describes a path from
the root of the tree to the corresponding object.

When you follow the path described by a given prefix, you arrive at a
node whose key matches the prefix exactly, and whose entire subtree
consists of nodes whose keys start with that prefix.

/gordon

Signature

[ don't email me support questions or followups ]
g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e

Simon Brooke - 29 Sep 2006 22:31 GMT
> What is a data structure out there, that you can select by wilecard,
> and also have fast retrievals?
>
> like, if i have 4 keys, JOHN, JONATHAN, JOAN, TOM., and I want to do a
> getKey by, "JO*", and that would return the values for the one that
> matches JO* as either array, set, collection..etc...

It's doable, but it wouldn't be pretty or efficient:

       Vector result = new Vector();

       Enumeration foo = hash.keys();

       while ( foo.hasMoreElements())
       {
               String bar = foo.nextElement().toString();

               if ( bar.indexOf( pattern) > -1)
               {
                       result.append( hash.het( bar);
               }
       }

       return result;

If you want to go down this route you lose all the benefits you got from
the hashtable in the first place. But if you do want to go down it I
suggest it would be more flexible if you allowed regular expression rather
than just substring matching.

Signature

simon@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/
;; We don't just borrow words; on occasion, English has pursued other
;; languages down alleyways to beat them unconscious and riffle their
;; pockets for new vocabulary                      -- James D. Nicoll

Wibble - 01 Oct 2006 16:24 GMT
>> What is a data structure out there, that you can select by wilecard,
>> and also have fast retrievals?
[quoted text clipped - 25 lines]
> suggest it would be more flexible if you allowed regular expression rather
> than just substring matching.

You could use a String Trie such as describe in links below.  You'll
probably have to write a walking pattern matcher but its not rocket science.

http://www.limewire.org/nightly/javadocs/com/limegroup/gnutella/util/TrieSet.html

http://en.wikipedia.org/wiki/Patricia_trie

http://www.cs.duke.edu/~ola/courses/cps108/fall96/joggle/trie/Trie.java

http://www.koders.com/java/fid0F06E53F2CFCC6E591C38752F355A7178F92FFE5.aspx

http://www.stylusstudio.com/api/fop-0.20.5/org/apache/fop/layout/hyphenation/Ter
naryTree.htm

etc...


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



©2008 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.