Added rankLessThan
[SXSI/XMLTree.git] / libcds / src / static_sequence / static_sequence_wvtree.cpp
index aa6a885..baabf02 100644 (file)
@@ -40,9 +40,10 @@ 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;i<n;i++) 
-    symbols[i] = (uchar)am->unmap((uint)symbols[i]);  
+       root = new wt_node_internal(symbols, n, 0, c, bmb); 
+        symbols = 0; // Already deleted!
+//  for(uint i=0;i<n;i++) 
+//    symbols[i] = (uchar)am->unmap((uint)symbols[i]);  
 }
 
 static_sequence_wvtree::static_sequence_wvtree() {}
@@ -57,12 +58,23 @@ 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) {