Binmap flattening sorta tested.
authorVictor Grishchenko <victor.grishchenko@gmail.com>
Tue, 11 May 2010 15:33:00 +0000 (17:33 +0200)
committerVictor Grishchenko <victor.grishchenko@gmail.com>
Tue, 11 May 2010 15:33:00 +0000 (17:33 +0200)
bins.cpp
bins.h
tests/binstest2.cpp

index 22d8798..319a7cd 100644 (file)
--- a/bins.cpp
+++ b/bins.cpp
@@ -179,15 +179,17 @@ uint16_t    binmap_t::alloc_cell () {
 }
 
 
-bin64_t iterator::next (bool need_solid, uint8_t min_layer) {
-    assert( (!deep()) || (layer()==min_layer));
+bin64_t iterator::next (bool stop_undeep, bool stop_solid, uint8_t stop_layer) {
+    //assert( (!deep()) || (layer()==min_layer));
     while (pos.is_right())
         parent();
     //parent();
     //if (need_solid ? !solid() : deep())
     //    right();
     sibling();
-    while ( (need_solid ? !solid() : deep()) && layer()>min_layer )
+    while (     (!stop_undeep || deep()) && 
+                (!stop_solid || (deep() || !solid()) ) && 
+                (layer()>stop_layer)      )
         left();
     return pos;
 }
@@ -304,7 +306,7 @@ uint64_t binmap_t::mass () {
     while (!i.end()) {
         if (*i==binmap_t::FILLED)
             ret += i.pos.width();
-        i.next(true);
+        i.next_solid();
     }
     return ret;
 }
@@ -350,7 +352,7 @@ uint64_t*   binmap_t::get_stripes (int& count) {
             }
         }
 
-        i.next(true);
+        i.next_solid();
 
     }
 
@@ -474,11 +476,8 @@ bool        binmap_t::is_solid (bin64_t range, fill_t val)  {
 }
 
 
-void    binmap_t::map16 (uint16_t* target, bin64_t range, iterator& lead) {
-    while (!range.within(lead.pos))
-        lead.parent();
-    while (lead.pos!=range)
-        lead.towards(range);
+void    binmap_t::map16 (uint16_t* target, bin64_t range) {
+    iterator lead(this,range,true);
     if (!lead.deep()) {
         *target = *lead;
         return;
@@ -492,19 +491,18 @@ void    binmap_t::map16 (uint16_t* target, bin64_t range, iterator& lead) {
         if (!lead.deep() && *lead==FILLED)
             *target |= shift;
         shift<<=1;
-        lead.next(false,range.layer()-4);
+        lead.next(false,false,range.layer()-4);
     }
 }
 
 
 void    binmap_t::to_coarse_bitmap (void* bits, bin64_t range, uint8_t height) {
     uint16_t* bits16 = (uint16_t*) bits;
-    iterator iter(this,range,true);
     int height16 = range.layer()-height-4;
     int wordwidth = 1 << height16;
     int offset = range.offset() << height16;
-    for(int i=offset; i<offset+wordwidth; i++) 
-        map16(bits16+i,bin64_t(height+4,i),iter);
+    for(int i=0; i<wordwidth; i++) 
+        map16(bits16+i,bin64_t(height+4,offset+i));
 }
 
 
diff --git a/bins.h b/bins.h
index 2068e28..a1e66ac 100644 (file)
--- a/bins.h
+++ b/bins.h
@@ -163,7 +163,7 @@ private:
     static uint32_t split16to32(uint16_t half);
     static int join32to16(uint32_t cell);
 
-    void        map16 (uint16_t* target, bin64_t range, iterator& lead);
+    void        map16 (uint16_t* target, bin64_t range);
     
     friend class iterator;
 #ifdef FRIEND_TEST
@@ -198,7 +198,8 @@ public:
     void right() {to(1);}
     /** Move to the next defined (non-deep, flat) cell.
         If solid==true, move to a solid (0xffff/0x0) cell. */
-    bin64_t next (bool solid=false, uint8_t min_layer=0);
+    bin64_t next (bool stop_undeep=true, bool stop_solid=false, uint8_t stop_layer=0);
+    bin64_t next_solid () { return next(false, true,0); }
     bin64_t bin() { return pos; }
     void towards(bin64_t bin) {
         bin64_t next = pos.towards(bin);
index 3cd0d0c..8217bc5 100644 (file)
@@ -416,6 +416,18 @@ TEST(BinsTest,CoarseBitmap) {
     i32=0;
     rough.to_coarse_bitmap(&i32,bin64_t(6,0),1);
     EXPECT_EQ(1,i32);
+    
+    binmap_t ladder;
+    ladder.set(bin64_t(6,2));
+    ladder.set(bin64_t(5,2));
+    ladder.set(bin64_t(4,2));
+    ladder.set(bin64_t(3,2));
+    ladder.set(bin64_t(2,2));
+    ladder.set(bin64_t(1,2));
+    ladder.set(bin64_t(0,2));
+    i32=0;
+    ladder.to_coarse_bitmap(&i32,bin64_t(8,0),3);
+    EXPECT_EQ(0x00ff0f34,i32);
 }
 
 /*TEST(BinsTest,AddSub) {