Sunteți pe pagina 1din 1

Report

Design of Data Structure


For this project, I used a hash table of lists with each node containing
vectors. Using about 20,000 buckets, I tried to uniformly distribute the symbol
s throughout the table. I used lists to account for any collisions in which more
than one symbol could be placed into the same bucket. The vectors inside the no
de kept track of the line numbers a certain symbol was declared in. I also had a
nother vector of pointers to vectors, which kept track of which scope the symbol
s were declared in. The pointers would point to the vector the symbol is from an
d would pop the symbols out of the vector when exiting the scope.
Time Complexity
In my implemetation, enterScope is constant time. Functions find and dec
lare are linear in the number of symbols in the same bucket. Lastly, exitScope i
s linear in the number of symbols declared in the scope.
Pseudocode
enterScope
push NULL onto the vector
increment scope count
exitScope
if we're in 0th scope
return false
while not null pointer
pop the symbol off the vector in the node
pop the pointer off the vector
pop the null pointer
decrement scope count
return true
declare
if not in a scope
enter scope
for the number of symbols in a bucket
if vector is empty
continue
if vector's name matches id
if declared in the scope already
return false
push a new declaration onto the vector
push the pointer to the vector onto the vector of pointe
rs
return true
if no symbols in the bucket
push new symbol onto the bucket
push a new declaration onto the vector
push the pointer to the vector onto the vector of pointers
return true
find
for number of symbols in a bucket
if vector is empty
return -1
if vector's name matches id
return the latest line number of the symbol

S-ar putea să vă placă și