Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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'
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)
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)
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
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)