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 / First Aid / April 2004

Tip: Looking for answers? Try searching our database.

Hash table bucket states

Thread view: 
Andy - 21 Apr 2004 20:22 GMT
Hi all,

I'm confused about Closed Hash Tables (i.e. where each bucket is
occupied by up to one entry).  I've read that each bucket in these
tables has three possible states;

never-occupied (if it has never been occupied)
occupied (if it is currently occupied)
formerly-occupied (if it previously contained an entry which has
previously
                  contained an entry but has not yet been replaced)

Why is it necessary to make the distinction between the first and the
last?  It seems that when an object is inserted into the hashtable, it
doesn't matter whether its key points to a "never-occupied" bucket or
a "formerly-occupied" bucket - as long as it doesn't point to an
occupied bucket.

Cheers,

Andy
Eric Sosman - 21 Apr 2004 20:55 GMT
> Hi all,
>
[quoted text clipped - 13 lines]
> a "formerly-occupied" bucket - as long as it doesn't point to an
> occupied bucket.

   (This isn't really a Java question -- it's about data
structures that aren't at all Java-specific.  Still ...)

   Insert object A in an empty hash table; it lands in its
"natural" bucket.  Now insert object B that happens to have
the same "natural" bucket.  B can't go there because that
bucket is already occupied by A, so B goes to some other,
second-choice bucket.

   Now delete object A, and then search for object B.  You
start by probing B's "natural" bucket, where A used to be.
B isn't there[*] because it went to its second-choice spot,
so you don't find B on the first probe.  Now: Do you stop,
or do you continue probing?  If you can't tell "never used"
from "used but vacated," you don't know what to do.

  [*]  This isn't necessarily true of all hash tables.  Some
    implementations do extra work when deleting objects,
    moving the colliders "closer" to their "natural"
    positions.  But in implementations where objects aren't
    shuffled around after being inserted, the first probe
    for B will find the emptied spot left by A.

   Any decent book on hashing will explain this; one oft-cited
(and much-feared, for reasons I've never understood) is "The Art
of Computer Programming, Volume III: Sorting and Searching" by
D.E. Knuth.

Signature

Eric.Sosman@sun.com

Andy - 22 Apr 2004 15:52 GMT
Thanks! That explanation helped a lot

>     (This isn't really a Java question -- it's about data
> structures that aren't at all Java-specific.  Still ...)

Sorry about off-topic question.  I couldn't find a more appropriate
group and since I'm implementing these data structures in java I
thought I'd post here.  If you recommend, I'll post a reference to the
code when I'm finished (since as far as I'm aware, Closed Hash Sets
don't come within the core java libs)

Andy


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.