Skip to content
This repository was archived by the owner on Oct 30, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
'sources': [
"./src/cpp_util.cpp",
"./src/node_util.cpp",
"./src/normalizationcache.cpp",
"./src/memorycache.cpp",
"./src/rocksdbcache.cpp",
"./src/coalesce.cpp",
Expand Down
1 change: 0 additions & 1 deletion src/binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,6 @@ extern "C" {
static void start(Handle<Object> target) {
JSMemoryCache::Initialize(target);
JSRocksDBCache::Initialize(target);
NormalizationCache::Initialize(target);
Nan::SetMethod(target, "coalesce", JSCoalesce);
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/binding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "coalesce.hpp"
#include "memorycache.hpp"
#include "node_util.hpp"
#include "normalizationcache.hpp"
#include "rocksdbcache.hpp"

#pragma clang diagnostic push
Expand Down Expand Up @@ -61,9 +60,9 @@ using JSRocksDBCache = JSCache<carmen::RocksDBCache>;
using JSMemoryCache = JSCache<carmen::MemoryCache>;

template <class T>
intarray __get(JSCache<T>* c, std::string phrase, langfield_type langfield);
intarray __get(JSCache<T>* c, const std::string& phrase, langfield_type langfield);
template <class T>
intarray __getmatching(JSCache<T>* c, std::string phrase, bool match_prefixes, langfield_type langfield);
intarray __getmatching(JSCache<T>* c, const std::string& phrase, bool match_prefixes, langfield_type langfield);

struct CoalesceBaton : carmen::noncopyable {
uv_work_t request;
Expand Down
2 changes: 1 addition & 1 deletion src/cpp_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ inline void packVec(intarray const& varr, std::unique_ptr<rocksdb::DB> const& db
db->Put(rocksdb::WriteOptions(), key, message);
}

// rocksdb is also used in memorycache, and normalizationcache
// rocksdb is also used in memorycache
rocksdb::Status OpenDB(const rocksdb::Options& options, const std::string& name, std::unique_ptr<rocksdb::DB>& dbptr);
rocksdb::Status OpenForReadOnlyDB(const rocksdb::Options& options, const std::string& name, std::unique_ptr<rocksdb::DB>& dbptr);

Expand Down
11 changes: 6 additions & 5 deletions src/memorycache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@

namespace carmen {

intarray MemoryCache::__get(std::string phrase, langfield_type langfield) {
intarray MemoryCache::__get(const std::string& phrase, langfield_type langfield) {
arraycache const& cache = this->cache_;
intarray array;
std::string phrase_with_langfield = phrase;

add_langfield(phrase, langfield);
auto aitr = cache.find(phrase);
add_langfield(phrase_with_langfield, langfield);
auto aitr = cache.find(phrase_with_langfield);
if (aitr != cache.end()) {
array = aitr->second;
}
std::sort(array.begin(), array.end(), std::greater<uint64_t>());
return array;
}

intarray MemoryCache::__getmatching(std::string phrase, bool match_prefixes, langfield_type langfield) {
intarray MemoryCache::__getmatching(const std::string& phrase_ref, bool match_prefixes, langfield_type langfield) {
intarray array;
std::string phrase = phrase_ref;

if (!match_prefixes) phrase.push_back(LANGFIELD_SEPARATOR);
size_t phrase_length = phrase.length();
const char* phrase_data = phrase.data();

// Load values from memory cache

for (auto const& item : this->cache_) {
Expand Down
6 changes: 3 additions & 3 deletions src/memorycache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class MemoryCache {

void _set(std::string key_id, std::vector<uint64_t>, langfield_type langfield, bool append);

std::vector<uint64_t> _get(std::string phrase, std::vector<uint64_t> languages);
std::vector<uint64_t> _get(std::string& phrase, std::vector<uint64_t> languages);
std::vector<uint64_t> _getmatching(std::string phrase, bool match_prefixes, std::vector<uint64_t> languages);

std::vector<uint64_t> __get(std::string phrase, langfield_type langfield);
std::vector<uint64_t> __getmatching(std::string phrase, bool match_prefixes, langfield_type langfield);
std::vector<uint64_t> __get(const std::string& phrase, langfield_type langfield);
std::vector<uint64_t> __getmatching(const std::string& phrase_ref, bool match_prefixes, langfield_type langfield);

arraycache cache_;
};
Expand Down
Loading