1#ifndef BMVMIN__H__INCLUDED__
2#define BMVMIN__H__INCLUDED__
27#pragma warning( push )
28#pragma warning( disable : 4100)
35#define BM_MINISET_GAPLEN (bm::gap_len_table<true>::_len[0])
36#define BM_MINISET_ARRSIZE(x) ((x / 32) + ( (x % 32) && 1 ))
66 init_gapbuf(mset.m_buf);
68 init_bitbuf(mset.m_buf);
81 A::deallocate(m_buf, m_type ?
113 val ? (m_buf[nword] |= mask) : (m_buf[nword] &= ~mask);
124 unsigned new_block_len =
136 return sizeof(*this) +
148 unsigned typetmp = m_type;
149 m_type = mset.m_type;
150 mset.m_type = typetmp;
159 m_buf = A::allocate(arr_size, 0);
162 ::memcpy(m_buf, buf, arr_size *
sizeof(
bm::word_t));
166 ::memset(m_buf, 0, arr_size *
sizeof(
bm::word_t));
175 m_buf = A::allocate(arr_size, 0);
178 ::memcpy(m_buf, buf, arr_size *
sizeof(
bm::word_t));
196 A::deallocate(m_buf, arr_size);
219 ::memset(m_buf, 0,
sizeof(m_buf));
224 ::memcpy(m_buf, mset.m_buf,
sizeof(m_buf));
239 val ? (m_buf[nword] |= mask) : (m_buf[nword] &= ~mask);
244 return sizeof(*this);
252 m_buf[i] = mset.m_buf[i];
286 m_buf = A::allocate(arr_size, 0);
287 ::memset(m_buf, 0, arr_size *
sizeof(
unsigned));
290 : m_size(
bvect.m_size)
293 m_buf = A::allocate(arr_size, 0);
294 ::memcpy(m_buf,
bvect.m_buf, arr_size *
sizeof(
unsigned));
299 A::deallocate(m_buf, (m_size / 32) + 1);
305 unsigned char mask = (
unsigned char)((
char)0x1 << (pos & 7));
306 unsigned char* offs = (
unsigned char*)m_buf + (pos >> 3);
307 return (*offs) & mask;
313 unsigned char mask = (
unsigned char)(0x1 << (pos & 7));
314 unsigned char* offs = (
unsigned char*)m_buf + (pos >> 3);
321 unsigned char mask = (
unsigned char)(0x1 << (pos & 7));
322 unsigned char* offs = (
unsigned char*)m_buf + (pos >> 3);
323 *offs &= (
unsigned char)~mask;
330 const unsigned* end = m_buf + (m_size / 32)+1;
331 for (
unsigned* start = m_buf; start < end; ++start)
333 unsigned value = *start;
334 for (count += (value!=0); value &= value - 1; ++count);
344 if (!cnt1 && !cnt2)
return 0;
345 size_type cnt_min = cnt1 < cnt2 ? cnt1 : cnt2;
346 if (!cnt_min)
return cnt1 ? 1 : -1;
355 return idx1 < idx2 ? 1 : -1;
362 if (!idx1)
return -1;
364 return idx1 < idx2 ? 1 : -1;
374 const unsigned char* ptr = (
unsigned char*) m_buf;
375 for (
unsigned i = 0; i < ((m_size/8)+1); ++i)
377 unsigned char w = ptr[i];
380 while ((w & 1u) == 0)
382 w = (
unsigned char)(w >> 1u);
387 pos =
size_type(pos +
sizeof(
unsigned char) * 8u);
397 for (i = idx+1; i < m_size; ++i)
399 unsigned char* offs = (
unsigned char*)m_buf + (i >> 3);
402 unsigned char mask = (
unsigned char)((
char)0x1 << (i & 7));
418 const unsigned* end = m_buf + (m_size / 32)+1;
419 const unsigned* src =
bvect.get_buf();
420 for (
unsigned* start = m_buf; start < end; ++start)
428 const unsigned* end = m_buf + (m_size / 32)+1;
429 const unsigned* src =
bvect.get_buf();
430 for (
unsigned* start = m_buf; start < end; ++start)
438 const unsigned* end = m_buf + (m_size / 32)+1;
439 const unsigned* src =
bvect.get_buf();
440 for (
unsigned* start = m_buf; start < end; ++start)
448 const unsigned* end = m_buf + (m_size / 32)+1;
449 const unsigned* src =
bvect.get_buf();
450 for (
unsigned* start = m_buf; start < end; ++start)
456 const unsigned*
get_buf()
const {
return m_buf; }
459 return unsigned(
sizeof(
bvector_mini) + (m_size / 32) + 1);
479#pragma warning( pop )
#define BM_MINISET_ARRSIZE(x)
#define BM_MINISET_GAPLEN
Bitvector class with very limited functionality.
const unsigned * get_buf() const
int is_bit_true(size_type pos) const
Checks if bit pos 1 or 0. Returns 0 if 0 and non zero otherwise.
unsigned mem_used() const
size_type get_first() const
Returns index of the first ON bit.
size_type get_next(size_type idx) const
Returns index of next bit, which is ON.
void combine_sub(const bvector_mini &bvect)
void swap(bvector_mini &bvm)
size_type bit_count() const
Counts number of bits ON.
bvector_mini(size_type size)
void combine_and(const bvector_mini &bvect)
void combine_or(const bvector_mini &bvect)
void combine_xor(const bvector_mini &bvect)
int compare(const bvector_mini &bvect)
Comparison.
bvector_mini(const bvector_mini &bvect)
void clear_bit(size_type pos)
Sets bit number pos to 0.
void set_bit(size_type pos)
Sets bit number pos to 1.
Bitvector Bit-vector container with runtime compression of bits.
size_type get_next(size_type prev) const BMNOEXCEPT
Finds the number of the next bit ON.
size_type get_first() const BMNOEXCEPT
find first 1 bit in vector. Function may return 0 and this requires an extra check if bit 0 is actual...
Mini bit-vector for auxiliary purposes.
unsigned mem_used() const
void set(bm::id_t n, bool val=true)
unsigned test(bm::id_t n) const
Checks if bit pos 1 or 0. Returns 0 if 0 and non zero otherwise.
bvmini(const bvmini &mset)
Template class implements memory saving set functionality.
void set(bm::id_t n, bool val=true)
unsigned mem_used() const
miniset(const miniset &mset)
unsigned test(bm::id_t n) const
Checks if bit pos 1 or 0. Returns 0 if 0 and non zero otherwise.
unsigned gap_set_value(unsigned val, T *BMRESTRICT buf, unsigned pos, unsigned *BMRESTRICT is_set) BMNOEXCEPT
Sets or clears bit in the GAP buffer.
void gap_convert_to_bitset(unsigned *BMRESTRICT dest, const T *BMRESTRICT buf, unsigned len=0) BMNOEXCEPT
GAP block to bitblock conversion.
unsigned gap_test(const T *BMRESTRICT buf, unsigned pos) BMNOEXCEPT
Tests if bit = pos is true.
void gap_set_all(T *buf, unsigned set_max, unsigned value) BMNOEXCEPT
Sets all bits to 0 or 1 (GAP)
const unsigned set_word_shift
unsigned long long int id64_t
unsigned short gap_word_t
const unsigned gap_max_bits
const unsigned set_word_mask