miniob
miniob copied to clipboard
duplicate codes in bplus_tree.h and tuple_cell.cpp
the codes for attribute compare is duplicate
int operator()(const char *v1, const char *v2) const {
switch (attr_type_) {
case INTS: {
return *(int *)v1 - *(int *)v2;
}
break;
case FLOATS: {
float result = *(float *)v1 - *(float *)v2;
if (-1e-6 < result && result < 1e-6) {
return 0;
}
return result > 0 ? 1 : -1;
}
case CHARS: {
return strncmp(v1, v2, attr_length_);
}
default:{
LOG_ERROR("unknown attr type. %d", attr_type_);
abort();
}
}
}
the other
int TupleCell::compare(const TupleCell &other) const
{
if (this->attr_type_ == other.attr_type_) {
switch (this->attr_type_) {
case INTS: return compare_int(this->data_, other.data_);
case FLOATS: return compare_float(this->data_, other.data_);
case CHARS: return compare_string(this->data_, this->length_, other.data_, other.length_);
default: {
LOG_WARN("unsupported type: %d", this->attr_type_);
}
}
} else if (this->attr_type_ == INTS && other.attr_type_ == FLOATS) {
float this_data = *(int *)data_;
return compare_float(&this_data, other.data_);
} else if (this->attr_type_ == FLOATS && other.attr_type_ == INTS) {
float other_data = *(int *)other.data_;
return compare_float(data_, &other_data);
}
LOG_WARN("not supported");
return -1; // TODO return rc?
}