diff ch3ex4.py @ 13:be7f2cd15faf

Completing Ch 3.4 exercise 4.1.
author Brian Neal <bgneal@gmail.com>
date Mon, 10 Dec 2012 19:42:38 -0600
parents b75bf8bfa2cf
children bc2c07a059be
line wrap: on
line diff
--- a/ch3ex4.py	Mon Dec 10 19:36:47 2012 -0600
+++ b/ch3ex4.py	Mon Dec 10 19:42:38 2012 -0600
@@ -42,6 +42,10 @@
         for i in range(n):
             self.maps.append(LinearMap())
 
+    def __len__(self):
+        """Returns the number of LinearMap buckets in the map."""
+        return len(self.maps)
+
     def find_map(self, k):
         """Finds the right LinearMap for key (k)."""
         index = hash(k) % len(self.maps)
@@ -78,7 +82,7 @@
 
     def add(self, k, v):
         """Resize the map if necessary and adds the new item."""
-        if self.num == len(self.maps.maps):
+        if self.num == len(self.maps):
             self.resize()
 
         self.maps.add(k, v)