Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btree 的更新值的函数update应该有一些小问题 #1

Open
Slipstream-Max opened this issue Dec 22, 2023 · 0 comments
Open

btree 的更新值的函数update应该有一些小问题 #1

Slipstream-Max opened this issue Dec 22, 2023 · 0 comments

Comments

@Slipstream-Max
Copy link

作者大大 我只是初学者 看您的代码想着动手复现一下btree 233 看到btree.hh 178行发现了一点点小问题
int update(const Key& k, const Value& v) {
if (empty()) return -1;
auto p = search_key(k);
int i = lower_bound(p->key, p->key + p->n, k) - p->key;
if (i == p->n) return -1;

    p->key[i] = v;
    return 0;
}

应该为 value[i]=v 才能更新值 而不是key
而且if判断可以加i!=k 保证确实找到了一致的值
int update(const Key& k, const Value& v) {
if (empty()) return -1;
auto p = search_key(k);
int i = lower_bound(p->key, p->key + p->n, k) - p->key;
if (i == p->n||k!=p->key[i]) return -1;

    p->value[i] = v;
    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant