Class NameToIndex
Construct a unique mapping of names to indices. Every time a new name
is inserted, it is assigned a new index. Indices start at 0 and
increment by 1. For example:
>>> n2n = nameToIndex()
>>> n2n.insert('n1')
>>> n2n.insert('n2')
>>> n2n.insert('n1') # has no effect since it is a duplicate
>>> n2n.lookup('n1')
0
>>> n2n.names()
['n1', 'n2']
|
|
|
insert(self,
name)
If name has been inserted before, do nothing. |
|
|
|
lookup(self,
name)
Returns the index associated with name . |
|
|
|
names(self)
Returns list of names that have been inserted so far, in the order
they were inserted. |
|
|
|
nextIndex
The next index to be allocated.
|
|
namesToNums
Dictionary mapping names to their assigned indices
|
|
namesList
List of names in order of insertion
|
If name has been inserted before, do nothing. Otherwise,
assign it the next index.
|
Returns the index associated with name . Generates an
error if it name has not previously been inserted.
|