Symbol Table Flashcards
what is the pair of things that a symbol table is made up of
key
value
why can keys not be allowed to be null
because get() will return null if the key isn’t present
should keys be changed once they’ve entered the abstract data type
no
basic methods that should be included in a basic symbol table APi
void put(key key, value val) value get(key key) boolean contains(key key) void delete(key key) boolean isEmpty() int size()
what types can keys and values be
any generic type so long as they are comparable
what three requirements make up equivalence relation
reflexive
symmetric
transistive
what does it mean if two objects are reflexive
x.equals(x) is true
what does it mean if two objects are symmetric
x.equals(y) iff y.equals(x)
what does iff mean
if and only if
what does it mean if two objects are transistive
if x.equals(y) and y.equals(z) then x.equals(z)
what does it mean for an object to be non null
x.equals(null) is false
default equality test in java
x == y
why is the deafault equality test not the optimal way to compare
compares references to objects, returns true if both variables point to the same object, otherwise false
This may not always be what we are seeking
How to speed up big compares
compare fields most likely to differ first
eg in dates, compare days before years
standard recipe for user-defined compare methods
reference equality?
check against null?
check that they are of the same type and cast?