Renamed "bins" to binmap_t
authorVictor Grishchenko <victor.grishchenko@gmail.com>
Sat, 16 Jan 2010 19:06:42 +0000 (20:06 +0100)
committerVictor Grishchenko <victor.grishchenko@gmail.com>
Sat, 16 Jan 2010 19:06:42 +0000 (20:06 +0100)
...well, it does not exactly mimic STL conventions, but at least...

bin64.h
bins.cpp
bins.h
ext/seq_picker.cpp
hashtree.cpp
hashtree.h
p2tp.h
sendrecv.cpp
tests/binstest2.cpp
tests/freemap.cpp

diff --git a/bin64.h b/bin64.h
index 1ba8532..9045fe7 100644 (file)
--- a/bin64.h
+++ b/bin64.h
@@ -164,7 +164,7 @@ struct bin64_t {
     /** Depth-first in-order binary tree traversal. */
     bin64_t next_dfsio (uint8_t floor);
 
-    /** Return the number of basci bins within this bin. */
+    /** Return the number of basic bins within this bin. */
     bin64_t width () const {
         return (tail_bits()+1)>>1;
     }
index ee5fbf8..1c20dd4 100644 (file)
--- a/bins.cpp
+++ b/bins.cpp
 
 // make it work piece by piece
 
-const uint8_t    bins::SPLIT[16] = 
+const uint8_t    binmap_t::SPLIT[16] = 
 {0, 3, 12, 15, 48, 51, 60, 63, 192, 195, 204, 207, 240, 243, 252, 255};
-const uint8_t    bins::JOIN[16] =
+const uint8_t    binmap_t::JOIN[16] =
 {0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15};
-const int bins::NOJOIN = 0x10000;
+const int binmap_t::NOJOIN = 0x10000;
 
 
-void bins::extend () {
+void binmap_t::extend () {
     uint16_t nblocks = blocks_allocated ? (blocks_allocated<<1) : 1;
     size_t had_bytes = blocks_allocated<<6;
     size_t need_bytes = nblocks<<6;
@@ -31,26 +31,26 @@ void bins::extend () {
     blocks_allocated = nblocks;
 }
 
-bins::bins() :  height(4), blocks_allocated(0), cells(NULL), 
+binmap_t::binmap_t() :  height(4), blocks_allocated(0), cells(NULL), 
                 ap(0), cells_allocated(0), twist_mask(0) {
     extend();
     assert(!alloc_cell());
 }
 
-void bins::twist (uint64_t mask) {
+void binmap_t::twist (uint64_t mask) {
     while ( (1<<height) <= mask )
         extend_range();
     twist_mask = mask;
 }
 
-bins::bins (const bins& b) : height(b.height), ap(b.ap),
+binmap_t::binmap_t (const binmap_t& b) : height(b.height), ap(b.ap),
 blocks_allocated(b.blocks_allocated), cells_allocated(b.cells_allocated) {
     size_t memsz = blocks_allocated*16*32;
     cells = (uint32_t*) malloc(memsz);
     memcpy(cells,b.cells,memsz);
 }
 
-void bins::dump (const char* note) {
+void binmap_t::dump (const char* note) {
     printf("%s\t",note);
     for(int i=0; i<(blocks_allocated<<5); i++) {
         if ( (i&0x1f)>29 )
@@ -65,7 +65,7 @@ void bins::dump (const char* note) {
     printf("\n");
 }
 
-uint32_t bins::split16to32(uint16_t halfval) {
+uint32_t binmap_t::split16to32(uint16_t halfval) {
     uint32_t nval = 0;
     for(int i=0; i<4; i++) {
         nval >>= 8;
@@ -76,7 +76,7 @@ uint32_t bins::split16to32(uint16_t halfval) {
 }
 
 
-int bins::join32to16(uint32_t cval) {
+int binmap_t::join32to16(uint32_t cval) {
     union { uint32_t i; uint8_t a[4]; } uvar;
     uvar.i = cval & (cval>>1) & 0x55555555;
     if ( (uvar.i|(uvar.i<<1)) != cval )
@@ -91,7 +91,7 @@ int bins::join32to16(uint32_t cval) {
 }
 
 
-void        bins::split (uint32_t half) {
+void        binmap_t::split (uint32_t half) {
     if (deep(half))
         return;
     uint32_t cell = alloc_cell(), left=cell<<1, right=left+1;
@@ -104,7 +104,7 @@ void        bins::split (uint32_t half) {
 }
 
 
-bool        bins::join (uint32_t half) {
+bool        binmap_t::join (uint32_t half) {
     uint32_t cellno = halves[half];
     int left = cellno<<1, right=left+1;
     if (deep(left) || deep(right))
@@ -120,7 +120,7 @@ bool        bins::join (uint32_t half) {
     return true;
 }
 
-void    bins::free_cell (uint16_t cell) {
+void    binmap_t::free_cell (uint16_t cell) {
     cells[cell] = 0;
     int left = cell<<1, right=left+1;
     mark(left);
@@ -131,7 +131,7 @@ void    bins::free_cell (uint16_t cell) {
 }
 
 /** Get a free cell. */
-uint16_t    bins::alloc_cell () {
+uint16_t    binmap_t::alloc_cell () {
     uint16_t ap1 = ap;
     cells_allocated++;
     for(; ap<(blocks_allocated<<4); ap++) {
@@ -165,7 +165,7 @@ bin64_t iterator::next (bool need_solid) {
 }
 
 
-iterator::iterator(bins* host_, bin64_t start, bool split) { 
+iterator::iterator(binmap_t* host_, bin64_t start, bool split) { 
     host = host_;
     half = 0;
     for(int i=0; i<64; i++)
@@ -200,7 +200,7 @@ void iterator::to (bool right) {
 }
 
 
-void bins::extend_range () {
+void binmap_t::extend_range () {
     assert(height<62);
     height++;
     uint16_t newroot = alloc_cell();
@@ -231,7 +231,7 @@ void iterator::parent () {
 }
 
 
-bin64_t bins::find (const bin64_t range, fill_t seek) {
+bin64_t binmap_t::find (const bin64_t range, fill_t seek) {
     iterator i(this,range,true);
     fill_t stop = seek==EMPTY ? FILLED : EMPTY;
     while (true) {
@@ -250,7 +250,7 @@ bin64_t bins::find (const bin64_t range, fill_t seek) {
 }
 
 
-uint16_t bins::get (bin64_t bin) {
+uint16_t binmap_t::get (bin64_t bin) {
     if (bin==bin64_t::NONE)
         return EMPTY;
     iterator i(this,bin,true);
@@ -263,18 +263,18 @@ uint16_t bins::get (bin64_t bin) {
 }
 
 
-void bins::clear () {
+void binmap_t::clear () {
     set(bin64_t(height,0),EMPTY);
 }
 
 
-uint64_t bins::mass () {
+uint64_t binmap_t::mass () {
     iterator i(this,bin64_t(0,0),false);
     uint64_t ret = 0;
     while (!i.solid())
         i.left();
     while (!i.end()) {
-        if (*i==bins::FILLED)
+        if (*i==binmap_t::FILLED)
             ret += i.pos.width();
         i.next(true);
     }
@@ -282,7 +282,7 @@ uint64_t bins::mass () {
 }
 
 
-void bins::set (bin64_t bin, fill_t val) {
+void binmap_t::set (bin64_t bin, fill_t val) {
     if (bin==bin64_t::NONE)
         return;
     assert(val==FILLED || val==EMPTY);
@@ -301,11 +301,11 @@ void bins::set (bin64_t bin, fill_t val) {
 }
 
 
-uint64_t*   bins::get_stripes (int& count) {
+uint64_t*   binmap_t::get_stripes (int& count) {
     int size = 32;
     uint64_t *stripes = (uint64_t*) malloc(32*8);
     count = 0;
-    uint16_t cur = bins::EMPTY;
+    uint16_t cur = binmap_t::EMPTY;
     stripes[count++] = 0;
     iterator i(this,bin64_t(0,0),false);
     while (!i.solid())
@@ -333,7 +333,7 @@ uint64_t*   bins::get_stripes (int& count) {
 }
 
 
-void    bins::remove (bins& b) {
+void    binmap_t::remove (binmap_t& b) {
     uint8_t start_lr = b.height>height ? b.height : height;
     bin64_t top(start_lr,0);
     iterator zis(this,top), zat(&b,top);
@@ -352,7 +352,7 @@ void    bins::remove (bins& b) {
 }
 
 
-bin64_t     bins::cover(bin64_t val) {
+bin64_t     binmap_t::cover(bin64_t val) {
     if (val==bin64_t::NONE)
         return val;
     iterator i(this,val,false);
@@ -364,8 +364,8 @@ bin64_t     bins::cover(bin64_t val) {
 }
 
 
-bin64_t     bins::find_filtered 
-    (bins& filter, bin64_t range, fill_t seek)  
+bin64_t     binmap_t::find_filtered 
+    (binmap_t& filter, bin64_t range, fill_t seek)  
 {
     if (range==bin64_t::ALL)
         range = bin64_t ( height>filter.height ? height : filter.height, 0 );
@@ -392,7 +392,7 @@ bin64_t     bins::find_filtered
 }
 
 // FIXME unite with remove(); do bitwise()
-void        bins::copy_range (bins& origin, bin64_t range) { 
+void        binmap_t::copy_range (binmap_t& origin, bin64_t range) { 
     if (range==bin64_t::ALL)
         range = bin64_t ( height>origin.height ? height : origin.height, 0 );
     iterator zis(this,range,true), zat(&origin,range,true);
@@ -410,7 +410,7 @@ void        bins::copy_range (bins& origin, bin64_t range) {
     }
 }
 
-uint64_t    bins::seq_length () {
+uint64_t    binmap_t::seq_length () {
     iterator i(this);
     if (!i.deep() && *i==FILLED)
         return i.pos.width();
@@ -424,7 +424,7 @@ uint64_t    bins::seq_length () {
 }
 
 
-bool        bins::is_solid (bin64_t range, fill_t val)  {
+bool        binmap_t::is_solid (bin64_t range, fill_t val)  {
     if (range==bin64_t::ALL) 
         return !deep(0) && (is_mixed(val) || halves[0]==val);
     iterator i(this,range,false);
diff --git a/bins.h b/bins.h
index 8d05680..c6a69f1 100644 (file)
--- a/bins.h
+++ b/bins.h
@@ -13,7 +13,7 @@
 /** A binmap covering 2^64 range. Binmap is a hybrid of a bitmap (aka
     bit vector) and a binary tree. The key ability of a binmap is
     the aggregation of solid (all-0 or all-1) ranges. */
-class bins {
+class binmap_t {
     
 public:
     /** Need a 3-valued logic as a range might be either all-0 or all-1
@@ -25,10 +25,10 @@ public:
     typedef enum { FILLED=0xffff, EMPTY=0x0000, MIXED=0x5555 } fill_t;
     static const int NOJOIN;
     
-    bins();
+    binmap_t();
     
     /** Copying constructor. */
-    bins(const bins& b);
+    binmap_t(const binmap_t& b);
     
     /** Get value for the bin. */
     uint16_t    get (bin64_t bin); 
@@ -37,7 +37,7 @@ public:
     void        set (bin64_t bin, fill_t val=FILLED); 
     
     /** Copy a range from another binmap. */
-    void        copy_range (bins& origin, bin64_t range);
+    void        copy_range (binmap_t& origin, bin64_t range);
     
     /** Find the leftmost bin within the specified range which is
         either filled or empty. */
@@ -47,11 +47,11 @@ public:
         either filled or empty. Bins set to 1 in the filter binmap cannot
         be returned. In fact, this is an incremental bitwise op. */
     bin64_t     find_filtered
-        (bins& filter, bin64_t range, fill_t seek=EMPTY) ;
+        (binmap_t& filter, bin64_t range, fill_t seek=EMPTY) ;
     
     /** Bitwise SUB; any bins set to one in the filter binmap should
         be set to 0 in this binmap. */
-    void        remove (bins& filter);
+    void        remove (binmap_t& filter);
     
     void        dump(const char* note);
 
@@ -155,17 +155,17 @@ private:
  or FILLED/EMPTY. */
 class iterator {
 public: // rm this
-    bins        *host;
+    binmap_t        *host;
     uint32_t    history[64];
     uint32_t    half;
     uint8_t     layer_;
     bin64_t     pos;  // TODO: half[] layer bin
 public:
-    iterator(bins* host, bin64_t start=bin64_t(0,0), bool split=false);
+    iterator(binmap_t* host, bin64_t start=bin64_t(0,0), bool split=false);
     ~iterator();
     bool deep () { return host->deep(half); }
     bool solid () { 
-        return !deep() && bins::is_solid(host->halves[half]); 
+        return !deep() && binmap_t::is_solid(host->halves[half]); 
     }
     void sibling () { half^=1; pos=pos.sibling(); }
     bool end () { return half==1; }
index 2a2290d..3132236 100644 (file)
@@ -13,7 +13,7 @@ using namespace p2tp;
 
 class SeqPiecePicker : public PiecePicker {
     
-    bins            ack_hint_out_;
+    binmap_t            ack_hint_out_;
     tbqueue         hint_out_;
     FileTransfer*   transfer_;
     uint64_t        twist_;
@@ -33,7 +33,7 @@ public:
         twist_ = twist;
     }
     
-    virtual bin64_t Pick (bins& offer, uint64_t max_width, tint expires) {
+    virtual bin64_t Pick (binmap_t& offer, uint64_t max_width, tint expires) {
         while (hint_out_.size() && hint_out_.front().time<NOW-TINT_SEC*3/2) { // FIXME sec
             ack_hint_out_.copy_range(file().ack_out(), hint_out_.front().bin);
             hint_out_.pop_front();
@@ -47,7 +47,7 @@ public:
             offer.twist(twist_);
             ack_hint_out_.twist(twist_);
         }
-        bin64_t hint = offer.find_filtered (ack_hint_out_,bin64_t::ALL,bins::FILLED);
+        bin64_t hint = offer.find_filtered (ack_hint_out_,bin64_t::ALL,binmap_t::FILLED);
         if (twist_) {
             hint = hint.twisted(twist_);
             offer.twist(0);
@@ -62,7 +62,7 @@ public:
         }
         while (hint.width()>max_width)
             hint = hint.left();
-        assert(ack_hint_out_.get(hint)==bins::EMPTY);
+        assert(ack_hint_out_.get(hint)==binmap_t::EMPTY);
         ack_hint_out_.set(hint);
         hint_out_.push_back(tintbin(NOW,hint));
         return hint;
index 0a4626f..47213e7 100644 (file)
@@ -286,14 +286,14 @@ bool            HashTree::OfferHash (bin64_t pos, const Sha1Hash& hash) {
         return false;
     if (peak==pos)
         return hash == hashes_[pos];
-    if (ack_out_.get(pos.parent())!=bins::EMPTY)
+    if (ack_out_.get(pos.parent())!=binmap_t::EMPTY)
         return hash==hashes_[pos]; // have this hash already, even accptd data
     hashes_[pos] = hash;
     if (!pos.is_base())
         return false; // who cares?
     bin64_t p = pos;
     Sha1Hash uphash = hash;
-    while ( p!=peak && ack_out_.get(p)==bins::EMPTY ) {
+    while ( p!=peak && ack_out_.get(p)==binmap_t::EMPTY ) {
         hashes_[p] = uphash;
         p = p.parent();
         uphash = Sha1Hash(hashes_[p.left()],hashes_[p.right()]) ;
@@ -309,7 +309,7 @@ bool            HashTree::OfferData (bin64_t pos, const char* data, size_t lengt
         return false;
     if (length<1024 && pos!=bin64_t(0,sizek_-1))
         return false;
-    if (ack_out_.get(pos)==bins::FILLED)
+    if (ack_out_.get(pos)==binmap_t::FILLED)
         return true; // to set data_in_
     bin64_t peak = peak_for(pos);
     if (peak==bin64_t::NONE)
@@ -322,7 +322,7 @@ bool            HashTree::OfferData (bin64_t pos, const char* data, size_t lengt
     }
 
     //printf("g %lli %s\n",(uint64_t)pos,hash.hex().c_str());
-    ack_out_.set(pos,bins::FILLED);
+    ack_out_.set(pos,binmap_t::FILLED);
     pwrite(fd_,data,length,pos.base_offset()<<10);
     complete_ += length;
     completek_++;
index 8e877d4..7878bf1 100644 (file)
@@ -70,7 +70,7 @@ class HashTree {
     /**    Part of the tree currently checked. */
     size_t          complete_;
     size_t          completek_;
-    bins            ack_out_;
+    binmap_t            ack_out_;
     
 protected:
     
@@ -122,7 +122,7 @@ public:
     bool            is_complete () 
         { return size_ && complete_==size_; }
     /** The binmap of complete packets. */
-    bins&           ack_out () { return ack_out_; }
+    binmap_t&           ack_out () { return ack_out_; }
     
     ~HashTree ();
 
diff --git a/p2tp.h b/p2tp.h
index df26eef..6812db5 100644 (file)
--- a/p2tp.h
+++ b/p2tp.h
@@ -152,7 +152,7 @@ namespace p2tp {
             return fd<files.size() ? files[fd] : NULL;
         }
 
-        bins&           ack_out ()  { return file_.ack_out(); }
+        binmap_t&           ack_out ()  { return file_.ack_out(); }
         PiecePicker&    picker () { return *picker_; }
         int             channel_count () const { return hs_in_.size(); }
         HashTree&       file() { return file_; }
@@ -196,7 +196,7 @@ namespace p2tp {
     class PiecePicker {
     public:
         virtual void Randomize (uint64_t twist) = 0;
-        virtual bin64_t Pick (bins& offered, uint64_t max_width, tint expires) = 0;
+        virtual bin64_t Pick (binmap_t& offered, uint64_t max_width, tint expires) = 0;
     };
 
 
@@ -307,7 +307,7 @@ namespace p2tp {
         uint32_t    peer_channel_id_;
         bool        own_id_mentioned_;
         /**    Peer's progress, based on acknowledgements. */
-        bins        ack_in_;
+        binmap_t        ack_in_;
         /**    Last data received; needs to be acked immediately. */
         tintbin     data_in_;
         bin64_t     data_in_dbl_;
@@ -315,7 +315,7 @@ namespace p2tp {
         tbqueue     data_out_;
         bin64_t     data_out_cap_;
         /** Index in the history array. */
-        bins        ack_out_;
+        binmap_t        ack_out_;
         /**    Transmit schedule: in most cases filled with the peer's hints */
         tbqueue     hint_in_;
         /** Hints sent (to detect and reschedule ignored hints). */
index e651eb4..02dc62b 100644 (file)
@@ -34,7 +34,7 @@ void    Channel::AddPeakHashes (Datagram& dgram) {
 void    Channel::AddUncleHashes (Datagram& dgram, bin64_t pos) {
     bin64_t peak = file().peak_for(pos);
     while (pos!=peak && ((NOW&3)==3 || !data_out_cap_.within(pos.parent())) &&
-            ack_in_.get(pos.parent())==bins::EMPTY  ) {
+            ack_in_.get(pos.parent())==binmap_t::EMPTY  ) {
         bin64_t uncle = pos.sibling();
         dgram.Push8(P2TP_HASH);
         dgram.Push32((uint32_t)uncle);
@@ -53,7 +53,7 @@ bin64_t        Channel::DequeueHint () {
         file().ack_out().twist(twist);
         ack_in_.twist(twist);
         bin64_t my_pick = 
-            file().ack_out().find_filtered(ack_in_,bin64_t::ALL,bins::FILLED);
+            file().ack_out().find_filtered(ack_in_,bin64_t::ALL,binmap_t::FILLED);
         while (my_pick.width()>max(1,(int)cwnd_))
             my_pick = my_pick.left();
         file().ack_out().twist(0);
@@ -75,7 +75,7 @@ bin64_t        Channel::DequeueHint () {
         }
         //if (time < NOW-TINT_SEC*3/2 )
         //    continue;  bad idea
-        if (ack_in_.get(hint)!=bins::FILLED) 
+        if (ack_in_.get(hint)!=binmap_t::FILLED) 
             send = hint;
     }
     uint64_t mass = 0;
@@ -254,7 +254,7 @@ void    Channel::AddAck (Datagram& dgram) {
             data_in_dbl_ = pos;
     }
     for(int count=0; count<4; count++) {
-        bin64_t ack = file().ack_out().find_filtered(ack_out_, bin64_t::ALL, bins::FILLED);
+        bin64_t ack = file().ack_out().find_filtered(ack_out_, bin64_t::ALL, binmap_t::FILLED);
         if (ack==bin64_t::NONE)
             break;
         ack = file().ack_out().cover(ack);
@@ -439,7 +439,7 @@ void Channel::OnTs (Datagram& dgram) {
 void    Channel::OnHint (Datagram& dgram) {
     bin64_t hint = dgram.Pull32();
     hint_in_.push_back(hint);
-    //ack_in_.set(hint,bins::EMPTY);
+    //ack_in_.set(hint,binmap_t::EMPTY);
     //RequeueSend(cc_->OnHintRecvd(hint));
     dprintf("%s #%u -hint %s\n",tintstr(),id,hint.str());
 }
index 7d5d2c4..0b42936 100755 (executable)
@@ -16,40 +16,40 @@ TEST(BinsTest,Routines) {
 
     uint32_t cell = (3<<10) | (3<<14) | (3<<0);
     uint16_t correct = (1<<5) | (1<<7) | (1<<0);
-    uint16_t joined  = bins::join32to16(cell);
+    uint16_t joined  = binmap_t::join32to16(cell);
     EXPECT_EQ(correct,joined);
     
-    uint32_t split = bins::split16to32(correct);
+    uint32_t split = binmap_t::split16to32(correct);
     EXPECT_EQ(cell,split);
     
-    EXPECT_EQ(bins::NOJOIN,bins::join32to16(cell|4));
+    EXPECT_EQ(binmap_t::NOJOIN,binmap_t::join32to16(cell|4));
 
 }
 
 TEST(BinsTest,SetGet) {
 
-    bins bs;
+    binmap_t bs;
     bin64_t b3(1,0), b2(0,1), b4(0,2), b6(1,1), b7(2,0);
     bs.set(b3);
     //bs.dump("set done");
-    EXPECT_EQ(bins::FILLED,bs.get(b3));
+    EXPECT_EQ(binmap_t::FILLED,bs.get(b3));
     //bs.dump("set checkd");
-    EXPECT_EQ(bins::FILLED,bs.get(b2));
+    EXPECT_EQ(binmap_t::FILLED,bs.get(b2));
     //bs.dump("get b2 done");
-    EXPECT_EQ(bins::FILLED,bs.get(b3));
+    EXPECT_EQ(binmap_t::FILLED,bs.get(b3));
     //bs.dump("get b3 done");
-    EXPECT_EQ(bins::EMPTY,bs.get(b4));
-    EXPECT_EQ(bins::EMPTY,bs.get(b6));
-    EXPECT_NE(bins::FILLED,bs.get(b7));
-    EXPECT_NE(bins::EMPTY,bs.get(b7));
-    EXPECT_EQ(bins::FILLED,bs.get(b3));
+    EXPECT_EQ(binmap_t::EMPTY,bs.get(b4));
+    EXPECT_EQ(binmap_t::EMPTY,bs.get(b6));
+    EXPECT_NE(binmap_t::FILLED,bs.get(b7));
+    EXPECT_NE(binmap_t::EMPTY,bs.get(b7));
+    EXPECT_EQ(binmap_t::FILLED,bs.get(b3));
     bs.set(bin64_t(1,1));
-    EXPECT_EQ(bins::FILLED,bs.get(bin64_t(2,0)));
+    EXPECT_EQ(binmap_t::FILLED,bs.get(bin64_t(2,0)));
 
 }
 
 TEST(BinsTest,Iterator) {
-    bins b;
+    binmap_t b;
     b.set(bin64_t(3,1));
     iterator i(&b,bin64_t(0,0),false);
     while (!i.solid())
@@ -57,69 +57,69 @@ TEST(BinsTest,Iterator) {
     EXPECT_EQ(bin64_t(3,0),i.bin());
     EXPECT_EQ(false,i.deep());
     EXPECT_EQ(true,i.solid());
-    EXPECT_EQ(bins::EMPTY,*i);
+    EXPECT_EQ(binmap_t::EMPTY,*i);
     i.next();
     EXPECT_EQ(bin64_t(3,1),i.bin());
     EXPECT_EQ(false,i.deep());
     EXPECT_EQ(true,i.solid());
-    EXPECT_EQ(bins::FILLED,*i);
+    EXPECT_EQ(binmap_t::FILLED,*i);
     i.next();
     EXPECT_TRUE(i.end());
 }
 
 TEST(BinsTest,Chess) {
-    bins chess16;
+    binmap_t chess16;
     for(int i=0; i<15; i++)
-        chess16.set(bin64_t(0,i), (i&1)?bins::FILLED:bins::EMPTY);
-    chess16.set(bin64_t(0,15), bins::FILLED);
+        chess16.set(bin64_t(0,i), (i&1)?binmap_t::FILLED:binmap_t::EMPTY);
+    chess16.set(bin64_t(0,15), binmap_t::FILLED);
     for(int i=0; i<16; i++)
-        EXPECT_EQ((i&1)?bins::FILLED:bins::EMPTY, chess16.get(bin64_t(0,i)));
-    EXPECT_NE(bins::FILLED,chess16.get(bin64_t(4,0)));
-    EXPECT_NE(bins::EMPTY,chess16.get(bin64_t(4,0)));
+        EXPECT_EQ((i&1)?binmap_t::FILLED:binmap_t::EMPTY, chess16.get(bin64_t(0,i)));
+    EXPECT_NE(binmap_t::FILLED,chess16.get(bin64_t(4,0)));
+    EXPECT_NE(binmap_t::EMPTY,chess16.get(bin64_t(4,0)));
     for(int i=0; i<16; i+=2)
-        chess16.set(bin64_t(0,i), bins::FILLED);
-    EXPECT_EQ(bins::FILLED,chess16.get(bin64_t(4,0)));
-    EXPECT_EQ(bins::FILLED,chess16.get(bin64_t(2,3)));
+        chess16.set(bin64_t(0,i), binmap_t::FILLED);
+    EXPECT_EQ(binmap_t::FILLED,chess16.get(bin64_t(4,0)));
+    EXPECT_EQ(binmap_t::FILLED,chess16.get(bin64_t(2,3)));
     
-    chess16.set(bin64_t(4,1),bins::FILLED);
-    EXPECT_EQ(bins::FILLED,chess16.get(bin64_t(5,0)));
+    chess16.set(bin64_t(4,1),binmap_t::FILLED);
+    EXPECT_EQ(binmap_t::FILLED,chess16.get(bin64_t(5,0)));
 }
 
 TEST(BinsTest,Staircase) {
     
     const int TOPLAYR = 44;
-    bins staircase;
+    binmap_t staircase;
     for(int i=0;i<TOPLAYR;i++)
-        staircase.set(bin64_t(i,1),bins::FILLED);
+        staircase.set(bin64_t(i,1),binmap_t::FILLED);
     
-    EXPECT_NE(bins::FILLED,staircase.get(bin64_t(TOPLAYR,0)));
-    EXPECT_NE(bins::EMPTY,staircase.get(bin64_t(TOPLAYR,0)));
+    EXPECT_NE(binmap_t::FILLED,staircase.get(bin64_t(TOPLAYR,0)));
+    EXPECT_NE(binmap_t::EMPTY,staircase.get(bin64_t(TOPLAYR,0)));
 
-    staircase.set(bin64_t(0,0),bins::FILLED);
-    EXPECT_EQ(bins::FILLED,staircase.get(bin64_t(TOPLAYR,0)));
+    staircase.set(bin64_t(0,0),binmap_t::FILLED);
+    EXPECT_EQ(binmap_t::FILLED,staircase.get(bin64_t(TOPLAYR,0)));
 
 }
 
 TEST(BinsTest,Hole) {
     
-    bins hole;
-    hole.set(bin64_t(8,0),bins::FILLED);
-    hole.set(bin64_t(6,1),bins::EMPTY);
-    hole.set(bin64_t(6,2),bins::EMPTY);
-    EXPECT_EQ(bins::FILLED,hole.get(bin64_t(6,0)));
-    EXPECT_EQ(bins::FILLED,hole.get(bin64_t(6,3)));
-    EXPECT_NE(bins::FILLED,hole.get(bin64_t(8,0)));
-    EXPECT_NE(bins::EMPTY,hole.get(bin64_t(8,0)));
-    EXPECT_EQ(bins::EMPTY,hole.get(bin64_t(6,1)));
+    binmap_t hole;
+    hole.set(bin64_t(8,0),binmap_t::FILLED);
+    hole.set(bin64_t(6,1),binmap_t::EMPTY);
+    hole.set(bin64_t(6,2),binmap_t::EMPTY);
+    EXPECT_EQ(binmap_t::FILLED,hole.get(bin64_t(6,0)));
+    EXPECT_EQ(binmap_t::FILLED,hole.get(bin64_t(6,3)));
+    EXPECT_NE(binmap_t::FILLED,hole.get(bin64_t(8,0)));
+    EXPECT_NE(binmap_t::EMPTY,hole.get(bin64_t(8,0)));
+    EXPECT_EQ(binmap_t::EMPTY,hole.get(bin64_t(6,1)));
     
 }
 
 TEST(BinsTest,Find){
     
-    bins hole;
-    hole.set(bin64_t(4,0),bins::FILLED);
-    hole.set(bin64_t(1,1),bins::EMPTY);
-    hole.set(bin64_t(0,7),bins::EMPTY);
+    binmap_t hole;
+    hole.set(bin64_t(4,0),binmap_t::FILLED);
+    hole.set(bin64_t(1,1),binmap_t::EMPTY);
+    hole.set(bin64_t(0,7),binmap_t::EMPTY);
     bin64_t f = hole.find(bin64_t(4,0)).left_foot();
     EXPECT_EQ(bin64_t(0,2),f);
     
@@ -127,11 +127,11 @@ TEST(BinsTest,Find){
 
 TEST(BinsTest,Stripes) {
     
-    bins zebra;
+    binmap_t zebra;
     zebra.set(bin64_t(5,0));
-    zebra.set(bin64_t(3,1),bins::EMPTY);
-    zebra.set(bin64_t(1,12),bins::EMPTY);
-    zebra.set(bin64_t(1,14),bins::EMPTY);
+    zebra.set(bin64_t(3,1),binmap_t::EMPTY);
+    zebra.set(bin64_t(1,12),binmap_t::EMPTY);
+    zebra.set(bin64_t(1,14),binmap_t::EMPTY);
     int count;
     uint64_t *stripes = zebra.get_stripes(count);
     EXPECT_EQ(9,count);
@@ -150,7 +150,7 @@ TEST(BinsTest,Stripes) {
 
 TEST(BinsTest,StripesAgg) {
     
-    bins zebra;
+    binmap_t zebra;
     zebra.set(bin64_t(0,1));
     zebra.set(bin64_t(0,2));
     int count;
@@ -165,30 +165,30 @@ TEST(BinsTest,StripesAgg) {
 
 TEST(BinsTest,Alloc) {
 
-    bins b;
+    binmap_t b;
     b.set(bin64_t(1,0));
     b.set(bin64_t(1,1));
-    b.set(bin64_t(1,0),bins::EMPTY);
-    b.set(bin64_t(1,1),bins::EMPTY);
+    b.set(bin64_t(1,0),binmap_t::EMPTY);
+    b.set(bin64_t(1,1),binmap_t::EMPTY);
     EXPECT_EQ(1,b.size());
 
 }
 
 TEST(BinsTest,Remove) {
     
-    bins b;
+    binmap_t b;
     b.set(bin64_t(5,0));
-    bins c;
+    binmap_t c;
     c.set(bin64_t(2,0));
     c.set(bin64_t(2,2));
     b.remove(c);
-    EXPECT_EQ(bins::EMPTY,b.get(bin64_t(2,0)));
-    EXPECT_EQ(bins::FILLED,b.get(bin64_t(2,1)));
-    EXPECT_EQ(bins::EMPTY,b.get(bin64_t(2,2)));
-    EXPECT_EQ(bins::FILLED,b.get(bin64_t(2,3)));
-    EXPECT_EQ(bins::FILLED,b.get(bin64_t(4,1)));
+    EXPECT_EQ(binmap_t::EMPTY,b.get(bin64_t(2,0)));
+    EXPECT_EQ(binmap_t::FILLED,b.get(bin64_t(2,1)));
+    EXPECT_EQ(binmap_t::EMPTY,b.get(bin64_t(2,2)));
+    EXPECT_EQ(binmap_t::FILLED,b.get(bin64_t(2,3)));
+    EXPECT_EQ(binmap_t::FILLED,b.get(bin64_t(4,1)));
     
-    bins b16, b1024, b8192;
+    binmap_t b16, b1024, b8192;
     b16.set(bin64_t(3,1));
     b1024.set(bin64_t(3,1));
     b1024.set(bin64_t(4,2));
@@ -199,22 +199,22 @@ TEST(BinsTest,Remove) {
     b1024.remove(b16);
     b1024.remove(b8192);
     
-    EXPECT_EQ(bins::EMPTY,b1024.get(bin64_t(3,1)));
-    EXPECT_EQ(bins::EMPTY,b1024.get(bin64_t(5,0)));
-    EXPECT_EQ(bins::EMPTY,b1024.get(bin64_t(9,1)));
-    EXPECT_EQ(bins::EMPTY,b1024.get(bin64_t(12,1)));
-    EXPECT_EQ(bins::FILLED,b1024.get(bin64_t(4,2)));
+    EXPECT_EQ(binmap_t::EMPTY,b1024.get(bin64_t(3,1)));
+    EXPECT_EQ(binmap_t::EMPTY,b1024.get(bin64_t(5,0)));
+    EXPECT_EQ(binmap_t::EMPTY,b1024.get(bin64_t(9,1)));
+    EXPECT_EQ(binmap_t::EMPTY,b1024.get(bin64_t(12,1)));
+    EXPECT_EQ(binmap_t::FILLED,b1024.get(bin64_t(4,2)));
     
     b8192.set(bin64_t(2,3));
     b16.remove(b8192);
-    EXPECT_EQ(bins::EMPTY,b16.get(bin64_t(2,3)));
-    EXPECT_EQ(bins::FILLED,b16.get(bin64_t(2,2)));
+    EXPECT_EQ(binmap_t::EMPTY,b16.get(bin64_t(2,3)));
+    EXPECT_EQ(binmap_t::FILLED,b16.get(bin64_t(2,2)));
     
 }
 
 TEST(BinsTest,FindFiltered) {
     
-    bins data, filter;
+    binmap_t data, filter;
     data.set(bin64_t(2,0));
     data.set(bin64_t(2,2));
     data.set(bin64_t(1,7));
@@ -230,13 +230,13 @@ TEST(BinsTest,FindFiltered) {
 
 TEST(BinsTest, Cover) {
     
-    bins b;
+    binmap_t b;
     b.set(bin64_t(2,0));
     b.set(bin64_t(4,1));
     EXPECT_EQ(bin64_t(4,1),b.cover(bin64_t(0,30)));
     EXPECT_EQ(bin64_t(2,0),b.cover(bin64_t(0,3)));
     EXPECT_EQ(bin64_t(2,0),b.cover(bin64_t(2,0)));
-    //bins c;
+    //binmap_t c;
     //EXPECT_EQ(bin64_t::ALL,b.cover(bin64_t(0,30)));
     
 }
@@ -244,12 +244,12 @@ TEST(BinsTest, Cover) {
 
 TEST(BinsTest,FindFiltered2) {
     
-    bins data, filter;
+    binmap_t data, filter;
     for(int i=0; i<1024; i+=2)
         data.set(bin64_t(0,i));
     for(int j=1; j<1024; j+=2)
         filter.set(bin64_t(0,j));
-    filter.set(bin64_t(0,501),bins::EMPTY);
+    filter.set(bin64_t(0,501),binmap_t::EMPTY);
     EXPECT_EQ(bin64_t(0,501),data.find_filtered(filter,bin64_t(10,0)).left_foot());
     data.set(bin64_t(0,501));
     EXPECT_EQ(bin64_t::NONE,data.find_filtered(filter,bin64_t(10,0)).left_foot());
@@ -257,7 +257,7 @@ TEST(BinsTest,FindFiltered2) {
 }
     
 TEST(BinsTest,CopyRange) {
-    bins data, add;
+    binmap_t data, add;
     data.set(bin64_t(2,0));
     data.set(bin64_t(2,2));
     data.set(bin64_t(1,7));
@@ -266,49 +266,49 @@ TEST(BinsTest,CopyRange) {
     add.set(bin64_t(0,13));
     add.set(bin64_t(5,118));
     data.copy_range(add, bin64_t(3,0));
-    EXPECT_TRUE(bins::is_mixed(data.get(bin64_t(3,0))));
-    EXPECT_EQ(bins::EMPTY,data.get(bin64_t(2,0)));
-    EXPECT_EQ(bins::FILLED,data.get(bin64_t(2,1)));
-    EXPECT_EQ(bins::EMPTY,data.get(bin64_t(1,6)));
-    EXPECT_EQ(bins::FILLED,data.get(bin64_t(1,7)));
+    EXPECT_TRUE(binmap_t::is_mixed(data.get(bin64_t(3,0))));
+    EXPECT_EQ(binmap_t::EMPTY,data.get(bin64_t(2,0)));
+    EXPECT_EQ(binmap_t::FILLED,data.get(bin64_t(2,1)));
+    EXPECT_EQ(binmap_t::EMPTY,data.get(bin64_t(1,6)));
+    EXPECT_EQ(binmap_t::FILLED,data.get(bin64_t(1,7)));
 }
 
 TEST(BinsTest, Mass) {
-    bins b;
-    b.set(bin64_t(6,0),bins::FILLED);
-    b.set(bin64_t(0,0),bins::EMPTY);
+    binmap_t b;
+    b.set(bin64_t(6,0),binmap_t::FILLED);
+    b.set(bin64_t(0,0),binmap_t::EMPTY);
     EXPECT_EQ(63,b.mass());
     EXPECT_FALSE(b.is_empty());
     b.clear();
     EXPECT_TRUE(b.is_empty());
     EXPECT_EQ(0,b.mass());
 
-    bins b50;
+    binmap_t b50;
     for(int i=0; i<50; i++)
         b50.set(bin64_t(4,i*2));
     EXPECT_EQ(50<<4,b50.mass());
 }
 
 TEST(BinsTest,Twist) {
-    bins b;
+    binmap_t b;
     b.set(bin64_t(3,2));
-    EXPECT_EQ(bins::FILLED,b.get(bin64_t(3,2)));
-    EXPECT_EQ(bins::EMPTY,b.get(bin64_t(3,3)));
+    EXPECT_EQ(binmap_t::FILLED,b.get(bin64_t(3,2)));
+    EXPECT_EQ(binmap_t::EMPTY,b.get(bin64_t(3,3)));
     b.twist(1<<3);
-    EXPECT_EQ(bins::FILLED,b.get(bin64_t(3,3)));
-    EXPECT_EQ(bins::EMPTY,b.get(bin64_t(3,2)));
-    bin64_t tw = b.find(bin64_t(5,0),bins::FILLED);
+    EXPECT_EQ(binmap_t::FILLED,b.get(bin64_t(3,3)));
+    EXPECT_EQ(binmap_t::EMPTY,b.get(bin64_t(3,2)));
+    bin64_t tw = b.find(bin64_t(5,0),binmap_t::FILLED);
     while (tw.width()>(1<<3))
         tw = tw.left();
     tw = tw.twisted(1<<3);
     EXPECT_EQ(bin64_t(3,2),tw);
     b.twist(0);
-    EXPECT_EQ(bins::FILLED,b.get(bin64_t(3,2)));
-    EXPECT_EQ(bins::EMPTY,b.get(bin64_t(3,3)));
+    EXPECT_EQ(binmap_t::FILLED,b.get(bin64_t(3,2)));
+    EXPECT_EQ(binmap_t::EMPTY,b.get(bin64_t(3,3)));
 }
 
 TEST(BinsTest,SeqLength) {
-    bins b;
+    binmap_t b;
     b.set(bin64_t(3,0));
     b.set(bin64_t(1,4));
     b.set(bin64_t(0,10));
@@ -318,7 +318,7 @@ TEST(BinsTest,SeqLength) {
 
 TEST(BinsTest,EmptyFilled) {
     // 1112 3312  2111 ....
-    bins b;
+    binmap_t b;
     
     EXPECT_TRUE(b.is_empty(bin64_t::ALL));
     
@@ -332,7 +332,7 @@ TEST(BinsTest,EmptyFilled) {
     
     EXPECT_TRUE(b.is_empty(bin64_t(2,3)));
     EXPECT_FALSE(b.is_filled(bin64_t(2,3)));
-    EXPECT_TRUE(b.is_solid(bin64_t(2,3),bins::MIXED));
+    EXPECT_TRUE(b.is_solid(bin64_t(2,3),binmap_t::MIXED));
     EXPECT_TRUE(b.is_filled(bin64_t(1,0)));
     EXPECT_TRUE(b.is_filled(bin64_t(1,5)));
     EXPECT_FALSE(b.is_filled(bin64_t(1,3)));
@@ -372,7 +372,7 @@ TEST(BinheapTest,Eat) {
 }
 
 /*TEST(BinsTest,AddSub) {
-       bins b;
+       binmap_t b;
        b|=15;
        b-=1;
        ASSERT_TRUE(b.contains(2));
@@ -397,7 +397,7 @@ TEST(BinsTest,Peaks) {
 }
 
 TEST(BinsTest,Performance) {
-       bins b;
+       binmap_t b;
        std::set<int> s;
        clock_t start, end;
        double b_time, s_time;
index 297cb07..721041a 100755 (executable)
@@ -17,7 +17,7 @@
        #define RANDOM  random
 #endif
 
-int bins_stripe_count (bins& b) {
+int bins_stripe_count (binmap_t& b) {
     int stripe_count;
     uint64_t * stripes = b.get_stripes(stripe_count);
     free(stripes);
@@ -35,9 +35,9 @@ uint8_t rand_norm (uint8_t lim) {
 }
 
 TEST(FreemapTest,Freemap) {
-    bins space;
+    binmap_t space;
     const bin64_t top(30,0);
-    space.set(top,bins::EMPTY);
+    space.set(top,binmap_t::EMPTY);
     typedef std::pair<int,bin64_t> timebin_t;
     typedef std::set<timebin_t> ts_t;
     ts_t to_free;
@@ -48,8 +48,8 @@ TEST(FreemapTest,Freemap) {
             while (alloc.layer()>lr)
                 alloc = alloc.left();
             ASSERT_NE(0ULL,~alloc);
-            EXPECT_EQ(bins::EMPTY, space.get(alloc));
-            space.set(alloc,bins::FILLED);
+            EXPECT_EQ(binmap_t::EMPTY, space.get(alloc));
+            space.set(alloc,binmap_t::FILLED);
             long dealloc_time = 1<<rand_norm(22);
             printf("alloc 2**%i starting at %lli for %li ticks\n",
                 (int)lr,(uint64_t)alloc,dealloc_time);
@@ -60,7 +60,7 @@ TEST(FreemapTest,Freemap) {
         while (to_free.begin()->first<=t) {
             bin64_t freebin = to_free.begin()->second;
             to_free.erase(to_free.begin());
-            space.set(freebin,bins::EMPTY);
+            space.set(freebin,binmap_t::EMPTY);
             printf("freed at %lli\n",
                 (uint64_t)freebin);
        }
@@ -72,8 +72,8 @@ TEST(FreemapTest,Freemap) {
         //space.dump("space");
     }
     for(ts_t::iterator i=to_free.begin(); i!=to_free.end(); i++)
-        space.set(i->second,bins::EMPTY);
-    EXPECT_EQ(bins::EMPTY,space.get(top));
+        space.set(i->second,binmap_t::EMPTY);
+    EXPECT_EQ(binmap_t::EMPTY,space.get(top));
 }
 
 int main (int argc, char** argv) {