|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpt.ua.base.Listable<K>
pt.ua.base.AssociativeArray<K,E>
pt.ua.base.HashTableChainingAssociativeArray<K,E>
public class HashTableChainingAssociativeArray<K,E>
Associative array module implemented with a closed address (chaining) hash table.
This type of associative memory does not allow the existence of several elements with
the same key (key repetition).
invariant: AssociativeArray
This class follows DbC(tm) methodology. Where possible, contracts are implement with JML and native's Java assert.
Constructor Summary | |
---|---|
HashTableChainingAssociativeArray()
Creates an empty associative array with an initial capacity of 1024 elements. |
|
HashTableChainingAssociativeArray(int expectedDim)
Creates an empty associative array dimensioned for an expected number of elements. |
Method Summary | |
---|---|
void |
clear()
Empties the associative array. |
AssociativeArray<K,E> |
deepClone()
Clones current list. |
boolean |
exists(K key)
Checks if key exists in the associative array. |
E |
get(K key)
Gets the element value associated with value key . |
Array<K> |
keysToArray()
Extracts all keys to an array. |
ImmutableList<K> |
keysToList()
Extracts all keys to an immutable list. |
void |
remove(K key)
Removes key and its associated element value from the array. |
void |
set(K key,
E elem)
Associates value elem with value key . |
int |
size()
The list total number of elements. |
Methods inherited from class pt.ua.base.AssociativeArray |
---|
copy, isFull, isLimited, maxSize, toArray, toList |
Methods inherited from class pt.ua.base.Listable |
---|
isEmpty |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HashTableChainingAssociativeArray()
ensures: isEmpty()
public HashTableChainingAssociativeArray(int expectedDim)
requires: expectedDim > 0
ensures: isEmpty()
expectedDim
- expected associative array maximum number of elementsMethod Detail |
---|
public AssociativeArray<K,E> deepClone()
Listable
ensures: \result.size() == size()
deepClone
in class AssociativeArray<K,E>
public void set(K key, E elem)
AssociativeArray
elem
with value key
.
If key did not exist, adds a new association, otherwise attaches existing
key to a new element value.
requires: key != null
ensures: exists(key)
ensures: get(key) == elem
ensures: \old(exists(key)) ==> (size() == \old(size()))
ensures: \old(!exists(key)) ==> (size() == \old(size()) + 1)
set
in class AssociativeArray<K,E>
key
- the keyelem
- the elementpublic E get(K key)
AssociativeArray
key
.
requires: key != null
requires: exists(key)
get
in class AssociativeArray<K,E>
key
- the key
public void remove(K key)
AssociativeArray
key
and its associated element value from the array.
requires: key != null
requires: exists(key)
ensures: !exists(key)
ensures: size() == \old(size()) - 1
remove
in class AssociativeArray<K,E>
key
- the key to be removedpublic boolean exists(K key)
AssociativeArray
key
exists in the associative array.
exists
in class AssociativeArray<K,E>
true
if key exists, false
otherwisepublic int size()
Listable
size
in class Listable<K>
public Array<K> keysToArray()
AssociativeArray
AssociativeArray.toArray()
.
ensures: \result.size() == size()
keysToArray
in class AssociativeArray<K,E>
public ImmutableList<K> keysToList()
AssociativeArray
AssociativeArray.toList()
.
ensures: \result.size == size()
keysToList
in class AssociativeArray<K,E>
public void clear()
AssociativeArray
ensures: isEmpty()
clear
in class AssociativeArray<K,E>
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |