How to use the immutables.map.Map function in immutables

To help you get started, we’ve selected a few immutables examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MagicStack / immutables / immutables / map.py View on Github external
def __init__(self, col=None, **kw):
        self.__count = 0
        self.__root = BitmapNode(0, 0, [], 0)
        self.__hash = -1

        if isinstance(col, Map):
            self.__count = col.__count
            self.__root = col.__root
            self.__hash = col.__hash
            col = None
        elif isinstance(col, MapMutation):
            raise TypeError('cannot create Maps from MapMutations')

        if col or kw:
            init = self.update(col, **kw)
            self.__count = init.__count
            self.__root = init.__root
github MagicStack / immutables / immutables / __init__.py View on Github external
try:
    from ._map import Map
except ImportError:
    from .map import Map
else:
    import collections.abc as _abc
    _abc.Mapping.register(Map)


__all__ = 'Map',
__version__ = '0.12'
github MagicStack / immutables / immutables / map.py View on Github external
if len(self) != len(other):
            return False

        for key, val in self.__root.items():
            try:
                oval = other.__root.find(0, map_hash(key), key)
            except KeyError:
                return False
            else:
                if oval != val:
                    return False

        return True


collections.abc.Mapping.register(Map)
github MagicStack / immutables / immutables / map.py View on Github external
raise TypeError(
                    'cannot convert map update '
                    'sequence element #{} to a sequence'.format(i)) from None
            key, val, *r = tup
            if r:
                raise ValueError(
                    'map update sequence element #{} has length '
                    '{}; 2 is required'.format(i, len(r) + 2))

            root, added = root.assoc(0, map_hash(key), key, val, mutid)
            if added:
                count += 1

            i += 1

        return Map._new(count, root)
github MagicStack / immutables / immutables / map.py View on Github external
def __eq__(self, other):
        if not isinstance(other, Map):
            return NotImplemented

        if len(self) != len(other):
            return False

        for key, val in self.__root.items():
            try:
                oval = other.__root.find(0, map_hash(key), key)
            except KeyError:
                return False
            else:
                if oval != val:
                    return False

        return True
github MagicStack / immutables / immutables / map.py View on Github external
def delete(self, key):
        res, node = self.__root.without(0, map_hash(key), key, 0)
        if res is W_EMPTY:
            return Map()
        elif res is W_NOT_FOUND:
            raise KeyError(key)
        else:
            return Map._new(self.__count - 1, node)