← 返回题库
中级

Chord DHT查找key的负责节点

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve(____):
    import hashlib
    nodes = nodes.split(____) if isinstance(____) else nodes
    key_hash = int(hashlib.sha1(key.encode()).hexdigest(), ____) % (____ ** ____)
    node_ids = sorted([int(hashlib.sha1(n.encode()).hexdigest(), ____) % (____ ** ____) for n in nodes])
    for nid in node_ids:
        if nid >= key_hash:
            print(____)
            return
    print(____)

示例

输入
solve('node1,node2,node3', 'key1')
期望输出
26
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码