|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.ObjectDictionary<K,D>
Skiplist<K,D>
K - The type of the key. Must be comparable.D - The type of the data.public class Skiplist<K extends java.lang.Comparable<K>,D>
This class implements the Map-interface as skiplists. In
a skiplist each key-value element is inserted into the n lowest
lists. Here, n is determined randomly in a geometric distribution.
So, given a propability p with 0 < p < 1 a new key-value
element is inserted into n lists with propability
p * (1-p)n-1.
All standard operations like insertion, deletion, finding,
etc. need O(log n) time in average.
Comparable| Constructor Summary | |
|---|---|
Skiplist()
Creates a new empty skiplist with default geometric distribution (where p = 0.5). |
|
Skiplist(int r)
Creates a new skiplist with given random seed. |
|
Skiplist(int r,
double p)
Creates a new skiplist with given random seed and given probability p. |
|
| Method Summary | |
|---|---|
void |
delete(K k)
Deletes the key-data association for the given key in this skiplist in O(log n) in average. |
D |
find(K k)
Looks up the data associated to the key k. |
void |
insert(K k,
D d)
Associates the data d to the key k in this skiplist. |
boolean |
iselement(K k)
Checks whether the key is present in this skiplist (in O(log n) time in average). |
boolean |
isempty()
Returns whether this skiplist is empty (in constant time). |
Iterator<K,D> |
iterator()
Creates a new iterator over all associations between keys and data. |
void |
print()
Prints the map to stdout |
int |
size()
Returns the size of this skiplist (in constant time). |
| Methods inherited from class Dictionary |
|---|
array, simpleiterator |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Skiplist()
public Skiplist(int r)
r - The seed that is used to initialize the random number
generator for the created skiplist.
public Skiplist(int r,
double p)
r - The seed that is used to initialize the random number
generator for the created skiplist.p - The probability p as mentioned in the desription of the Skiplist-class.| Method Detail |
|---|
public void insert(K k,
D d)
insert in interface Map<K extends java.lang.Comparable<K>,D>insert in class Dictionary<K extends java.lang.Comparable<K>,D>k - The key to store.d - The data associated to the key k.Map.insert(Object, Object)public D find(K k)
find in interface Map<K extends java.lang.Comparable<K>,D>find in class Dictionary<K extends java.lang.Comparable<K>,D>k - The key for which the data should be found.
Map.find(Object)public boolean iselement(K k)
iselement in interface Map<K extends java.lang.Comparable<K>,D>iselement in class Dictionary<K extends java.lang.Comparable<K>,D>k - The key to look for.
Map.iselement(Object)public void delete(K k)
delete in interface Map<K extends java.lang.Comparable<K>,D>delete in class Dictionary<K extends java.lang.Comparable<K>,D>k - The key which should be deletedMap.delete(Object)public int size()
size in interface Map<K extends java.lang.Comparable<K>,D>size in class Dictionary<K extends java.lang.Comparable<K>,D>Map.size()public boolean isempty()
isempty in interface Map<K extends java.lang.Comparable<K>,D>isempty in class Dictionary<K extends java.lang.Comparable<K>,D>Map.isempty()public Iterator<K,D> iterator()
Map
iterator in interface Map<K extends java.lang.Comparable<K>,D>iterator in class Dictionary<K extends java.lang.Comparable<K>,D>Iterator over all keys with
associated data.public void print()
Map
print in interface Map<K extends java.lang.Comparable<K>,D>print in class Dictionary<K extends java.lang.Comparable<K>,D>
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||