在分布式哈希表字典中用指数递增法进行探测,然后进行二进制搜索

2024-06-16 12:55:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要关于如何完成这项任务的建议。autor创建了函数find\u next\u free\u dataset\u num(node)并在分布式哈希表中搜索空闲槽。此DHT使用类似于字典的接口,该接口覆盖\uuuSetItem\uuuuuuuuuuuuuuuu\uuuuuuGetItem\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu\uuuuuuuuuuuu。哪个好 设计。但是这个函数现在使用线性探测来搜索新的未使用的插槽 可预测键。所以问题是如果指数num=num*num+1解决了它 如何在0和已用槽数之间的新num值上实现二进制搜索?你知道吗

def predictable_key(node, num):
    return "monitor_dataset_{0}_{1}".format(node.get_address(), str(num))


def find_next_free_dataset_num(node):
    # FIXME probe with exponential increase then binary search lowest unused
    num = 0
    while node[predictable_key(node, num)] is not None:
        _log.info("Dataset {0} already exists!".format(num))
        num += 1
    return num

Tags: key函数nodefreeformatreturndef分布式