diff --git a/Database/Database.cpp b/Database/Database.cpp index 042ca15..6924642 100644 --- a/Database/Database.cpp +++ b/Database/Database.cpp @@ -732,18 +732,19 @@ Database::load_vstree(unsigned _vstree_size) void Database::check() { -//string tstr; +string tstr; //unsigned pid = this->kvstore->getIDByPredicate(""); //cout<<"check: pre "<stringindex->randomAccess(pid, &tstr, false); //cout<<"string index: "<kvstore->getPredicateByID(pid)<kvstore->getIDByEntity(""); - //cout<<"check: sub "<stringindex->randomAccess(sid, &tstr, true); - //cout<<"string index: "<kvstore->getEntityByID(sid)<"<kvstore->getIDByEntity(""); + cout<<"check: sub "<stringindex->randomAccess(sid, &tstr, true); + cout<<"string index: "<kvstore->getEntityByID(sid)<kvstore->getIDByString(""); //cout<<"check: obj "<basic_query->getEdgeNeighborID(_var_i, j); - if (neighbor_id != -1) //TODO:what does it mean???variables in join not considered here + //-1: constant or variable not in join; otherwise, variable in join + if (neighbor_id != -1) { continue; } - //TODO set ready here? - this->basic_query->setReady(_var_i); + char edge_type = this->basic_query->getEdgeType(_var_i, j); int triple_id = this->basic_query->getEdgeID(_var_i, j); Triple triple = this->basic_query->getTriple(triple_id); @@ -234,8 +235,8 @@ Join::pre_handler() neighbor_name = triple.subject; } - //TODO : consider or not?? bool only_preid_filter = (this->basic_query->isOneDegreeNotJoinVar(neighbor_name)); + //NOTICE: we only need to consider constants here if(only_preid_filter) { continue; @@ -243,11 +244,11 @@ Join::pre_handler() else { this->dealed_triple[triple_id] = true; + this->basic_query->setReady(_var_i); } TYPE_PREDICATE_ID pre_id = this->basic_query->getEdgePreID(_var_i, j); - //TODO : cancle the literal TYPE_ENTITY_LITERAL_ID lit_id = (this->kvstore)->getIDByEntity(neighbor_name); if (lit_id == INVALID_ENTITY_LITERAL_ID) { @@ -284,19 +285,20 @@ Join::pre_handler() id_list_len = 0; } + //WARN: this may need to check, end directly if (id_list_len == 0) { _list.clear(); delete[] id_list; return false; } - //TODO : correct ways to intersect //updateList(_list, id_list, id_list_len); if (_list.size() == 0) _list.unionList(id_list,id_list_len); else _list.intersectList(id_list, id_list_len); delete[] id_list; + if (_list.size() == 0) { return false; @@ -305,7 +307,9 @@ Join::pre_handler() cout << "\t\t[" << _var_i << "] after constant filter, candidate size = " << _list.size() << endl << endl << endl; } - cout << "pre var filter start here" << endl; + + cout << "pre filter start here" << endl; + //TODO:use vector instead of set for(int _var = 0; _var < this->var_num; _var++) { if(this->basic_query->isSatelliteInJoin(_var)) @@ -316,7 +320,6 @@ Join::pre_handler() unsigned size = this->basic_query->getCandidateSize(_var); //result if already empty for non-literal variable - //TODO: whether use this /* if (size == 0) { @@ -362,8 +365,6 @@ Join::pre_handler() continue; } - //TODO+BETTER: is any pre really used? do we need to losen the restrictions? - //size:mbasic_query->setReady(_var); //NOTICE:use p2s here, use s2p in only_pre_filter_after_join because pres there are not efficient set::iterator it; @@ -407,6 +407,10 @@ Join::pre_handler() else cans.intersectList(list, len); delete[] list; + if(cans.size() == 0) + { + return false; + } } if(in_edge_pre_id.size() != 0 && cans.size() == 0) @@ -423,6 +427,10 @@ Join::pre_handler() else cans.intersectList(list, len); delete[] list; + if(cans.size() == 0) + { + return false; + } } @@ -432,8 +440,8 @@ Join::pre_handler() return false; } cout << "\t\t[" << _var << "] after pre var filter, candidate size = " << cans.size() << endl << endl << endl; - } + return true; } diff --git a/KVstore/ISTree/ISTree.cpp b/KVstore/ISTree/ISTree.cpp index 7ddff0d..fc5c7ef 100644 --- a/KVstore/ISTree/ISTree.cpp +++ b/KVstore/ISTree/ISTree.cpp @@ -129,7 +129,20 @@ ISTree::search(unsigned _key, char*& _str, unsigned& _len) _str = val->getStr(); _len = val->getLen(); + char* debug = new char[_len]; + memcpy(debug, _str, _len); +// debug[_len] = '\0'; + _str = debug; + + //if(_key==62) + //{ + //cout<<"check in search: "<TSM->request(request); + //if(_key==62) + //{ + //cout<<"check in search: "<length = 0; this->size = _size; - //this->heap = (Node**)malloc(this->size * sizeof(Node*)); //not use 4 or 8 - this->heap = new ISNode*[this->size]; + this->heap = (ISNode**)malloc(this->size * sizeof(ISNode*)); //not use 4 or 8 + //this->heap = new ISNode*[this->size]; if (this->heap == NULL) { this->print("error in ISHeap: Allocation fail!"); @@ -69,6 +69,10 @@ ISHeap::insert(ISNode* _np) { if (this->length == this->size) //when full, reallocate { + cout<<"check: double the heap"<heap = (ISNode**)realloc(this->heap, 2 * this->size * sizeof(ISNode*)); if (this->heap == NULL) { @@ -173,7 +177,8 @@ ISHeap::modify(ISNode* _np, bool _flag) //control direction ISHeap::~ISHeap() { - delete[] this->heap; + //delete[] this->heap; + free(this->heap); this->heap = NULL; this->length = this->size = 0; } @@ -183,4 +188,4 @@ ISHeap::print(string s) { #ifdef DEBUG_KVSTORE #endif -} \ No newline at end of file +} diff --git a/KVstore/ISTree/node/ISLeafNode.cpp b/KVstore/ISTree/node/ISLeafNode.cpp index 796c175..0e4b1ab 100644 --- a/KVstore/ISTree/node/ISLeafNode.cpp +++ b/KVstore/ISTree/node/ISLeafNode.cpp @@ -223,6 +223,7 @@ ISLeafNode::split(ISNode* _father, int _index) p->addNum(); } unsigned tp = this->keys[MIN_KEY_NUM]; + //cout<<"split: "<values[MIN_KEY_NUM].getStr()<setNum(MIN_KEY_NUM); _father->addKey(tp, _index); _father->addChild(p, _index + 1); //DEBUG(check the index) diff --git a/KVstore/IVTree/IVTree.cpp b/KVstore/IVTree/IVTree.cpp index 63aebba..4ee5bf3 100644 --- a/KVstore/IVTree/IVTree.cpp +++ b/KVstore/IVTree/IVTree.cpp @@ -137,6 +137,13 @@ IVTree::search(unsigned _key, char*& _str, unsigned& _len) //_str = this->transfer[0].getStr(); //_len = this->transfer[0].getLen(); + if (!VList::isLongList(_len)) + { + char* debug = new char [_len]; + memcpy(debug, _str, _len); + _str = debug; + } + this->TSM->request(request); return true; } diff --git a/KVstore/IVTree/heap/IVHeap.cpp b/KVstore/IVTree/heap/IVHeap.cpp index 5cc291f..a254d32 100644 --- a/KVstore/IVTree/heap/IVHeap.cpp +++ b/KVstore/IVTree/heap/IVHeap.cpp @@ -20,8 +20,8 @@ IVHeap::IVHeap(unsigned _size) { this->length = 0; this->size = _size; - //this->heap = (Node**)malloc(this->size * sizeof(Node*)); //not use 4 or 8 - this->heap = new IVNode*[this->size]; + this->heap = (IVNode**)malloc(this->size * sizeof(IVNode*)); //not use 4 or 8 + //this->heap = new IVNode*[this->size]; if (this->heap == NULL) { this->print("error in IVHeap: Allocation fail!"); @@ -69,6 +69,7 @@ IVHeap::insert(IVNode* _np) { if (this->length == this->size) //when full, reallocate { + cout<<"check: double the heap"<heap = (IVNode**)realloc(this->heap, 2 * this->size * sizeof(IVNode*)); if (this->heap == NULL) { @@ -173,7 +174,8 @@ IVHeap::modify(IVNode* _np, bool _flag) //control direction IVHeap::~IVHeap() { - delete[] this->heap; + //delete[] this->heap; + free(this->heap); this->heap = NULL; this->length = this->size = 0; } diff --git a/KVstore/IVTree/node/IVLeafNode.cpp b/KVstore/IVTree/node/IVLeafNode.cpp index f2ac757..5f70d14 100644 --- a/KVstore/IVTree/node/IVLeafNode.cpp +++ b/KVstore/IVTree/node/IVLeafNode.cpp @@ -342,7 +342,7 @@ IVLeafNode::split(IVNode* _father, int _index) p->addValue(this->values + i, k); p->addNum(); } - int tp = this->keys[MIN_KEY_NUM]; + unsigned tp = this->keys[MIN_KEY_NUM]; this->setNum(MIN_KEY_NUM); _father->addKey(tp, _index); _father->addChild(p, _index + 1); //DEBUG(check the index) diff --git a/KVstore/KVstore.cpp b/KVstore/KVstore.cpp index 284de57..c59c299 100644 --- a/KVstore/KVstore.cpp +++ b/KVstore/KVstore.cpp @@ -1154,6 +1154,38 @@ KVstore::getEntityByID(TYPE_ENTITY_LITERAL_ID _id) const //NOTICE: no need to add \0 at last if we indicate the length string _ret = string(_tmp, _len); + delete[] _tmp; + //CONSIDER: represent "abc" by 4 chars with length=4, and construct with string(str) directly + + //if(_id == 62) + //{ + //cout<<"check 62: "<<_ret<getEntityByID(62)<addValueByKey(this->id2entity, _id, str, len); } @@ -1287,6 +1321,7 @@ KVstore::getPredicateByID(TYPE_PREDICATE_ID _id) const return ""; } string _ret = string(_tmp, _len); + delete[] _tmp; return _ret; } @@ -1422,6 +1457,21 @@ KVstore::getLiteralByID(TYPE_ENTITY_LITERAL_ID _id) const return ""; } string _ret = string(_tmp, _len); + delete[] _tmp; + + //bool invalid = false; + //for(unsigned i = 0; i < _len; ++i) + //{ + //if(int(_ret[i])<0) + //{ + //invalid = true; + //break; + //} + //} + //if(invalid) + //{ + //cout<<"error in kvstore: "<<_id<<" "<<_ret<length = 0; this->size = _size; - //this->heap = (Node**)malloc(this->size * sizeof(Node*)); //not use 4 or 8 - this->heap = new SINode*[this->size]; + this->heap = (SINode**)malloc(this->size * sizeof(SINode*)); //not use 4 or 8 + //this->heap = new SINode*[this->size]; if (this->heap == NULL) { this->print("error in SIHeap: Allocation fail!"); @@ -69,6 +69,7 @@ SIHeap::insert(SINode* _np) { if (this->length == this->size) //when full, reallocate { + cout<<"check: double the heap"<heap = (SINode**)realloc(this->heap, 2 * this->size * sizeof(SINode*)); if (this->heap == NULL) { @@ -173,7 +174,8 @@ SIHeap::modify(SINode* _np, bool _flag) //control direction SIHeap::~SIHeap() { - delete[] this->heap; + //delete[] this->heap; + free(this->heap); this->heap = NULL; this->length = this->size = 0; } diff --git a/Main/ghttp.cpp b/Main/ghttp.cpp index 6dcce6d..fa8fddf 100644 --- a/Main/ghttp.cpp +++ b/Main/ghttp.cpp @@ -249,6 +249,7 @@ int initialize() { string format = "json"; cout<<"HTTP: this is query"<path_match[1]; + cout<<"check: "< #include #include +#include //NOTICE:below are libraries need to link #include //only for c++11 or greater versions diff --git a/api/http/java/src/jgsc/GstoreConnector.java b/api/http/java/src/jgsc/GstoreConnector.java index 1e2a8dc..e83bb51 100644 --- a/api/http/java/src/jgsc/GstoreConnector.java +++ b/api/http/java/src/jgsc/GstoreConnector.java @@ -132,6 +132,8 @@ public class GstoreConnector { return false; } + //TODO: also use encode to support spaces? + //Consider change format into ?name=DBname String cmd = "build/" + _db_name + "/" + _rdf_file_path; String msg = this.sendGet(cmd);