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

Incorrect documentation for GenericComparator #760

Open
maxjkwang opened this issue Oct 17, 2024 · 0 comments
Open

Incorrect documentation for GenericComparator #760

maxjkwang opened this issue Oct 17, 2024 · 0 comments

Comments

@maxjkwang
Copy link

In src/include/storage/index/generic_key.h, it's mentioned that Function object returns true if lhs < rhs, but the implemented comparator performs 3-way comparison.

/**
 * Function object returns true if lhs < rhs, used for trees
 */
class GenericComparator {
 public:
  inline auto operator()(const GenericKey<KeySize> &lhs, const GenericKey<KeySize> &rhs) const -> int {
    uint32_t column_count = key_schema_->GetColumnCount();

    for (uint32_t i = 0; i < column_count; i++) {
      Value lhs_value = (lhs.ToValue(key_schema_, i));
      Value rhs_value = (rhs.ToValue(key_schema_, i));

      if (lhs_value.CompareLessThan(rhs_value) == CmpBool::CmpTrue) {
        return -1;
      }
      if (lhs_value.CompareGreaterThan(rhs_value) == CmpBool::CmpTrue) {
        return 1;
      }
    }
    // equals
    return 0;
  }

  GenericComparator(const GenericComparator &other) : key_schema_{other.key_schema_} {}

  // constructor
  explicit GenericComparator(Schema *key_schema) : key_schema_(key_schema) {}

 private:
  Schema *key_schema_;
};
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