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

About comparing a record's key with input key #34

Open
duclahoang opened this issue Mar 14, 2022 · 0 comments
Open

About comparing a record's key with input key #34

duclahoang opened this issue Mar 14, 2022 · 0 comments

Comments

@duclahoang
Copy link

Hi, everyone
I've read source code kyotocabinet-1.2.79 recently, and there is a piece of code (at line 1936 file kcdirdb.h) that I can't clearly understand.

bool accept_impl(const char* kbuf, size_t ksiz, Visitor* visitor, const char* name) {
    _assert_(kbuf && ksiz <= MEMMAXSIZ && visitor && name);
    bool err = false;
    const std::string& rpath = path_ + File::PATHCHR + name;
    Record rec;
    if (read_record(rpath, &rec)) {
      if (rec.ksiz == ksiz || !std::memcmp(rec.kbuf, kbuf, ksiz)) {
        if (!accept_visit_full(kbuf, ksiz, rec.vbuf, rec.vsiz, rec.rsiz,
                               visitor, rpath, name)) err = true;
      } else {
        set_error(_KCCODELINE_, Error::LOGIC, "collision of the hash values");
        err = true;
      }
      delete[] rec.rbuf;
    } else {
      if (!accept_visit_empty(kbuf, ksiz, visitor, rpath, name)) err = true;
    }
    return !err;
  }

The code that compares input key with record's key: rec.ksiz == ksiz || !std::memcmp(rec.kbuf, kbuf, ksiz)
I think it must be something looks like: rec.ksiz == ksiz && !std::memcmp(rec.kbuf, kbuf, ksiz).
Thank you for reading my issue.

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