def key_ranked(*args): modulus = args[0] TRIES_LIMIT = 1000 for i in range(0, TRIES_LIMIT): key = str(i) if (ncore.node_hash(key) / long_max_digit == modulus): return key raise Exception("Could not generate an appropriate key")
def test_node_hash_same_string_same_hash(self): hash_a = ncore.node_hash("hello world!") hash_b = ncore.node_hash("hello" + " world!") self.assertEqual(hash_a, hash_b)
def test_rank(self): nd = ncore.NodeDescriptor(host_port="127.0.0.1:8000") self.assertEqual(nd.rank, ncore.node_hash("127.0.0.1:8000")) self.assertEqual(nd.rank, 102808487155392830909659332955855849052L)
def test_node_hash_to_number(self): numeric_hash = ncore.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))