def find_key_with_modulus(modulus, count): TRIES_LIMIT=1000 for i in range(0, TRIES_LIMIT): key = str(i) if (node.node_hash(key) % count == modulus): return key raise Exception("Could not generate an appropriate key")
def key_ranked(*args): modulus = args[0] long_max_digit = 100000000000000000000000000000000000000L TRIES_LIMIT=1000 for i in range(0, TRIES_LIMIT): key = str(i) if (node.node_hash(key) / long_max_digit == modulus): return key raise Exception("Could not generate an appropriate key")
def test_node_hash_to_number(self): numeric_hash = node.node_hash("hello world!") self.assertTrue(isinstance(numeric_hash, (int,long)), "Expected hash to be numeric (int or long). Got %s: '%s'" % (type(numeric_hash), numeric_hash) )
def hash_modulus(key, node_count): return node.node_hash(key) % node_count
def test_node_hash_same_string_same_hash(self): hash_a = node.node_hash("hello world!") hash_b = node.node_hash("hello"+ " world!") self.assertEqual(hash_a, hash_b)
def test_rank(self): nd = node.NodeDescriptor(ip_port="127.0.0.1:8000") self.assertEqual(nd.rank, node.node_hash("127.0.0.1:8000")) self.assertEqual(nd.rank, 102808487155392830909659332955855849052L)