1#ifndef BMSPARSEVEC_UTIL_H__INCLUDED__
2#define BMSPARSEVEC_UTIL_H__INCLUDED__
24#ifndef BM__H__INCLUDED__
27# error missing include (bm.h or bm64.h)
58 if (
this != &addr_res)
60 addr_bv_ = addr_res.addr_bv_;
61 in_sync_ = addr_res.in_sync_;
64 rs_index_->copy_from(*addr_res.rs_index_);
225template<
class Value,
class BV>
348 typename BV::statistics bv_st;
350 addr_bv.calc_stat(&bv_st);
355 for (
size_t i = 0; i < this->
dense_vect_.size(); ++i)
363 size_t h_size = 2 + 1 + ((this->
dense_vect_.size()+1) * 8);
380: rs_index_(0), in_sync_(false)
413 rs_index_->~rs_index();
423: addr_bv_(addr_res.addr_bv_),
424 in_sync_(addr_res.in_sync_)
431 rs_index_->copy_from(*addr_res.rs_index_);
442 if (
this != &addr_res)
444 addr_bv_.move_from(addr_res.addr_bv_);
445 in_sync_ = addr_res.in_sync_;
449 rs_index_ = addr_res.rs_index_;
450 addr_res.rs_index_ = 0;
455 rs_index_ = 0; in_sync_ =
false;
468 *id_to = addr_bv_.count_to_test(id_from, *rs_index_);
472 bool found = addr_bv_.test(id_from);
479 *id_to = addr_bv_.count_range(0, id_from);
482 return (
bool) *id_to;
494 *id_to = addr_bv_.count_to_test(id_from, *rs_index_);
506 addr_bv_.set(id_from);
516 if (in_sync_ && force ==
false)
519 addr_bv_.build_rs_index(rs_index_);
528 addr_bv_.optimize(temp_block);
537 return addr_bv_.equal(addr_res.addr_bv_);
550 set_flags_bv_.init();
557: set_flags_bv_(addr_res.set_flags_bv_),
558 addr_sv_(addr_res.addr_sv_),
559 max_addr_(addr_res.max_addr_)
570 bool found = set_flags_bv_.test(id_from);
571 *id_to = found ? addr_sv_.at(id_from) : 0;
580 bool found = set_flags_bv_.test(id_from);
583 set_flags_bv_.set(id_from);
585 addr_sv_.set(id_from, max_addr_);
594 set_flags_bv_.optimize(temp_block);
595 addr_sv_.optimize(temp_block);
601template<
class Value,
class BV>
609template<
class Value,
class BV>
612 if (dense_vect_.empty())
616 if (key <= last_add_)
623 dense_vect_.push_back(val);
630template<
class Value,
class BV>
638template<
class Value,
class BV>
641 addr_res_.optimize(temp_block);
646template<
class Value,
class BV>
650 bool found = addr_res_.resolve(key, addr);
658template<
class Value,
class BV>
662 return dense_vect_.at(addr);
667template<
class Value,
class BV>
672 bool found = addr_res_.resolve(key, &idx);
675 throw_range_error(
"compressed collection item not found");
682template<
class Value,
class BV>
687 bool found = addr_res_.resolve(key, &idx);
690 throw_range_error(
"compressed collection item not found");
692 return dense_vect_.at(idx-1);
698template<
class Value,
class BV>
702 throw std::range_error(err_msg);
710template<
class Value,
class BV>
717 int cmp = bv.compare(bva);
721 for (
size_t i = 0; i < dense_vect_.size(); ++i)
#define BM_ASSERT_THROW(x, xerrcode)
Serialization / compression of bvector<>. Set theoretical operations on compressed BLOBs.
Bitvector Bit-vector container with runtime compression of bits.
bvector_size_type size_type
rs_index< allocator_type > rs_index_type
Bit-bector prefix sum address resolver using bit-vector prefix sum as a space compactor.
void unsync()
Unsync the prefix sum table.
void sync(bool force=false)
Re-calculate prefix sum table (same as calc_prefix_sum)
void calc_prefix_sum(bool force=false)
Re-calculate prefix sum table.
bool in_sync() const
returns true if prefix sum table is in sync with the vector
bvps_addr_resolver(const bvps_addr_resolver &addr_res)
void construct_rs_index()
bvector_type::rs_index_type rs_index_type
bvps_addr_resolver & operator=(const bvps_addr_resolver &addr_res)
bool resolve(size_type id_from, size_type *id_to) const BMNOEXCEPT
Resolve id to integer id (address)
void optimize(bm::word_t *temp_block=0)
optimize underlying bit-vector
bool get(size_type id_from, size_type *id_to) const BMNOEXCEPT
Resolve id to integer id (address) without sync check.
void set(size_type id_from)
Set id (bit) to address resolver.
void move_from(bvps_addr_resolver &addr_res) BMNOEXCEPT
Move content from the argument address resolver.
bool equal(const bvps_addr_resolver &addr_res) const BMNOEXCEPT
equality comparison
bvector_type & get_bvector()
Get writable reference to the underlying bit-vector.
const bvector_type & get_bvector() const
Get const reference to the underlying bit-vector.
Compressed (sparse collection of objects)
void calc_stat(statistics *st) const
compute statistics on memory consumption
serializer< BV >::buffer buffer_type
bool move_buffer(typename parent_type::key_type key, buffer_type &buffer)
move external buffer into collection
compressed_collection< typename serializer< BV >::buffer, BV > parent_type
Compressed (sparse collection of objects)
address_resolver_type & resolver()
Get address resolver.
bool push_back(key_type key, const value_type &val)
Add new value to compressed collection.
void optimize(bm::word_t *temp_block=0)
perform memory optimizations/compression
container_type & container()
return dense container for direct access (this should be treated as an internal function designed for...
bm::bvps_addr_resolver< bvector_type > address_resolver_type
void sync()
Checkpoint method to prepare collection for reading.
value_type & at(key_type key)
find and return associated value (with bounds/presense checking)
size_t size() const
size of collection
key_type last_add_
last added element
container_type dense_vect_
compressed space container
bool equal(const compressed_collection< Value, BV > &ccoll) const
perform equality comparison with another collection
const value_type & at(key_type key) const
find and return const associated value (with bounds/presense checking)
const value_type & get(address_type addr) const
Get access to associated value by resolved address.
void throw_range_error(const char *err_msg) const
address_resolver_type addr_res_
address resolver
bool resolve(key_type key, address_type *addr) const
Resolve key address (index) in the dense vector.
const address_resolver_type & resolver() const
Get address resolver.
std::vector< value_type > container_type
byte_buffer< allocator_type > buffer
sparse vector based address resolver (no space compactor, just bit-plane compressors provided by spar...
bvector_type::size_type size_type
const bvector_type & get_bvector() const
Get const reference to the underlying bit-vector of set values.
SV::bvector_type bvector_type
bool get(size_type id_from, size_type *id_to) const
Resolve id to integer id (address)
bool resolve(size_type id_from, size_type *id_to) const
Resolve id to integer id (address)
void set(size_type id_from)
Set id (bit) to address resolver.
void optimize(bm::word_t *temp_block=0)
optimize underlying sparse vectors
void aligned_free(void *ptr) BMNOEXCEPT
Aligned free.
void * aligned_new_malloc(size_t size)
Aligned malloc (unlike classic malloc it throws bad_alloc exception)
size_t max_serialize_mem
memory needed for serialization
size_t memory_used
total capacity