Esempio n. 1
0
class RedblackMap(object):
    """An implementation of a hashtable using a BetterMap
    backed by a red black tree"""

    def __init__(self):
        self.map = RedBlackTree()

        logging.basicConfig(
            format="%(levelname)-10s %(asctime)s %(filename)s %(lineno)d %(message)s",
            level=logging.DEBUG
        )
        self.log = logging.getLogger(sys.argv[0])

    def get(self, k):
        """Looks up the key (k) and returns the corresponding value,
        or raises KeyError if the key is not found."""
        return self.map.search_by_key(k)

    def add(self, k, v):
        """Resize the map if necessary and adds the new item."""
        kv = KeyVal(k, v)
        self.map.insert(kv)