Skip to content
This repository was archived by the owner on Oct 17, 2025. It is now read-only.
This repository was archived by the owner on Oct 17, 2025. It is now read-only.

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

@duclahoang

Description

@duclahoang

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions