コード例 #1
0
ファイル: neighbor.py プロジェクト: impe83/pyquarkchain
def is_neighbor(b1: Branch, b2: Branch):
    """A naive algorithm to decide neighbor relationship
    TODO: a better algorithm, because the current one ensures 32 neighbors ONLY when there are 2^32 shards
    """
    if b1.get_chain_id() == b2.get_chain_id():
        return is_p2(abs(b1.get_shard_id() - b2.get_shard_id()))
    if b1.get_shard_id() == b2.get_shard_id():
        return is_p2(abs(b1.get_chain_id() - b2.get_chain_id()))
    return False
コード例 #2
0
def is_neighbor(b1: Branch, b2: Branch):
    """A naive algorithm to decide neighbor relationship
    Two shards are neighbor iff there is only 1 bit difference in their shard ids.
    This only applies if there are more than 32 shards in the network.
    Otherwise all shards are neighbor to each other.
    TODO: a better algorithm
    """
    check(b1.get_shard_size() == b2.get_shard_size())
    check(b1.get_shard_id() != b2.get_shard_id())

    if b1.get_shard_size() <= 32:
        return True

    return is_p2(abs(b1.get_shard_id() - b2.get_shard_id()))