#include "RocksDBWrapper.h"
|
|
RocksDBWrapper::RocksDBWrapper(const std::string &db_path, const std::string &index_path)
|
{
|
rocksdb::Options options;
|
options.create_if_missing = true;
|
|
// Open the main RocksDB database
|
rocksdb::Status status = rocksdb::DB::Open(options, db_path, &db_);
|
if (!status.ok())
|
{
|
std::cerr << "Error opening RocksDB database: " << status.ToString() << std::endl;
|
}
|
|
// Open the index RocksDB database
|
status = rocksdb::DB::Open(options, index_path, &index_db_);
|
if (!status.ok())
|
{
|
std::cerr << "Error opening RocksDB index database: " << status.ToString() << std::endl;
|
}
|
}
|
|
RocksDBWrapper::~RocksDBWrapper()
|
{
|
delete db_;
|
delete index_db_;
|
}
|
|
bool RocksDBWrapper::keyExists(const std::string &key)
|
{
|
std::string value;
|
rocksdb::Status status = db_->Get(rocksdb::ReadOptions(), serializeKey(key), &value);
|
return status.ok();
|
}
|
|
bool RocksDBWrapper::StringMatch(const std::string &text, const std::string &pattern)
|
{
|
int n = text.length();
|
int m = pattern.length();
|
int i = 0, j = 0, startIndex = -1, match = 0;
|
|
while (i < n)
|
{
|
if (j < m && (pattern[j] == '?' || pattern[j] == text[i]))
|
{
|
i++;
|
j++;
|
}
|
else if (j < m && pattern[j] == '*')
|
{
|
startIndex = j;
|
match = i;
|
j++;
|
}
|
else if (startIndex != -1)
|
{
|
j = startIndex + 1;
|
match++;
|
i = match;
|
}
|
else
|
{
|
return false;
|
}
|
}
|
|
while (j < m && pattern[j] == '*')
|
{
|
j++;
|
}
|
|
return j == m;
|
}
|