|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjdsl.core.ref.AbstractDictionary
jdsl.core.ref.HashtableDictionary
An implementation of Dictionary using a chaining hashtable. Elements are inserted at the front of each chain, to ensure a constant time bound (disregarding resizing overhead).
The chains have references to both the next and previous element in the chains to make remove(Locator) guaranteed constant time (again, disregarding resizing overhead).
In the time complexities listed for the methods, O(1) is constant time, O(N) is time proportional to the number of elements in the data structure, and O(C) is time proportional to the capacity of the data structure.
| Nested Class Summary |
| Nested classes inherited from class jdsl.core.api.InspectableDictionary |
InspectableDictionary.InvalidLocator |
| Field Summary |
| Fields inherited from interface jdsl.core.api.InspectableDictionary |
NO_SUCH_KEY |
| Constructor Summary | |
HashtableDictionary(HashComparator comp)
This constructor takes a Comparator which can determine if it can compare a key, and if two keys are equal, nothing more. |
|
HashtableDictionary(HashComparator comp,
int initCap)
This constructor takes a Comparator which can determine if it can compare a key, and if two keys are equal, nothing more, and an integer denoting the initial capacity. |
|
| Method Summary | |
boolean |
contains(Accessor acc)
O(1) |
ObjectIterator |
elements()
O(1) if structure *AND* elements haven't changed, O(N) otherwise. |
Locator |
find(Object key)
O(1) -- expected, O(N) worst case with excessive chaining. |
LocatorIterator |
findAll(Object key)
O(#elts with target key), worst case O(N) |
Locator |
insert(Object key,
Object value)
O(1) expected, O(N) if insertion pushes the size above the rehashing threshhold. |
boolean |
isEmpty()
O(1) |
ObjectIterator |
keys()
O(1) if structure hasn't changed, O(N) otherwise. |
LocatorIterator |
locators()
O(1) if structure hasn't changed, O(N) otherwise. |
Container |
newContainer()
O(1) |
void |
remove(Locator loc)
O(1) expected: strictly O(1) unless removal reduces size below the downhashing threshhold, in which case it is O(N) |
LocatorIterator |
removeAll(Object key)
O(#elts with target key) expected, worst case O(N) with excessive chaining, or if removeAll drops the size below the downhashing threshhold. |
Locator |
removeKey(Object key)
Removes the first element found with the given key from the hashtable. |
Object |
replaceElement(Accessor acc,
Object Element)
O(1) |
Object |
replaceKey(Locator loc,
Object key)
O(1) |
int |
size()
O(1) |
String |
toString()
O(N) human readable description of the contents of this dictionary, conforming to the Collections spec for key-element structures. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public HashtableDictionary(HashComparator comp)
public HashtableDictionary(HashComparator comp,
int initCap)
| Method Detail |
public final int size()
size in interface InspectableContainerpublic boolean isEmpty()
isEmpty in interface InspectableContainertrue if and only if the container is empty (holds
no elements)InspectableBinaryTree
public Object replaceElement(Accessor acc,
Object Element)
replaceElement in interface Containeracc - Accessor in this containerElement - to be stored at a
public Container newContainer()
newContainer in interface Containerpublic boolean contains(Accessor acc)
contains in interface InspectableContainer
public void remove(Locator loc)
throws InvalidAccessorException
remove in interface KeyBasedContainerloc - a locator in the container to remove
InvalidAccessorException - if the locator is not valid or
is not contained by this container
public Object replaceKey(Locator loc,
Object key)
replaceKey in interface KeyBasedContainerloc - the locator in the container whose key should be replacedkey - the new key to associate with loc.
public LocatorIterator locators()
locators in interface InspectableKeyBasedContainerpublic ObjectIterator keys()
keys in interface InspectableKeyBasedContainerpublic ObjectIterator elements()
elements in interface InspectableContainer
public LocatorIterator findAll(Object key)
throws InvalidKeyException
findAll in interface InspectableDictionarykey - The key to search for.
InvalidKeyException - if the specified key is not valid in
this containerpublic LocatorIterator removeAll(Object key)
removeAll in interface Dictionarykey - the key to search for
public Locator removeKey(Object key)
throws InvalidKeyException
InvalidKeyException - if the key cannot be compared
public Locator insert(Object key,
Object value)
throws InvalidKeyException
insert in interface KeyBasedContainerkey - the key associated with the specified element.value - the element to insert into the container.
InvalidKeyException - if key cannot be used
by this container
public Locator find(Object key)
throws InvalidKeyException
find in interface InspectableDictionarykey - The key mapped to search for.
Locator referring to the key-element pair
that was found, or NO_SUCH_KEY if it could not be found.
InvalidKeyException - if the specified key is not a valid
key in this container.InspectableDictionary.NO_SUCH_KEYpublic String toString()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||