本文整理汇总了C++中bit_vector::size方法的典型用法代码示例。如果您正苦于以下问题:C++ bit_vector::size方法的具体用法?C++ bit_vector::size怎么用?C++ bit_vector::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bit_vector
的用法示例。
在下文中一共展示了bit_vector::size方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: go
bit_vector YaoChooser::go(Circuit_p cc, FmtFile &fmt, const bit_vector &inputs) {
FmtFile::VarDesc vars = fmt.getVarDesc();
GarbledCircuit_p gcc = GarbledCircuit::readCircuit(in);
vector<SFEKey_p> yourinpsecs;
readVector(in, yourinpsecs);
uint ot_size = in->readInt();
if (ot_size != inputs.size())
throw new ProtocolException(cstr_printf(
"ot_size %d != inputs.size %d", ot_size, inputs.size()));
pinkasnaor::OT ot;
bit_vector inputs_copy(inputs);
pinkasnaor::Chooser chooser(inputs_copy, &ot);
chooser.setStreams(in, out);
chooser.precalc();
BigInt_Vect myinpsecs = chooser.online();
GCircuitEval geval;
vector<SecretKey_p> gcirc_input(cc->inputs.size());
int ja=0;
int jb=0;
for (uint i=0; i<gcirc_input.size(); ++i) {
if (vars.who.at(i) == "A") {
gcirc_input[i] = yourinpsecs.at(ja++);
} else if (vars.who.at(i) == "B") {
gcirc_input[i] = SFEKey_p(new SFEKey(
new byte_buf(BigInt::fromPaddedBigInt(myinpsecs.at(jb++))), true));
}
}
bit_vector circ_out = geval.eval(*gcc, gcirc_input);
return circ_out;
}
示例2: serialize_bit_vector
void serialize_bit_vector(std::ostream &out, const bit_vector &v)
{
out << v.size() << "\n";
for (size_t i = 0; i < v.size(); ++i)
{
out << v[i] << "\n";
}
}
示例3:
bit_vector vert::operator&( const bit_vector &rhs, const bit_vector &lhs ) {
bit_vector result;
std::size_t maxSize = std::max( rhs.size(), lhs.size() );
for( std::size_t i = 0; i < maxSize; ++i ) {
result.append( i < rhs.size() && rhs[i] && i < lhs.size() && lhs[i] );
}
return result;
}
示例4:
void
bit_vector::and_op(const bit_vector& v)
{
uint sz = m_size;
const uchar* vbuf = v.buf();
if (v.size() < sz)
sz = v.size();
for (uint o=0; o<sz; o++) {
m_buf[o] &= vbuf[o];
}
// shorten our size if v is smaller than us
if (sz < m_size)
m_size=sz;
}
示例5:
gap_vector(const bit_vector& bv) {
m_size = bv.size();
if (m_size == 0)
return;
size_type ones = util::get_one_bits(bv);
m_position = int_vector<>(ones, 0, bit_magic::l1BP(m_size)+1);
const uint64_t* bvp = bv.data();
for (size_type i=0, one_cnt=0; i < (bv.size()+63)/64; ++i, ++bvp) {
if (*bvp) { // if there is a one in the word
for (size_type j=0; j<64 and 64*i+j < bv.size(); ++j) // check each bit of the word
if (bv[64*i+j]) {
m_position[one_cnt++] = 64*i+j;
}
}
}
}
示例6: assert
r1cs_primary_input<FieldT> l_input_map(const bit_vector &h1,
const bit_vector &h2,
const bit_vector &x
)
{
// Construct the multipacked field points which encode
// the verifier's knowledge. This is the "dual" of the
// multipacking gadget logic in the constructor.
assert(h1.size() == sha256_digest_len);
assert(h2.size() == sha256_digest_len);
assert(x.size() == sha256_digest_len);
bit_vector input_as_bits;
input_as_bits.insert(input_as_bits.end(), h1.begin(), h1.end());
input_as_bits.insert(input_as_bits.end(), h2.begin(), h2.end());
input_as_bits.insert(input_as_bits.end(), x.begin(), x.end());
std::vector<FieldT> input_as_field_elements = pack_bit_vector_into_field_element_vector<FieldT>(input_as_bits);
return input_as_field_elements;
}
示例7: logic_error
/*! \param v The supported bit_vector.
*/
nearest_neighbour_dictionary(const bit_vector& v):m_ones(0), m_size(0) {
if (sample_dens==0) { // first logical error check
throw std::logic_error(util::demangle(typeid(this).name())+": sample_dens should not be equal 0!");
}
size_type max_distance_between_two_ones = 0;
size_type ones = 0; // counter for the ones in v
// get maximal distance between to ones in the bit vector
// speed this up by broadword computing
for (size_type i=0, last_one_pos_plus_1=0; i < v.size(); ++i) {
if (v[i]) {
if (i+1-last_one_pos_plus_1 > max_distance_between_two_ones)
max_distance_between_two_ones = i+1-last_one_pos_plus_1;
last_one_pos_plus_1 = i+1;
++ones;
}
}
m_ones = ones;
m_size = v.size();
// std::cerr<<ones<<std::endl;
// initialize absolute samples m_abs_samples[0]=0
m_abs_samples = int_vector<>(m_ones/sample_dens + 1, 0, bits::hi(v.size())+1);
// initialize different values
m_differences = int_vector<>(m_ones - m_ones/sample_dens, 0, bits::hi(max_distance_between_two_ones)+1);
// initialize m_contains_abs_sample
m_contains_abs_sample = bit_vector((v.size()+sample_dens-1)/sample_dens, 0);
ones = 0;
for (size_type i=0, last_one_pos=0; i < v.size(); ++i) {
if (v[i]) {
++ones;
if ((ones % sample_dens) == 0) { // insert absolute samples
m_abs_samples[ones/sample_dens] = i;
m_contains_abs_sample[i/sample_dens] = 1;
} else {
m_differences[ones - ones/sample_dens - 1] = i - last_one_pos;
}
last_one_pos = i;
}
}
util::init_support(m_rank_contains_abs_sample, &m_contains_abs_sample);
}
示例8: shift_bit_vector
///
/// @brief shift a bit vector to left or right @a num times
///
void shift_bit_vector(bit_vector &v, int num, bool to_left)
{
#ifdef DEBUG
cout<<"before shifting to "<<(to_left? "left" : "right")<<" : ";
for (int i = v.size() - 1; i >= 0; --i) {
cout<<(v[i]? 1 : 0);
}
cout<<endl;
#endif
if (to_left) {
for (int i = v.size() - 1; i >= num; --i) {
v[i] = v[i - num];
}
for (int i = 0; i < num; ++i) {
v[i] = 0;
}
} else {
for (int i = 0; i < v.size() - num; ++i) {
v[i] = v[i + num];
}
for (int i = v.size() - num; i < v.size(); ++i) {
v[i] = 0;
}
}
#ifdef DEBUG
cout<<"after shifting to "<<(to_left? "left" : "right")<<" : ";
for (int i = v.size() - 1; i >= 0; --i) {
cout<<(v[i]? 1 : 0);
}
cout<<endl;
#endif
}
示例9: darray
darray(bit_vector const& bv)
: m_positions()
{
mapper::mappable_vector<uint64_t> const& data = bv.data();
std::vector<uint64_t> cur_block_positions;
std::vector<int64_t> block_inventory;
std::vector<uint16_t> subblock_inventory;
std::vector<uint64_t> overflow_positions;
for (uint64_t word_idx = 0; word_idx < data.size(); ++word_idx) {
uint64_t cur_pos = word_idx * 64;
uint64_t cur_word = WordGetter()(data, word_idx);
unsigned long l;
while (broadword::lsb(cur_word, l)) {
cur_pos += l;
cur_word >>= l;
if (cur_pos >= bv.size()) break;
cur_block_positions.push_back(cur_pos);
if (cur_block_positions.size() == block_size) {
flush_cur_block(cur_block_positions, block_inventory, subblock_inventory, overflow_positions);
}
// can't do >>= l + 1, can be 64
cur_word >>= 1;
cur_pos += 1;
m_positions += 1;
}
}
if (cur_block_positions.size()) {
flush_cur_block(cur_block_positions, block_inventory, subblock_inventory, overflow_positions);
}
m_block_inventory.steal(block_inventory);
m_subblock_inventory.steal(subblock_inventory);
m_overflow_positions.steal(overflow_positions);
}
示例10: size
size_type size()const {
return m_sct_bp.size()/2;
}
示例11: while
/*!
* \param bv Uncompressed bitvector.
* \param k Store rank samples and pointers each k-th blocks.
*/
rrr_vector(const bit_vector& bv) {
m_size = bv.size();
int_vector<> bt_array;
bt_array.width(bits::hi(t_bs)+1);
bt_array.resize((m_size+t_bs)/((size_type)t_bs)); // blocks for the bt_array + a dummy block at the end,
// if m_size%t_bs == 0
// (1) calculate the block types and store them in m_bt
size_type pos = 0, i = 0, x;
size_type btnr_pos = 0;
size_type sum_rank = 0;
while (pos + t_bs <= m_size) { // handle all blocks full blocks
bt_array[ i++ ] = x = rrr_helper_type::get_bt(bv, pos, t_bs);
sum_rank += x;
btnr_pos += rrr_helper_type::space_for_bt(x);
pos += t_bs;
}
if (pos < m_size) { // handle last not full block
bt_array[ i++ ] = x = rrr_helper_type::get_bt(bv, pos, m_size - pos);
sum_rank += x;
btnr_pos += rrr_helper_type::space_for_bt(x);
}
m_btnr = bit_vector(std::max(btnr_pos, (size_type)64), 0); // max necessary for case: t_bs == 1
m_btnrp = int_vector<>((bt_array.size()+t_k-1)/t_k, 0, bits::hi(btnr_pos)+1);
m_rank = int_vector<>((bt_array.size()+t_k-1)/t_k + ((m_size % (t_k*t_bs))>0), 0, bits::hi(sum_rank)+1);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// only add a finishing block, if the last block of the superblock is not a dummy block
m_invert = bit_vector((bt_array.size()+t_k-1)/t_k, 0);
// (2) calculate block type numbers and pointers into btnr and rank samples
pos = 0; i = 0;
btnr_pos= 0, sum_rank = 0;
bool invert = false;
while (pos + t_bs <= m_size) { // handle all full blocks
if ((i % t_k) == (size_type)0) {
m_btnrp[ i/t_k ] = btnr_pos;
m_rank[ i/t_k ] = sum_rank;
// calculate invert bit for that superblock
if (i+t_k <= bt_array.size()) {
size_type gt_half_t_bs = 0; // counter for blocks greater than half of the blocksize
for (size_type j=i; j < i+t_k; ++j) {
if (bt_array[j] > t_bs/2)
++gt_half_t_bs;
}
if (gt_half_t_bs > (t_k/2)) {
m_invert[ i/t_k ] = 1;
for (size_type j=i; j < i+t_k; ++j) {
bt_array[j] = t_bs - bt_array[j];
}
invert = true;
} else {
invert = false;
}
} else {
invert = false;
}
}
uint16_t space_for_bt = rrr_helper_type::space_for_bt(x=bt_array[i++]);
sum_rank += (invert ? (t_bs - x) : x);
if (space_for_bt) {
number_type bin = rrr_helper_type::decode_btnr(bv, pos, t_bs);
number_type nr = rrr_helper_type::bin_to_nr(bin);
rrr_helper_type::set_bt(m_btnr, btnr_pos, nr, space_for_bt);
}
btnr_pos += space_for_bt;
pos += t_bs;
}
if (pos < m_size) { // handle last not full block
if ((i % t_k) == (size_type)0) {
m_btnrp[ i/t_k ] = btnr_pos;
m_rank[ i/t_k ] = sum_rank;
m_invert[ i/t_k ] = 0; // default: set last block to not inverted
invert = false;
}
uint16_t space_for_bt = rrr_helper_type::space_for_bt(x=bt_array[i++]);
// no extra dummy block added to bt_array, therefore this condition should hold
assert(i == bt_array.size());
sum_rank += invert ? (t_bs - x) : x;
if (space_for_bt) {
number_type bin = rrr_helper_type::decode_btnr(bv, pos, m_size-pos);
number_type nr = rrr_helper_type::bin_to_nr(bin);
rrr_helper_type::set_bt(m_btnr, btnr_pos, nr, space_for_bt);
}
btnr_pos += space_for_bt;
assert(m_rank.size()-1 == ((i+t_k-1)/t_k));
} else { // handle last empty full block
assert(m_rank.size()-1 == ((i+t_k-1)/t_k));
}
// for technical reasons we add a last element to m_rank
m_rank[ m_rank.size()-1 ] = sum_rank; // sum_rank contains the total number of set bits in bv
m_bt = bt_array;
}
示例12: all_used
bool all_used(void) {
for (unsigned i = 0; i < m_bitset.size() ; i++)
if (!m_bitset.get(i))
return false;
return true;
}