|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object
|
+--org.abora.gold.java.AboraHeaper
|
+--org.abora.gold.xpp.basic.Heaper
|
+--org.abora.gold.collection.sets.ScruSet
|
+--org.abora.gold.collection.sets.MuSet
|
+--org.abora.gold.collection.sets.HashSet
The HashSet class is an implementation of a MuTable set that can contain arbitrary
Heapers. It uses the hashForEqual member function to get a hash value for the items
contained in the set. The set establishes the equality of objects in the set through the
isEqual: function.
The implemention of HashSet is straightforward. There are primitive tables used to store
pointers to the stored items (myHashEntries), and their corresponding hash values
(myHashValues). The HashSet also maintain a current tally of the number of items in the
set.
definition: preferred location - the location calculated from item hashForEqual mod
tableSize.
The search routine first calculates the preferred location. This is used as the first
location in the myHashEntries table to test for the presence of the item, and the search
proceeds forward (in a linear probe) from there. If there is no object at that position,
the routine assumes the item is not in the table. If there is an item there, the first
test is to check if the item''s hash matches the hash myHashValues at that position. If
the match is successful, a full isEqual: test is performed. If the isEqual: test
succeeds, the item is present in the set. If either test fails, the entry at the desired
location is tested to see if it is closer to its own preferred location than the item (a
test which necessarily fails the first time). If it is closer, the item is not in the
set. (This extra test is what distinguishes an ordered hash set from an ordinary hash
set. It often detects the absense of an item well before an empty slot is encountered,
and the advantage becomes pronounced as the set fills up. Ordered hash sets with linear
probe beat ordinary hash sets with secondary clustering on misses (the big time eater),
yet they preserve linear probe''s easy deletion.)
On insertion to the set, the hash and probe sequence is essentially the same as the
search. The main exception is that on a hash collision, the item bumps down any item that
is no farther than its own preferred position.
An example is perhaps in order:
the set contains items a, b, and c in table locations 3, 4, and 5. Assume that a has
location 2 as its preferred location, while b and c both have location 4 as their
preferred location. Now, if we attempt to add an item d to the table, and item d were to
have a preferred location of 3. Since 3 is already occupied by something that is already
far from its preferred location, we probe for a another location. At location 4, item d
is displaced by one from its preferred location. Since b is in it''s preferred location
(4) d replaces it, and we move item b down. Item c is in location 5 because it had
already been bumped from location 4 when b was inserted previously. B again ties with c,
so it pushes it out of location 5, replacing it there. Item c will end up in location 6.
This probe function minimizes the individual displacement of hash misses, while keeping
the most items in their preferred locations.
Note that, though the choice of which item to bump is obvious when the distances from home
are different, when they are equal we could have given preference to either the new or the
old item. We chose to put the new item closer to its preferred location, on the
assumption that things entered recently are more likely to be looked up than things
entered long ago.
This algorithm was derived from a short discussion with Michael McClary (probably
completely missing his intended design - all mistakes are mine -- heh).
(Unfortunately, I wasn''t clear in the discussion. Since hugh was unavailable when I
discovered this, I''ve taken the opportunity to practice with Smalltalk and corrected both
the explanation and the code rather than sending him a clarification. -- michael)
| Field Summary |
| Fields inherited from class org.abora.gold.xpp.basic.Heaper |
AllBlasts, BecomeMap, GarbageCount, InGC, InitializedClasses, InitializingClasses, LastMemory, NextClientRequestNumber, NotOneElementSignal, PackageTable, PromiseNameTable, StringHashSBoxes |
| Fields inherited from class org.abora.gold.java.AboraHeaper |
ActiveClubs, CurrentAuthor, CurrentBertCanopyCache, CurrentBertCrum, CurrentChunk, CurrentGrandMap, CurrentKeyMaster, CurrentPacker, CurrentSensorCanopyCache, CurrentServer, CurrentSession, CurrentSessions, CurrentTrace, InitialEditClub, InitialOwner, InitialReadClub, InitialSponsor, InsideTransactionFlag |
| Constructor Summary | |
HashSet()
|
|
| Method Summary | |
ImmuSet |
asImmuSet()
Return an immu snapshot of my current state. |
MuSet |
asMuSet()
Return a Mu whose initial state is the same as my current state, but which will now deviate independently of me. |
ScruSet |
copy()
A new one whose initial state is my current state, but that doesn't track changes. |
IntegerVar |
count()
How many elements are currently in the set. |
boolean |
hasMember(Heaper someone)
Is someone a member of the set now? |
Stepper |
immuStepper()
|
void |
introduce(Heaper anElement)
Add anElement to my members, but only if it isn't already a member. If it is already a member, BLAST |
boolean |
isEmpty()
Whether it currently has any elements |
static Heaper |
make()
|
static Heaper |
make(Heaper something)
|
static Heaper |
make(IntegerVar someSize)
someSize is a non-semantic hint about how big the set might get. |
void |
printInternals(java.io.PrintWriter oo)
|
void |
remove(Heaper anElement)
Remove anElement from my members. |
Stepper |
stepper()
Returns a stepper which will enumerate all the elements of the set in some unspecified order |
void |
store(Heaper anElement)
Add anElement to my set of members. |
Heaper |
theOne()
Iff I contain exactly one member, return it. |
void |
wipe(Heaper anElement)
make anElement no longer be one of my members. |
| Methods inherited from class org.abora.gold.collection.sets.MuSet |
actualHashForEqual, fromStepper, initTimeNonInherited, isEqual, make, make, problems, restrictTo, storeAll, wipeAll |
| Methods inherited from class org.abora.gold.collection.sets.ScruSet |
asArray, asOrderedCollection, contentsEqual, contentsHash, dox, inspect, intersects, isEqual, isSubsetOf, printOn, printOnWithSimpleSyntax, printOnWithSyntax |
| Methods inherited from class org.abora.gold.java.AboraHeaper |
asOop, basicInspect, displayString, error, hack, halt, knownBug, mightNotImplement, REQUIRES, shouldImplement, shouldNotImplement, stubbleForSubclassResponsibility, thingToDo, willNotImplement |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public HashSet()
| Method Detail |
public boolean hasMember(Heaper someone)
ScruSet
hasMember in class MuSetpublic boolean isEmpty()
ScruSet
isEmpty in class MuSetpublic ScruSet copy()
ScruSet
copy in class MuSetpublic IntegerVar count()
ScruSet
count in class MuSetpublic Stepper stepper()
ScruSet
stepper in class MuSetpublic Heaper theOne()
ScruSet
theOne in class ScruSetpublic void introduce(Heaper anElement)
MuSet
introduce in class MuSetpublic void remove(Heaper anElement)
MuSet
remove in class MuSetpublic void store(Heaper anElement)
store in class MuSetpublic void wipe(Heaper anElement)
wipe in class MuSetpublic ImmuSet asImmuSet()
ScruSet
asImmuSet in class MuSetpublic MuSet asMuSet()
ScruSet
asMuSet in class MuSetpublic void printInternals(java.io.PrintWriter oo)
public Stepper immuStepper()
immuStepper in class MuSetpublic static Heaper make()
public static Heaper make(Heaper something)
public static Heaper make(IntegerVar someSize)
MuSet
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||