-
Notifications
You must be signed in to change notification settings - Fork 1
/
bit_vector.hpp
61 lines (60 loc) · 1.81 KB
/
bit_vector.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef BIT_VECTOR_HPP_INCLUDED
#define BIT_VECTOR_HPP_INCLUDED
#include <cstdint>//uint64_t
#include <cstddef>//std::size_t
#include "bitsof.hpp"
//#define HAVE_GOON_BIT_VECTOR
#ifdef HAVE_GOON_BIT_VECTOR
std::size_t constexpr bits_per_block
=bitsof<uint64_t>()//must be multiple of sse_width.
;
#include <goon/bit_vector.hpp>
using goon::bit_vector;
#else
std::size_t constexpr bits_per_block
=bitsof<uint64_t>()//must be multiple of sse_width.
;
#include <vector>
//The following bit_vector implementation
//was copy&pasted from:
/*
From: Michael Marcin <[email protected]>
Newsgroups: gmane.comp.lib.boost.devel
Subject: Re: interest in structure of arrays container?
Date: Sun, 30 Oct 2016 18:45:41 -0500
*/
//and then minor modifications made.
//Then converted to use bitset instead of uint64_t
//as value_type for convenience.
#include <bitset>
struct bit_vector
: public std::vector
< std::bitset<bits_per_block>
>
{
using
super_t=
std::vector
< std::bitset<bits_per_block>
>;
using super_t::data;
bit_vector():num_bits_m(0){}
void resize( std::size_t num_bits, bool value = false )
{
std::size_t num_blocks =
( num_bits + (bits_per_block-1) )
/ bits_per_block
;//assert(num_blocks*bits_per_block >= num_bits);
super_t::value_type block;//all bits false.
if(value) block.set();//set all bits true.
super_t::resize( num_blocks, block );
num_bits_m = num_bits;
}
std::size_t size() const { return num_bits_m; }
std::size_t vec_size() const { return super_t::size(); }
auto* end(){ return data()+vec_size();}
private:
std::size_t num_bits_m;
};
#endif//HAVE_GOON_BIT_VECTOR
#endif//BIT_VECTOR_HPP_INCLUDED