def test_hash_from_dict(): dicts = [{}, { 0: 0 }, { 0: 1 }, { 1: 0 }, { 1: 1 }, { 0: (0, ) }, { 0: [1] }, { 0: (0, 1) }, { 0: [1, 0] }] for elem in dicts[:]: dicts.append(OrderedDict(elem)) hashs = [] for idx, d in enumerate(dicts): h = hash_from_dict(d) assert h not in hashs hashs.append(h) # List are not hashable. So they are transformed into tuple. assert hash_from_dict({0: (0, )}) == hash_from_dict({0: [0]})
def test_hash_from_dict(): dicts = [{}, {0: 0}, {0: 1}, {1: 0}, {1: 1}, {0: (0,)}, {0: [1]}, {0: (0, 1)}, {0: [1, 0]}] for elem in dicts[:]: dicts.append(OrderedDict(elem)) hashs = [] for idx, d in enumerate(dicts): h = hash_from_dict(d) assert h not in hashs hashs.append(h) # List are not hashable. So they are transformed into tuple. assert hash_from_dict({0: (0,)}) == hash_from_dict({0: [0]})
def __hash__(self): return hash((type(self), hash(self.scalar_op), hash_from_dict(self.inplace_pattern)))
def __hash__(self): return (hash(type(self)) ^ hash(self.scalar_op) ^ hash_from_dict(self.inplace_pattern))