#include <assert.h>
#include <stdint.h>
-//#include <stdio.h>
-/** Bin numbers in the tail111 encoding: meaningless
+
+/** Numbering for (aligned) logarithmical bins.
+ Each number stands for an interval
+ [o*2^l,(o+1)*2^l), where l is the layer and o
+ is the offset.
+ Bin numbers in the tail111 encoding: meaningless
bits in the tail are set to 0111...11, while the
head denotes the offset. Thus, 1101 is the bin
at layer 1, offset 3 (i.e. fourth). */
return (v&~short_tail) == (maybe_asc.v&~short_tail) ;
}
- bin64_t towards (bin64_t desc) const {
- if (!desc.within(*this))
+ /** Left or right, depending whether the destination is. */
+ bin64_t towards (bin64_t dest) const {
+ if (!dest.within(*this))
return NONE;
- if (desc.within(left()))
+ if (dest.within(left()))
return left();
else
return right();
return bin64_t(0,base_offset());
}
+ /** Whether layer is 0. */
bool is_base () const {
return !(v & 1);
}
+ /** Depth-first in-order binary tree traversal. */
bin64_t next_dfsio (uint8_t floor);
bin64_t width () const {
}
+TEST(BinsTest,Remove) {
+
+ bins b;
+ b.set(bin64_t(5,0));
+ bins 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)));
+
+}
+
/*TEST(BinsTest,AddSub) {
bins b;
b|=15;
E000 = Sha1Hash(E0,Sha1Hash::ZERO);
ABCDE000 = Sha1Hash(ABCD,E000);
ROOT = ABCDE000;
- for (int i=0; i<60; i++)
+ for (bin64_t pos(3,0); pos!=bin64_t::ALL; pos=pos.parent())
ROOT = Sha1Hash(ROOT,Sha1Hash::ZERO);
// submit a new file
leech->OfferHash(bin64_t(1,0), seed->hashes[bin64_t(1,0)]);
leech->OfferHash(bin64_t(1,1), seed->hashes[bin64_t(1,1)]);
for (int i=0; i<4; i++) {
- /*if (leech->complete()==trap) {
+ /*if (leech->seq_complete==3) {
delete leech;
- FileTransfer* leech = new FileTransfer(seed,"copy");
+ leech = new FileTransfer(seed,"copy");
+ EXPECT_EQ(3,leech->complete);
}*/
bin64_t next = leech->picker->Pick(seed->ack_out,0);
uint8_t buf[1024]; //size_t len = seed->storer->ReadData(next,&buf);