Skip to content

Incorrect documentation for GenericComparator #760

Open
@maxjkwang

Description

@maxjkwang

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_;
};

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