com.tagtraum.perf.datastructures
Class SkipList

java.lang.Object
  |
  +--java.util.AbstractMap
        |
        +--com.tagtraum.perf.datastructures.SkipList
All Implemented Interfaces:
java.util.Map

public class SkipList
extends java.util.AbstractMap

Realization of a SkipList. Note that this is not a complete realization of the Map interface, some methods aren't supported.

A SkipList is an alternative to a balanced tree like TreeMap. As this implementation is slower than the standard TreeMap it serves only educational/demonstrational purposes.

Version:
$Id: $
Author:
Hendrik Schreiber

Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Constructor Summary
SkipList()
          Constructs a new skip list with a capacity of 101 entries.
SkipList(int capacity)
          Constructs a new skip list optimized for the given capacity.
SkipList(int capacity, float probability)
          Constructs a new skip list optimized for the given capacity and probability.
 
Method Summary
 void clear()
           
 java.util.Comparator comparator()
          Returns the comparator used to order this map, or null if this map uses its keys' natural order.
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set entrySet()
          Not supported.
 java.lang.Object firstKey()
          Returns the first (lowest) key currently in this sorted map.
 java.lang.Object get(java.lang.Object key)
           
 java.util.SortedMap headMap(java.lang.Object toKey)
          Not supported.
 boolean isEmpty()
           
 java.lang.Object lastKey()
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 java.lang.Object remove(java.lang.Object key)
           
 int size()
          Returns the number of key-value mappings in this map.
 java.util.SortedMap subMap(java.lang.Object fromKey, java.lang.Object toKey)
          Not supported.
 java.util.SortedMap tailMap(java.lang.Object fromKey)
          Not supported.
 
Methods inherited from class java.util.AbstractMap
clone, equals, hashCode, keySet, putAll, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SkipList

public SkipList()
Constructs a new skip list with a capacity of 101 entries.


SkipList

public SkipList(int capacity)
Constructs a new skip list optimized for the given capacity.


SkipList

public SkipList(int capacity,
                float probability)
Constructs a new skip list optimized for the given capacity and probability.

Method Detail

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map
Overrides:
get in class java.util.AbstractMap

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map
Overrides:
put in class java.util.AbstractMap

remove

public java.lang.Object remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map
Overrides:
remove in class java.util.AbstractMap

size

public int size()
Returns the number of key-value mappings in this map.

Specified by:
size in interface java.util.Map
Overrides:
size in class java.util.AbstractMap
Returns:
the number of key-value mappings in this map.

firstKey

public java.lang.Object firstKey()
Returns the first (lowest) key currently in this sorted map.

Returns:
the first (lowest) key currently in this sorted map.
Throws:
java.util.NoSuchElementException - Map is empty.

lastKey

public java.lang.Object lastKey()

comparator

public java.util.Comparator comparator()
Returns the comparator used to order this map, or null if this map uses its keys' natural order.

Returns:
the comparator associated with this sorted map, or null if it uses its keys' natural sort method.

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map
Overrides:
isEmpty in class java.util.AbstractMap

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map
Overrides:
containsKey in class java.util.AbstractMap

clear

public void clear()
Specified by:
clear in interface java.util.Map
Overrides:
clear in class java.util.AbstractMap

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map
Overrides:
containsValue in class java.util.AbstractMap

entrySet

public java.util.Set entrySet()
Not supported.

Specified by:
entrySet in interface java.util.Map
Specified by:
entrySet in class java.util.AbstractMap

subMap

public java.util.SortedMap subMap(java.lang.Object fromKey,
                                  java.lang.Object toKey)
Not supported.


headMap

public java.util.SortedMap headMap(java.lang.Object toKey)
Not supported.


tailMap

public java.util.SortedMap tailMap(java.lang.Object fromKey)
Not supported.



Copyright © 2002 Hendrik Schreiber
http://www.tagtraum.com/performance/
This software can be distributed under LGPL