def test_hashmap_can_set_an_object_by_key_if_not_already_set(self): map = HashMap(10, hash, equal) key = {'hash': 1} self.assertEqual(map.maybe_set(key, 42), 42) self.assertEqual(map.get(key), 42) self.assertEqual(map.maybe_set(key, 43), 42) self.assertEqual(map.get(key), 42)
def index(self): index_by_point = HashMap(len(self.coordinates) * 1.4, self.hash_index, self.equal_index, Int32Array, -1, Int32Array) indexes = Int32Array(len(self.coordinates)) for i in range(len(self.coordinates)): tmp = index_by_point.maybe_set(i, i) indexes[i] = tmp return indexes