do not use template for index
This commit is contained in:
16
index.h
16
index.h
@@ -6,16 +6,18 @@
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <variant>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace usql {
|
||||
|
||||
using IndexValue=std::variant<long, std::string>;
|
||||
using rowid_t = size_t; // int is now enough but size_t is correct
|
||||
|
||||
static const int k_default_rowids_size = 16;
|
||||
|
||||
template<typename K>
|
||||
|
||||
class Index {
|
||||
public:
|
||||
Index(std::string index_name, std::string col_name, ColumnType type) :
|
||||
@@ -25,7 +27,7 @@ public:
|
||||
throw Exception("creating index on unsupported type");
|
||||
}
|
||||
|
||||
void insert(K key, rowid_t rowid) {
|
||||
void insert(IndexValue key, rowid_t rowid) {
|
||||
auto search = m_index.find(key);
|
||||
if (search != m_index.end()) {
|
||||
if (m_uniq)
|
||||
@@ -40,7 +42,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void remove(K key, rowid_t rowid) {
|
||||
void remove(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));
|
||||
@@ -49,7 +51,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<rowid_t> search(K key) {
|
||||
std::vector<rowid_t> search(IndexValue key) {
|
||||
auto search = m_index.find(key);
|
||||
if (search != m_index.end()) {
|
||||
return search->second;
|
||||
@@ -74,8 +76,8 @@ public:
|
||||
|
||||
// void dump() {
|
||||
// std::for_each(m_index.begin(), m_index.end(),
|
||||
// [](std::pair<K, std::vector<rowid_t>> element){
|
||||
// K key = element.first;
|
||||
// [](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;
|
||||
// });
|
||||
@@ -99,7 +101,7 @@ private:
|
||||
std::string m_column_name;
|
||||
ColumnType m_data_type;
|
||||
|
||||
std::map<K, std::vector<rowid_t> > m_index;
|
||||
std::map<IndexValue, std::vector<rowid_t> > m_index;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user