1.1 --- a/lib/__builtins__/mapping.py Sat Feb 04 22:26:23 2017 +0100
1.2 +++ b/lib/__builtins__/mapping.py Sun Feb 05 00:25:59 2017 +0100
1.3 @@ -43,23 +43,26 @@
1.4
1.5 return buckets
1.6
1.7 - def _get_entry(self, key):
1.8 + def _get_entry(self, buckets, key):
1.9
1.10 - "Return the index and entry index as a tuple for 'key'."
1.11 + "Return the index and entry index as a tuple in 'buckets' for 'key'."
1.12
1.13 # Find an index identifying the bucket involved.
1.14
1.15 - index = self._get_index(key)
1.16 + index = self._get_index(buckets, key)
1.17
1.18 # Find the entry index within the bucket of the key.
1.19
1.20 - i = self._find_entry(key, index)
1.21 + i = self._find_entry(buckets, key, index)
1.22
1.23 return index, i
1.24
1.25 - def _get_index(self, key):
1.26 + def _get_index(self, buckets, key):
1.27
1.28 - "Check 'key' and return an index or raise TypeError."
1.29 + """
1.30 + Find in 'buckets' the given 'key', returning an index or raising
1.31 + TypeError.
1.32 + """
1.33
1.34 index = key.__hash__()
1.35
1.36 @@ -68,10 +71,12 @@
1.37
1.38 return index % len(self.buckets)
1.39
1.40 - def _find_entry(self, key, index):
1.41 + def _find_entry(self, buckets, key, index):
1.42
1.43 """
1.44 - Search for 'key', using an 'index' identifying the bucket involved.
1.45 + Search in 'buckets' for 'key', using an 'index' identifying the bucket
1.46 + involved.
1.47 +
1.48 Method to be overridden by subclasses.
1.49 """
1.50
1.51 @@ -107,6 +112,17 @@
1.52
1.53 pass
1.54
1.55 + # Public special methods.
1.56 +
1.57 + def __len__(self):
1.58 +
1.59 + "Return the number of items in the mapping."
1.60 +
1.61 + n = 0
1.62 + for bucket in self.buckets:
1.63 + n += bucket.__len__()
1.64 + return n
1.65 +
1.66 # Public conventional methods.
1.67
1.68 def clear(self):