Skip to content

Commit

Permalink
Another bit of optimization. I think that's about all I can do with t…
Browse files Browse the repository at this point in the history
…his data structure.
  • Loading branch information
nrubin29 committed Oct 21, 2017
1 parent bbe5cb3 commit 2e46eb7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion common.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ class ImmutableIndexedDict:
def __init__(self, data):
self._keys = tuple(item[0] for item in data)
self._key_indices = {key: self._keys.index(key) for key in self._keys} # Caching indices cuts down on runtime.
self._len = len(self._keys)
self._data = dict(data)

def __getitem__(self, key):
return self._data[key]

def __len__(self):
return len(self._data)
return self._len

def index(self, key):
return self._key_indices[key]
Expand Down

0 comments on commit 2e46eb7

Please sign in to comment.