public class SequentialSearchST<Key,Value> extends java.lang.Object
A classe SequentialSearchST implementa uma tabela de símbolos (não ordenada) de pares (chave,valor) genéricos. Ela dá suporte aos métodos put(), get(), contains(), delete(), size(), e isEmpty() usuais.
Conventions: When associating a value with a key that is already in the symbol table, the old value is replaced with the new. Values cannot be null; setting the value associated with a key to null has the effect of deleting the key from the table.
Convenções: Quando associa um valor com uma chave que já está na tabela, o valor antigo é substituído pelo novo. Além disso, valores não podem ser null; atribuir null ao valor associado com uma chave tem o efeito de remover a chave da tabela.
This implementation uses a singly-linked list and sequential search. It relies on the equals() method to test whether two keys are equal. It does not call either the compareTo() or hashCode() method. The put() and delete() operations take linear time; the get() and contains() operations takes linear time in the worst case. The size(), and isEmpty() operations take constant time. Construction takes constant time.
Esta implementação usa uma lista ligada simples e busca sequencial. Ela depende do método equals() para verificar se duas chaves são iguais. Ela não invoca o método compareTo() nem o método hashCode(). As operações put() e delete() consomem tempo linear; as operações get() e contains() consomem tempo linear no pior caso. As operações size() e isEmpty() consomem tempo constante. A construção consome tempo constante.
For additional documentation, see Section 3.1 of "Algorithms, 4th Edition", by Robert Sedgewick and Kevin Wayne.
Para documentação adicional, veja a Seção 3.1 de "Algorithms, 4a edição" de Robert Sedgewick e Kevin Wayne.
Constructor and Description |
---|
SequentialSearchST()
Initializes an empty symbol table.
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(Key key)
Does this symbol table contain the given key?
|
void |
delete(Key key)
Removes the key and associated value from the symbol table
if the key is in the symbol table.
|
Value |
get(Key key)
Returns the value associated with the given key.
|
boolean |
isEmpty()
Is this symbol table empty?
|
java.lang.Iterable<Key> |
keys()
Returns all keys in the symbol table as an Iterable.
|
static void |
main(java.lang.String[] args)
Unit tests the SequentialSearchST data type.
|
void |
put(Key key,
Value val)
Inserts the (key, val) pair into the symbol table,
overwriting the old value with val
if the key is already in the symbol table.
|
int |
size()
Returns the number of (key, value) pairs in this symbol table.
|
public SequentialSearchST()
public int size()
public boolean isEmpty()
public boolean contains(Key key)
public Value get(Key key)
public void put(Key key, Value val)
public void delete(Key key)
public java.lang.Iterable<Key> keys()
public static void main(java.lang.String[] args)