均匀放置的跳过指针

发布于 2024-10-18 17:13:49 字数 106 浏览 1 评论 0原文

我正在阅读有关跳过指针的内容,有人建议最好放置均匀间隔的 sqrt(len of list) 跳过指针。谁能告诉我“均匀分布”是什么意思?我还想看看用 Java 或 Python 做这样的事情的代码

I was reading about skip pointers and someone suggested that it is best to put evenly spaced sqrt(len of list) skip pointers. Can someone tell me what "evenly spaced" means here? I will also like to see the code of doing such a thing in Java or Python

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心安伴我暖 2024-10-25 17:13:49

我认为你的朋友正在谈论跳过列表。通常,跳过指针在列表中随机放置。均匀间隔的指针是指在整个列表中确定性地间隔它们而不是随机放置它们。这样的方案可能会提供更快的读取速度,但在写入列表时可能需要更多计算。

I think your friend was talking about skip lists. Usually the skip pointers are placed randomly through the list. Evenly spaced pointers refers to deterministically spacing them throughout the list instead of randomly placing them. Such a scheme would probably give faster reads, but would probably require more calculation when writing to the list.

爱本泡沫多脆弱 2024-10-25 17:13:49
def add_skips(posting_list):
post_list_with_skips = []
skip_count = math.floor(math.sqrt(len(posting_list)))
pos_index = 0
skip_period = math.floor(len(posting_list) / skip_count)
# -1 because of list indexing starts with 0
skip_index = skip_period - 1
while pos_index < len(posting_list):
    if pos_index == skip_index:
        post_list_with_skips.append([posting_list[pos_index], 1])
        skip_index += skip_period
    else:
        post_list_with_skips.append([posting_list[pos_index], 0])
    pos_index += 1
return post_list_with_skips
def add_skips(posting_list):
post_list_with_skips = []
skip_count = math.floor(math.sqrt(len(posting_list)))
pos_index = 0
skip_period = math.floor(len(posting_list) / skip_count)
# -1 because of list indexing starts with 0
skip_index = skip_period - 1
while pos_index < len(posting_list):
    if pos_index == skip_index:
        post_list_with_skips.append([posting_list[pos_index], 1])
        skip_index += skip_period
    else:
        post_list_with_skips.append([posting_list[pos_index], 0])
    pos_index += 1
return post_list_with_skips
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文