From: nvalimak Date: Fri, 17 Apr 2009 10:19:54 +0000 (+0000) Subject: Bug fixes for rankLessThan() X-Git-Url: http://git.nguyen.vg/gitweb/?a=commitdiff_plain;h=95f2dabec7cabe4002865e5f9d12651e6e32229a;p=SXSI%2FXMLTree.git Bug fixes for rankLessThan() git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@329 3cdefd35-fc62-479d-8e8d-bae585ffb9ca --- diff --git a/libcds/src/static_sequence/static_sequence_wvtree.cpp b/libcds/src/static_sequence/static_sequence_wvtree.cpp index ceeb732..b4a6298 100644 --- a/libcds/src/static_sequence/static_sequence_wvtree.cpp +++ b/libcds/src/static_sequence/static_sequence_wvtree.cpp @@ -66,7 +66,7 @@ uint static_sequence_wvtree::rank(uint symbol, uint pos) { 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); + uint r = root->rankLessThan(s, pos); symbol = am->unmap(s); return r; } diff --git a/libcds/src/static_sequence/wt_node.h b/libcds/src/static_sequence/wt_node.h index 5f8c84f..15ce49d 100644 --- a/libcds/src/static_sequence/wt_node.h +++ b/libcds/src/static_sequence/wt_node.h @@ -38,7 +38,6 @@ class wt_node { public: virtual ~wt_node() {} virtual uint rank(uint symbol, uint pos, uint l, wt_coder * c)=0; - virtual uint rankLessThan(uint &symbol, uint pos, uint level, wt_coder * c) = 0; virtual uint rankLessThan(uint &symbol, uint pos) = 0; virtual uint select(uint symbol, uint pos, uint l, wt_coder * c)=0; virtual uint access(uint pos)=0; diff --git a/libcds/src/static_sequence/wt_node_internal.cpp b/libcds/src/static_sequence/wt_node_internal.cpp index 2219e9b..4e6871a 100644 --- a/libcds/src/static_sequence/wt_node_internal.cpp +++ b/libcds/src/static_sequence/wt_node_internal.cpp @@ -250,39 +250,12 @@ uint wt_node_internal::rank(uint symbol, uint pos, uint l, wt_coder * c) { // return value is rank of symbol (less or equal to the given symbol) that has rank > 0, // the parameter symbol is updated accordinly -uint wt_node_internal::rankLessThan(uint &symbol, uint pos, uint l, wt_coder * c) -{ - bool is_set = c->is_set(symbol,l); - using std::cout; - using std::endl; -// cout << "l = " << l << ", symbol = " << (uchar)symbol << ", rank0 = " << bitmap->rank0(pos) << ", rank1 = " << bitmap->rank1(pos) << endl; - - uint result = -1; - if(!is_set) { - if(left_child==NULL) return -1; - uint rank = bitmap->rank0(pos); - if(rank != 0) - result = left_child->rankLessThan(symbol,rank-1,l+1,c); - return result; - } - - uint rank = bitmap->rank1(pos); - if (rank != 0 && right_child != NULL) - result = right_child->rankLessThan(symbol, rank-1,l+1,c); - -// cout << "recursion to leftchild at l = " << l << ", symbol = " << (uchar)symbol << ", rank0 = " << bitmap->rank0(pos) << ", rank1 = " << bitmap->rank1(pos) << endl; - // check left child for symbols <= givenSymbol - if (result != (uint)-1 || left_child == NULL) - return result; - return left_child->rankLessThan(symbol, bitmap->rank0(pos)-1); -} - uint wt_node_internal::rankLessThan(uint &symbol, uint pos) { uint result = -1; using std::cout; using std::endl; -// cout << "pos = " << pos << ", symbol = " << (uchar)symbol << endl; +// cout << "pos = " << pos << ", symbol = " << symbol << endl; if (pos == (uint)-1) return (uint)-1; @@ -429,7 +402,7 @@ void wt_node_internal::access(vector &result, uint i, uint j) } } - +// Count uint wt_node_internal::access(uint i, uint j, uint min, uint max, uint l, uint pivot) { uint count = 0; diff --git a/libcds/src/static_sequence/wt_node_internal.h b/libcds/src/static_sequence/wt_node_internal.h index f4bb3f1..3fd0579 100644 --- a/libcds/src/static_sequence/wt_node_internal.h +++ b/libcds/src/static_sequence/wt_node_internal.h @@ -41,7 +41,6 @@ class wt_node_internal: public wt_node { wt_node_internal(uchar * seq, uint n, uint l, wt_coder * c, static_bitsequence_builder * bmb, uint, uint *); virtual ~wt_node_internal(); virtual uint rank(uint symbol, uint pos, uint level, wt_coder * c); - virtual uint rankLessThan(uint &symbol, uint pos, uint level, wt_coder * c); virtual uint rankLessThan(uint &symbol, uint pos); virtual uint select(uint symbol, uint pos, uint level, wt_coder * c); virtual uint access(uint pos); diff --git a/libcds/src/static_sequence/wt_node_leaf.cpp b/libcds/src/static_sequence/wt_node_leaf.cpp index 43ca7ca..6c036fd 100644 --- a/libcds/src/static_sequence/wt_node_leaf.cpp +++ b/libcds/src/static_sequence/wt_node_leaf.cpp @@ -36,17 +36,9 @@ uint wt_node_leaf::rank(uint symbol, uint pos, uint l, wt_coder * c) { return pos; } -uint wt_node_leaf::rankLessThan(uint &symbol, uint pos, uint l, wt_coder * c) { -// std::cout <<"this-symbol: " << (uchar)this->symbol << ", symbol = " << (uchar)symbol << ", pos = " << pos << std::endl; - if(symbol > this->symbol) return -1; - symbol = this->symbol; - pos++; - return pos; -} - uint wt_node_leaf::rankLessThan(uint &symbol, uint pos) { // std::cout <<"this-symbol: " << (uchar)this->symbol << ", symbol = " << (uchar)symbol << ", pos = " << pos << std::endl; - if (pos == (uint)-1) + if (pos == (uint)-1 || symbol < this->symbol) return -1; symbol = this->symbol; pos++; diff --git a/libcds/src/static_sequence/wt_node_leaf.h b/libcds/src/static_sequence/wt_node_leaf.h index 0f5e5aa..ad6823d 100644 --- a/libcds/src/static_sequence/wt_node_leaf.h +++ b/libcds/src/static_sequence/wt_node_leaf.h @@ -37,7 +37,6 @@ class wt_node_leaf: public wt_node { wt_node_leaf(uint symbol, uint count); virtual ~wt_node_leaf(); virtual uint rank(uint symbol, uint pos, uint l, wt_coder * c); - virtual uint rankLessThan(uint &symbol, uint pos, uint level, wt_coder * c); virtual uint rankLessThan(uint &symbol, uint pos); virtual uint select(uint symbol, uint pos, uint l, wt_coder * c); virtual uint access(uint pos);