X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=libcds%2Fsrc%2Fstatic_sequence%2Fstatic_sequence_wvtree.cpp;h=baabf02ffb699af75bd645acdf28a22fe9945d07;hb=a2625dad3e0b32cd0a8ceee350aef39e8412e5b0;hp=efdd8f70f9ac4473666f9abf64ab28a000d691b6;hpb=0bf9688e2615a9fc07860c5762240e4ce26ee5d3;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 efdd8f7..baabf02 100644 --- a/libcds/src/static_sequence/static_sequence_wvtree.cpp +++ b/libcds/src/static_sequence/static_sequence_wvtree.cpp @@ -1,37 +1,80 @@ - +/* static_sequence_wvtree.cpp + * Copyright (C) 2008, Francisco Claude, all rights reserved. + * + * static_sequence_wvtree definition + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + #include static_sequence_wvtree::static_sequence_wvtree(uint * symbols, uint n, wt_coder * c, static_bitsequence_builder * bmb, alphabet_mapper * am) { for(uint i=0;imap(symbols[i]); this->am = am; + am->use(); this->c=c; - cout << "Building..."; cout.flush(); + c->use(); root = new wt_node_internal(symbols, n, 0, c, bmb); - cout << "done" << endl; cout.flush(); for(uint i=0;iunmap(symbols[i]); } -static_sequence_wvtree::static_sequence_wvtree() {} +static_sequence_wvtree::static_sequence_wvtree(uchar * symbols, uint n, wt_coder * c, static_bitsequence_builder * bmb, alphabet_mapper * am) { + for(uint i=0;imap((uint)symbols[i]); + this->am = am; + am->use(); + this->c=c; + c->use(); + root = new wt_node_internal(symbols, n, 0, c, bmb); + symbols = 0; // Already deleted! +// for(uint i=0;iunmap((uint)symbols[i]); +} +static_sequence_wvtree::static_sequence_wvtree() {} static_sequence_wvtree::~static_sequence_wvtree() { delete root; - delete am; - delete c; + am->unuse(); + c->unuse(); } 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) { @@ -64,8 +107,9 @@ static_sequence_wvtree * static_sequence_wvtree::load(FILE *fp) { static_sequence_wvtree * ret = new static_sequence_wvtree(); if(fread(&ret->n,sizeof(uint),1,fp)!=1) return NULL; ret->c = wt_coder::load(fp); + ret->c->use(); ret->am = alphabet_mapper::load(fp); + ret->am->use(); ret->root = wt_node::load(fp); return ret; } -