diff options
Diffstat (limited to 'lib/spack/llnl/util/lang.py')
-rw-r--r-- | lib/spack/llnl/util/lang.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/spack/llnl/util/lang.py b/lib/spack/llnl/util/lang.py index 4943c9df67..9821ec7416 100644 --- a/lib/spack/llnl/util/lang.py +++ b/lib/spack/llnl/util/lang.py @@ -266,10 +266,28 @@ def key_ordering(cls): @key_ordering -class HashableMap(dict): +class HashableMap(collections.MutableMapping): """This is a hashable, comparable dictionary. Hash is performed on a tuple of the values in the dictionary.""" + def __init__(self): + self.dict = {} + + def __getitem__(self, key): + return self.dict[key] + + def __setitem__(self, key, value): + self.dict[key] = value + + def __iter__(self): + return iter(self.dict) + + def __len__(self): + return len(self.dict) + + def __delitem__(self, key): + del self.dict[key] + def _cmp_key(self): return tuple(sorted(self.values())) |