Package dsa
Interface OrderedST<Key extends Comparable<Key>,Value>
-
- All Known Implementing Classes:
BinarySearchST
,BinarySearchTreeST
,RedBlackBinarySearchTreeST
public interface OrderedST<Key extends Comparable<Key>,Value>
This interface specifies the API for the ordered symbol table data structure.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Key
ceiling(Key key)
Returns the smallest key in this symbol table that is larger than or equal tokey
.boolean
contains(Key key)
Returnstrue
if this symbol table containskey
, andfalse
otherwise.void
delete(Key key)
Deleteskey
and the associated value from this symbol table.void
deleteMax()
Deletes the largest key and the associated value from this symbol table.void
deleteMin()
Deletes the smallest key and the associated value from this symbol table.Key
floor(Key key)
Returns the largest key in this symbol table that is smaller than or equal tokey
.Value
get(Key key)
Returns the value associated withkey
in this symbol table, ornull
.boolean
isEmpty()
Returnstrue
if this symbol table is empty, andfalse
otherwise.Iterable<Key>
keys()
Returns all the keys in this symbol table in sorted order.Iterable<Key>
keys(Key lo, Key hi)
Returns the keys in this symbol table that are in the interval[lo, hi]
in sorted order.Key
max()
Returns the largest key in this symbol table.Key
min()
Returns the smallest key in this symbol table.void
put(Key key, Value value)
Inserts thekey
andvalue
pair into this symbol table.int
rank(Key key)
Returns the number of keys in this symbol table that are strictly smaller thankey
.Key
select(int k)
Returns the key in this symbol table with the rankk
.int
size()
Returns the number of key-value pairs in this symbol table.int
size(Key lo, Key hi)
Returns the number of keys in this symbol table that are in the interval[lo, hi]
.
-
-
-
Method Detail
-
isEmpty
boolean isEmpty()
Returnstrue
if this symbol table is empty, andfalse
otherwise.- Returns:
true
if this symbol table is empty, andfalse
otherwise.
-
size
int size()
Returns the number of key-value pairs in this symbol table.- Returns:
- the number of key-value pairs in this symbol table.
-
put
void put(Key key, Value value)
Inserts thekey
andvalue
pair into this symbol table.- Parameters:
key
- the key.value
- the value.
-
get
Value get(Key key)
Returns the value associated withkey
in this symbol table, ornull
.- Parameters:
key
- the key.- Returns:
- the value associated with
key
in this symbol table, ornull
.
-
contains
boolean contains(Key key)
Returnstrue
if this symbol table containskey
, andfalse
otherwise.- Parameters:
key
- the key.- Returns:
true
if this symbol table containskey
, andfalse
otherwise.
-
delete
void delete(Key key)
Deleteskey
and the associated value from this symbol table.- Parameters:
key
- the key.
-
keys
Iterable<Key> keys()
Returns all the keys in this symbol table in sorted order.- Returns:
- all the keys in this symbol table in sorted order.
-
min
Key min()
Returns the smallest key in this symbol table.- Returns:
- the smallest key in this symbol table.
-
max
Key max()
Returns the largest key in this symbol table.- Returns:
- the largest key in this symbol table.
-
deleteMin
void deleteMin()
Deletes the smallest key and the associated value from this symbol table.
-
deleteMax
void deleteMax()
Deletes the largest key and the associated value from this symbol table.
-
floor
Key floor(Key key)
Returns the largest key in this symbol table that is smaller than or equal tokey
.- Parameters:
key
- the key.- Returns:
- the largest key in this symbol table that is smaller than or equal to
key
.
-
ceiling
Key ceiling(Key key)
Returns the smallest key in this symbol table that is larger than or equal tokey
.- Parameters:
key
- the key.- Returns:
- the smallest key in this symbol table that is larger than or equal to
key
.
-
rank
int rank(Key key)
Returns the number of keys in this symbol table that are strictly smaller thankey
.- Parameters:
key
- the key.- Returns:
- the number of keys in this symbol table that are strictly smaller than
key
.
-
select
Key select(int k)
Returns the key in this symbol table with the rankk
.- Parameters:
k
- the rank.- Returns:
- the key in this symbol table with the rank
k
.
-
size
int size(Key lo, Key hi)
Returns the number of keys in this symbol table that are in the interval[lo, hi]
.- Parameters:
lo
- lower key.hi
- higher key- Returns:
- the number of keys in this symbol table that are in the interval
[lo, hi]
.
-
-