Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Release memory of value stored when art node is destroyed.
Kishore Nallan4d2ba27cabb3
diff --git a/include/forarray.h b/include/forarray.hindex 14f0e20e..7ac9327f 100644--- a/include/forarray.h+++ b/include/forarray.h@@ -24,6 +24,10 @@ public:memset(in, 0, size_bytes);}+ ~forarray() {+ delete in;+ }+static inline uint32_t required_bits(const uint32_t v) {return v == 0 ? 0 : 32 - __builtin_clz(v);}diff --git a/src/art.cpp b/src/art.cppindex 8110bdca..3d0192d2 100644--- a/src/art.cpp+++ b/src/art.cpp@@ -96,7 +96,9 @@ static void destroy_node(art_node *n) {// Special case leafsif (IS_LEAF(n)) {- free(LEAF_RAW(n));+ art_leaf *leaf = (art_leaf *) LEAF_RAW(n);+ delete leaf->values;+ free(leaf);return;}diff --git a/src/collection.cpp b/src/collection.cppindex 1a6a6f80..deda470d 100644--- a/src/collection.cpp+++ b/src/collection.cpp@@ -37,11 +37,10 @@ void Collection::add(std::vector<std::string> tokens, uint16_t score) {uint32_t num_hits = 0;+ const unsigned char *key = (const unsigned char *) kv.first.c_str();int key_len = (int) kv.first.length() + 1; // for the terminating \0 char- char *key = new char[key_len];- strcpy(key, kv.first.c_str());- art_leaf* leaf = (art_leaf *) art_search(&t, (const unsigned char *) key, key_len);+ art_leaf* leaf = (art_leaf *) art_search(&t, key, key_len);if(leaf != NULL) {num_hits = leaf->values->ids.getLength();}diff --git a/src/server.cpp b/src/server.cppindex ec5cba84..3769b606 100644--- a/src/server.cpp+++ b/src/server.cpp@@ -75,11 +75,11 @@ static int chunked_test(h2o_handler_t *self, h2o_req_t *req) {h2o_iovec_init(req->path.base + req->query_at, req->path.len - req->query_at) :h2o_iovec_init(H2O_STRLIT(""));- printf("Query: %.*s\n", (int) query.len, query.base);-std::string query_str(query.base, query.len);std::map<std::string, std::string> query_map = parse_query(query_str);+ printf("Query: %s\n", query_map["q"].c_str());+auto begin = std::chrono::high_resolution_clock::now();collection->search(query_map["q"], 100);long long int timeMillis = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - begin).count();@@ -145,8 +145,8 @@ static int create_listener(void) {}void index_documents() {- std::ifstream infile("/Users/kishore/others/wreally/typesense/test/documents.txt");- //std::ifstream infile("/Users/kishore/Downloads/hnstories.tsv");+ //std::ifstream infile("/Users/kishore/others/wreally/typesense/test/documents.txt");+ std::ifstream infile("/Users/kishore/Downloads/hnstories.tsv");std::string line;