62 #ifdef NCBI_COMPILER_GCC
88 const char* tail_ptr =
reinterpret_cast<const char*
>(word_block_end);
89 const char* block_end = block +
size;
90 for ( ; tail_ptr != block_end; ++tail_ptr ) {
106 for (
size_t i = 0;
i < 8; ++
i,
b <<= 1 ) {
124 for (
size_t i = prev_i+1;
i < 8; ++
i,
b <<= 1 ) {
139 const char* ptr = beg;
141 for ( ; ptr != end &&
reinterpret_cast<size_t>(ptr)%
sizeof(TBig); ++ptr ) {
147 for ( ; ptr+
sizeof(TBig) <= end; ptr +=
sizeof(TBig) ) {
148 if ( *
reinterpret_cast<const TBig*
>(ptr) != 0 ) {
153 for ( ; ptr != end; ++ptr ) {
167 size_t size = bytes.size();
168 const char* ptr = &bytes[0];
183 size_t size = bytes.size();
190 size_t block_index = byte_count / kBlockSize;
191 size_t block_offset = byte_count % kBlockSize;
192 for ( ; block_index >
info.m_BlocksFilled; ) {
193 if ( !
info.m_Blocks ) {
194 size_t block_count =
size / kBlockSize;
195 info.m_Blocks.reset(
new size_t[block_count]);
197 size_t next_index =
info.m_BlocksFilled;
200 if ( next_index > 0 ) {
204 info.m_BlocksFilled = next_index+1;
206 size_t ret = block_index?
info.m_Blocks[block_index-1]: 0;
207 if ( block_offset ) {
208 if ( block_index !=
info.m_CacheBlockIndex ) {
209 if ( !
info.m_CacheBlockInfo ) {
210 info.m_CacheBlockInfo.reset(
new size_t[kBlockSize]);
213 size_t block_pos = block_index*kBlockSize;
214 size_t block_size =
min(kBlockSize,
size-block_pos);
215 const char* block = &bytes[block_pos];
216 for (
size_t i = 0;
i < block_size; ++
i ) {
220 info.m_CacheBlockIndex = block_index;
222 ret +=
info.m_CacheBlockInfo[block_offset-1];
239 : m_Blocks(new
TValue[(
size+kBlockSize-1)/kBlockSize]),
242 m_CacheBlockInfo(new
TValue[kBlockSize]),
244 m_CacheBlockIndex(size_t(0)-1)
260 #ifdef USE_DELTA_CACHE
263 size_t size = deltas.size();
267 _ASSERT(block_offset < block_size);
270 for (
size_t i = 0;
i < block_size; ++
i ) {
282 size_t size = deltas.size();
286 _ASSERT(block_offset < block_size);
289 for (
size_t i = 0;
i <= block_offset; ++
i ) {
294 for (
size_t i = block_offset+1;
i < block_size; ++
i ) {
313 size_t size = deltas.size();
317 #ifdef USE_DELTA_CACHE
318 if ( block_index < m_BlocksFilled && find_sum >
m_Blocks[block_index] ) {
323 if ( find_sum >
m_Blocks[block_index] ) {
330 _ASSERT(value_index < block_size);
336 return block_pos + value_index;
340 for (
size_t i = 0;
i < block_size; ++
i ) {
342 if ( sum >= find_sum ) {
345 for (
size_t j =
i+1; j < block_size; ++j ) {
367 _ASSERT(index < deltas.size());
380 size_t size = deltas.size();
384 block_index = lower_bound(&
m_Blocks[0],
443 return indexes.empty()? 0: indexes.back()+1;
466 return indexes.empty()?
kInvalidRow: indexes.front();
471 return deltas.empty()?
kInvalidRow: deltas.front();
491 size_t value_index)
const
497 return ++value_index >= indexes.size()?
503 return ++value_index >= deltas.size()?
509 size_t byte_index =
row / 8;
510 size_t bit_index =
row % 8;
513 return byte_index*8 + bit_index;
539 TIndexes::const_iterator iter =
540 lower_bound(indexes.begin(), indexes.end(),
row);
541 if ( iter != indexes.end() && *iter ==
row ) {
542 return iter - indexes.begin();
553 size_t byte_index =
row/8;
554 if ( byte_index >= bytes.size() ) {
557 Uint1 byte = bytes[byte_index];
558 size_t bit_index =
row%8;
559 if ( !((
byte<<bit_index)&0x80) ) {
589 TIndexes::const_iterator iter =
590 lower_bound(indexes.begin(), indexes.end(),
row);
591 return iter != indexes.end() && *iter ==
row;
599 return i < bits.size() && ((bits[
i]<<j)&0x80) != 0;
633 "CSeqTable_sparse_index::ChangeTo(): "
634 "requested sparse index type is invalid");
675 *it =
row - prev_row;
683 indexes.push_back(
row-prev_row);
700 bytes.reserve((
GetSize()+7)/8);
702 size_t last_byte_index = 0;
705 size_t row = it.GetRow();
706 size_t byte_index =
row / 8;
707 if ( byte_index != last_byte_index ) {
708 if ( bytes.capacity() < byte_index+1 ) {
709 bytes.reserve(
max(bytes.capacity(), byte_index+1)*2);
711 bytes.resize(last_byte_index);
712 bytes.push_back(last_byte);
713 last_byte_index = byte_index;
716 size_t bit_index =
row % 8;
717 last_byte |= 0x80 >> bit_index;
720 bytes.reserve(last_byte_index+1);
721 bytes.resize(last_byte_index);
722 bytes.push_back(last_byte);
738 size_t row = it.GetRow();
739 bv->set_bit(
static_cast<TBVSize
>(
row));
static size_t sx_CalcByteBitCount(Uint4 word)
static size_t sx_FindFirstNonZeroByte(const char *beg, const char *end)
static size_t sx_CalcBlockBitCount(const char *block, size_t size)
static size_t sx_FindNextNonZeroBit(Uint1 b, size_t prev_i)
static size_t sx_FindFirstNonZeroBit(Uint1 b)
DEFINE_STATIC_MUTEX(sx_PrepareMutex_sparse_index)
User-defined methods of the data storage class.
Bit manipulation primitives (internal)
Serialization / compression of bvector<>. Set theoretical operations on compressed BLOBs.
const bm::bvector & GetBitVector(void) const
void SetBitVector(const bm::bvector<> *bv)
TValue GetDeltaSum(const TDeltas &deltas, size_t index)
static const size_t kBlockSize
CSeqTable_sparse_index_Base::TIndexes_delta TDeltas
CIndexDeltaSumCache(size_t size)
static const size_t kInvalidRow
TValue x_GetDeltaSum2(const TDeltas &deltas, size_t block_index, size_t block_offset)
AutoArray< TValue > m_CacheBlockInfo
~CIndexDeltaSumCache(void)
static const size_t kBlockTooLow
AutoArray< TValue > m_Blocks
size_t x_FindDeltaSum2(const TDeltas &deltas, size_t block_index, TValue find_sum)
size_t FindDeltaSum(const TDeltas &deltas, TValue find_sum)
Seq-loc and seq-align mapper exceptions.
void ChangeToIndexes_delta(void)
TIndexes_delta & SetIndexes_delta(void)
void ChangeToBit_set_bvector(void)
size_t GetSize(void) const
TIndexes & SetIndexes(void)
static const size_t kSkipped
size_t GetIndexAt(size_t row) const
size_t x_FindDeltaSum(size_t sum) const
const_iterator begin(void) const
size_t x_GetFirstRowWithValue(void) const
void ChangeTo(E_Choice type)
void ChangeToIndexes(void)
CIndexDeltaSumCache & x_GetDeltaCache(void) const
size_t x_GetNextRowWithValue(size_t row, size_t value_index) const
TBit_set_bvector & SetBit_set_bvector(void)
TBit_set & SetBit_set(void)
size_t x_GetBitSetCache(size_t byte_count) const
bool HasValueAt(size_t row) const
~CSeqTable_sparse_index(void)
static const size_t kInvalidRow
size_t x_GetDeltaSum(size_t index) const
void ChangeToBit_set(void)
bool get_bit(size_type n) const noexcept
returns true if bit n is set and false is bit n is 0.
size_type size() const noexcept
Returns bvector's capacity (number of bits it can store)
size_type count_range(size_type left, size_type right, const rs_index_type &rs_idx) const noexcept
Returns count of 1 bits in the given range [left..right] Uses rank-select index to accelerate the sea...
bvector_size_type size_type
size_type get_next(size_type prev) const noexcept
Finds the number of the next bit ON.
size_type get_first() const noexcept
find first 1 bit in vector. Function may return 0 and this requires an extra check if bit 0 is actual...
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
element_type * release(void)
Release will release ownership of pointer to caller.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
TObjectType * GetNCPointerOrNull(void) const THROWS_NONE
Get pointer value.
void Reset(void)
Reset reference object.
uint8_t Uint1
1-byte (8-bit) unsigned integer
uint32_t Uint4
4-byte (32-bit) unsigned integer
uint64_t Uint8
8-byte (64-bit) unsigned integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
bm::id_t word_bitcount(bm::id_t w) noexcept
unsigned bit_count_min_unroll(const bm::word_t *block, const bm::word_t *block_end) noexcept
Bitcount for bit block without agressive unrolling.
bool IsBit_set_bvector(void) const
Check if variant Bit_set_bvector is selected.
vector< unsigned > TIndexes
E_Choice Which(void) const
Which variant is currently selected.
const TIndexes & GetIndexes(void) const
Get the variant data.
bool IsIndexes_delta(void) const
Check if variant Indexes_delta is selected.
vector< unsigned > TIndexes_delta
const TBit_set & GetBit_set(void) const
Get the variant data.
bool IsBit_set(void) const
Check if variant Bit_set is selected.
const TBit_set_bvector & GetBit_set_bvector(void) const
Get the variant data.
const TIndexes_delta & GetIndexes_delta(void) const
Get the variant data.
TSize GetSize(void) const
Get the Size member data.
bool IsIndexes(void) const
Check if variant Indexes is selected.
@ e_Bit_set
Bitset of rows with values, set bit means the row has value. Most-significant bit in each octet comes...
@ e_Bit_set_bvector
Bitset of rows with values, as serialized bvector<>, see include/util/bitset/bm.h.
@ e_Indexes_delta
Indexes of rows with values, delta-encoded.
@ e_Indexes
Indexes of rows with values.
static void byte(MDB_val *v)
double value_type
The numeric datatype used by the parser.
const struct ncbi::grid::netcache::search::fields::SIZE size
#define row(bind, expected)
static const size_t kBlockSize
Structure to aid in counting bits table contains count of bits in 0-255 diapason of numbers.