Package org.biojava.nbio.structure.math
Class SymbolTable<Key extends Comparable<Key>,Value>
java.lang.Object
org.biojava.nbio.structure.math.SymbolTable<Key,Value>
- All Implemented Interfaces:
Serializable
,Iterable<Key>
public class SymbolTable<Key extends Comparable<Key>,Value>
extends Object
implements Iterable<Key>, Serializable
Sorted symbol table implementation using a java.util.TreeMap.
Does not allow duplicate keys.
This class represents an ordered symbol table. It assumes that
the elements are Comparable.
It supports the usual put, get, contains,
and delete methods.
It also provides ordered methods for finding the minimum,
maximum, floor, and ceiling.
The class uses the convention that values cannot be null. Setting the value associated with a key to null is equivalent to removing the key.
This implementation uses a balanced binary search tree. The add, contains, delete, minimum, maximum, ceiling, and floor methods take logarithmic time. Derived from http://introcs.cs.princeton.edu/java/44st/ST.java.html
For additional documentation, see Section 4.4 of Introduction to Programming in Java: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturn the smallest key in the table >= k.boolean
Is the key in the table?Delete the key (and paired value) from table.Return the largest key in the table <= k.Return the value paired with given key; null if key is not in table.iterator()
Return an Iterator for the keys in the table.keys()
Return an Iterable for the keys in the table.max()
Return the largest key in the table.min()
Return the smallest key in the table.void
Put key-value pair into the symbol table.int
size()
How many keys are in the table?Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
SymbolTable
public SymbolTable()Create an empty symbol table.
-
-
Method Details
-
put
Put key-value pair into the symbol table. Remove key from table if value is null. -
get
Return the value paired with given key; null if key is not in table. -
delete
Delete the key (and paired value) from table. Return the value paired with given key; null if key is not in table. -
contains
Is the key in the table? -
size
public int size()How many keys are in the table? -
iterator
Return an Iterator for the keys in the table. To iterate over all of the keys in the symbol table st, use the foreach notation: for (Key key : st).- Specified by:
iterator
in interfaceIterable<Key extends Comparable<Key>>
-
keys
Return an Iterable for the keys in the table. To iterate over all of the keys in the symbol table st, use the foreach notation: for (Key key : st.keys()). -
min
Return the smallest key in the table. -
max
Return the largest key in the table. -
ceil
Return the smallest key in the table >= k. -
floor
Return the largest key in the table <= k.
-