X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=libcds%2Fsrc%2Fstatic_sequence%2Fstatic_sequence_wvtree.cpp;h=0e08676e9dfd405b5bedcff754b030c869299ec9;hb=65d17f36ed533e22abc9dc4edee8925080d38651;hp=aa6a885572fcf9e68a7003d311c5fe4e48f6bffa;hpb=4bd816265ae88b4e1631634260384baa559f8967;p=SXSI%2FXMLTree.git diff --git a/libcds/src/static_sequence/static_sequence_wvtree.cpp b/libcds/src/static_sequence/static_sequence_wvtree.cpp index aa6a885..0e08676 100644 --- a/libcds/src/static_sequence/static_sequence_wvtree.cpp +++ b/libcds/src/static_sequence/static_sequence_wvtree.cpp @@ -40,9 +40,15 @@ static_sequence_wvtree::static_sequence_wvtree(uchar * symbols, uint n, wt_coder am->use(); this->c=c; c->use(); - root = new wt_node_internal(symbols, n, 0, c, bmb); - for(uint i=0;iunmap((uint)symbols[i]); + uint *done = new uint[n/W+1]; + for (uint i = 0; i < n/W+1; i++) + done[i] = 0; + root = new wt_node_internal(symbols, n, 0, c, bmb, 0, done); + delete [] done; + delete [] symbols; + symbols = 0; // Already deleted! +// for(uint i=0;iunmap((uint)symbols[i]); } static_sequence_wvtree::static_sequence_wvtree() {} @@ -57,18 +63,57 @@ uint static_sequence_wvtree::rank(uint symbol, uint pos) { return root->rank(am->map(symbol), pos, 0, c); } +uint static_sequence_wvtree::rankLessThan(uint &symbol, uint pos) { + uint s = am->map(symbol); + std::cout << "lessthan..." << std::endl; + uint r = root->rankLessThan(s, pos, 0, c); + symbol = am->unmap(s); + return r; +} + + uint static_sequence_wvtree::count(uint s) { return root->rank(am->map(s), len-1, 0, c); } uint static_sequence_wvtree::select(uint symbol, uint pos) { - return root->select(am->map(symbol), pos, 0, c)-1; + uint ret = root->select(am->map(symbol), pos, 0, c); + if(ret==((uint)-1)) return (uint)-1; + return ret-1; } uint static_sequence_wvtree::access(uint pos) { return am->unmap(root->access(pos)); } +vector static_sequence_wvtree::access(uint i, uint j, uint min, uint max) +{ + vector resultSet; + root->access(resultSet, i, j, am->map(min), am->map(max), c->depth()-1, 0); + for (vector::iterator it = resultSet.begin(); it != resultSet.end(); ++it) + *it = am->unmap(*it); + return resultSet; +} + +vector static_sequence_wvtree::accessAll(uint i, uint j) +{ + vector resultSet; + if (j > i) + return resultSet; + + resultSet.reserve(j-i+1); + root->access(resultSet, i, j); + for (vector::iterator it = resultSet.begin(); it != resultSet.end(); ++it) + *it = am->unmap(*it); + return resultSet; +} + +uint static_sequence_wvtree::count(uint i, uint j, uint min, uint max) +{ + return root->access(i, j, am->map(min), am->map(max), c->depth()-1, 0); +} + + uint static_sequence_wvtree::size() { /*cout << "WT: " << root->size() << endl; cout << "Coder: " << c->size() << endl;