some methods marked const
This commit is contained in:
34
index.h
34
index.h
@@ -29,15 +29,15 @@ public:
|
||||
}
|
||||
|
||||
|
||||
std::vector<rowid_t> search(ValueNode *key) {
|
||||
std::vector<rowid_t> search(const ValueNode *key) {
|
||||
return search(to_index_value(key));
|
||||
}
|
||||
|
||||
void insert(ColValue *key, rowid_t rowid) {
|
||||
void insert(const ColValue *key, rowid_t rowid) {
|
||||
return insert(to_index_value(key), rowid);
|
||||
}
|
||||
|
||||
void remove(ColValue *key, rowid_t rowid) {
|
||||
void remove(const ColValue *key, rowid_t rowid) {
|
||||
return remove(to_index_value(key), rowid);
|
||||
}
|
||||
|
||||
@@ -53,13 +53,9 @@ public:
|
||||
return m_index_name;
|
||||
}
|
||||
|
||||
[[nodiscard]] ColumnType get_data_type() const {
|
||||
return m_data_type;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
IndexValue to_index_value(ValueNode *key) {
|
||||
IndexValue to_index_value(const ValueNode *key) {
|
||||
if (m_data_type == ColumnType::integer_type)
|
||||
return key->getIntegerValue();
|
||||
else if (m_data_type == ColumnType::varchar_type)
|
||||
@@ -68,16 +64,16 @@ private:
|
||||
throw Exception("using index on unsupported type");
|
||||
}
|
||||
|
||||
IndexValue to_index_value(ColValue *key) {
|
||||
IndexValue to_index_value(const ColValue *key) {
|
||||
if (m_data_type == ColumnType::integer_type)
|
||||
return key->getIntValue();
|
||||
return key->getIntegerValue();
|
||||
else if (m_data_type == ColumnType::varchar_type)
|
||||
return key->getStringValue();
|
||||
else
|
||||
throw Exception("using index on unsupported type");
|
||||
}
|
||||
|
||||
void insert(IndexValue key, rowid_t rowid) {
|
||||
void insert(const IndexValue& key, rowid_t rowid) {
|
||||
auto search = m_index.find(key);
|
||||
if (search != m_index.end()) {
|
||||
if (m_uniq)
|
||||
@@ -92,7 +88,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void remove(IndexValue key, rowid_t rowid) {
|
||||
void remove(const IndexValue& key, rowid_t rowid) {
|
||||
auto search = m_index.find(key);
|
||||
if (search != m_index.end()) {
|
||||
search->second.erase(find(search->second.begin(), search->second.end(), rowid));
|
||||
@@ -111,21 +107,11 @@ private:
|
||||
}
|
||||
|
||||
|
||||
|
||||
// void dump() {
|
||||
// std::for_each(m_index.begin(), m_index.end(),
|
||||
// [](std::pair<IndexValue, std::vector<rowid_t>> element){
|
||||
// IndexValue key = element.first;
|
||||
// std::vector<rowid_t> rowids = element.second;
|
||||
// std::cout << "key: " << key << ", rowids count:" << rowids.size() << std::endl;
|
||||
// });
|
||||
// }
|
||||
|
||||
private:
|
||||
bool m_uniq;
|
||||
bool m_uniq;
|
||||
std::string m_index_name;
|
||||
std::string m_column_name;
|
||||
ColumnType m_data_type;
|
||||
ColumnType m_data_type;
|
||||
|
||||
std::map<IndexValue, std::vector<rowid_t> > m_index;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user