
class HashableMap(dict):
   """
   A dictionary that has a working hash function.  You should only
   modify it using the 'update' method.
   """
   def __init__(self, other):
      dict.__init__(self, other)
      self.updateHash()

   def update(self, other):
      dict.update(self, other)
      self.updateHash()

   def updateHash(self):
      self.savedHashCode = self.calculateHash()

   def calculateHash(self):
      hashCode = 0
      for (key, value) in self.iteritems():
         hashCode = hashCode ^ hash(key) ^ hash(value)
      return int(hashCode)

   def __hash__(self):
      return self.savedHashCode


