Example #1
0
TEST(RSDic, random){
  RSDicBuilder bvb;
  vector<int> B;
  const uint64_t n = 100000;
  for (int i = 0; i < n; ++i){
    int b = rand() % 2;
    bvb.PushBack(b);
    B.push_back(b);
  }
  
  RSDic bv;
  bvb.Build(bv);
  ASSERT_EQ(n, bv.num());
  int sum = 0;
  for (size_t i = 0; i < bv.num(); ++i){
    ASSERT_EQ(B[i]  , bv.GetBit(i)) << " i=" << i;
    if (B[i]){
      ASSERT_EQ(sum, bv.Rank(i, 1));
      ASSERT_EQ(i,bv.Select(sum, 1));
    } else {
      ASSERT_EQ(i - sum, bv.Rank(i, 0));
      ASSERT_EQ(i, bv.Select(i-sum, 0));
    }
    sum += B[i];
  }

  ostringstream os;
  bv.Save(os);
  istringstream is(os.str());

  RSDic bv_load;
  bv_load.Load(is);

  ASSERT_EQ(bv, bv_load);
}
Example #2
0
TEST(RSDic, large){
  RSDicBuilder rsdb;
  const uint64_t n = 26843545;
  vector<uint64_t> poses;
  for (uint64_t i = 0; i < n; ++i){
    float r = (float)rand() / RAND_MAX;
    if (r < 0.001) {
      rsdb.PushBack(1);
      poses.push_back(i);
    }
    else rsdb.PushBack(0);
  }

  RSDic bv;
  rsdb.Build(bv);
  uint64_t one_num = bv.one_num();
  for (uint64_t i = 0; i < one_num; ++i){
    ASSERT_EQ(poses[i], bv.Select(i, 1));
  }
}
Example #3
0
void GMR::BuildGMRBitArray(FFLCArray &fflca){

  uint64_t previous = fflca[perm_.Access(0)];
  RSDicBuilder bvb;
  
  for(size_t i = 0; i <= fflca[perm_.Access(0)];i++){
    bvb.PushBack(1);
  }
  bvb.PushBack(0);
  for(size_t i = 1; i < perm_.Length();i++){
    if(previous == fflca[perm_.Access(i)]){
      bvb.PushBack(0);
    }
    else{
      for(size_t j = previous; j < fflca[perm_.Access(i)]; j++){
	bvb.PushBack(1);
      }
      bvb.PushBack(0);
    }
    previous = fflca[perm_.Access(i)];
  }
  bvb.PushBack(1);
  bvb.Build(b_);

}
Example #4
0
TEST(RSDic, trivial_one){
  RSDicBuilder bvb;
  const uint64_t n = 10000;
  for (int i = 0; i < n; ++i){
    bvb.PushBack(1);
  }
  
  RSDic bv;
  bvb.Build(bv);
  ASSERT_EQ(n, bv.num());
  ASSERT_EQ(n, bv.one_num());
  for (size_t i = 0; i < bv.num(); ++i){
    ASSERT_EQ(1, bv.GetBit(i));
    ASSERT_EQ(i, bv.Rank(i, 1)) << " i=" << i;
    ASSERT_EQ(i, bv.Select(i, 1)) << " i=" << i;
  }
}
Example #5
0
TEST(RSDic, small){
  RSDicBuilder bvb;
  const uint64_t n = 65;
  for (int i = 0; i < n; ++i){
    bvb.PushBack(1);
  }
  
  RSDic bv;
  bvb.Build(bv);
  ASSERT_EQ(n, bv.num());
  ASSERT_EQ(n, bv.one_num());
  for (size_t i = 0; i < bv.num(); ++i){
    ASSERT_EQ(1, bv.GetBit(i));
    ASSERT_EQ(i, bv.Rank(i, 1));
    ASSERT_EQ(i, bv.Select(i, 1));
  }
}