16 #ifndef INCLUDE_NN_NLIB_SUCCINCT_SBV_H_ 17 #define INCLUDE_NN_NLIB_SUCCINCT_SBV_H_ 23 #include "nn/nlib/Swap.h" 29 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS) 30 #undef NLIB_VIS_PUBLIC 31 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT 38 static const unsigned int BLK_SIZE = 32;
46 NLIB_DEFMOVE_PIMPL(
Set);
54 uint32_t rank1 = this->Rank1(idx);
55 return idx + 1 - rank1;
68 mutable SetPrivate* prv_;
77 #ifdef __cpp_rvalue_references 80 set_ = std::move(rhs.set_);
90 rhs.set_.assign(rhs.set_,
move_tag());
105 uint32_t GetBitVectorSize() const
NLIB_NOEXCEPT {
return set_.GetBitVectorSize(); }
124 lowest_idx_(0xFFFFFFFF),
131 #ifdef __cpp_rvalue_references 142 uint32_t rank1 = this->Rank1(idx);
143 if (rank) *rank = rank1;
144 if (rank1 == 0)
return false;
145 int64_t select1 = this->Select1Ex(rank1 - 1);
146 NLIB_ASSERT(select1 >= 0);
148 return idx ==
static_cast<uint64_t
>(select1);
153 uint32_t rank1 = this->Rank1(idx);
154 return static_cast<uint32_t
>(idx + 1 - rank1);
165 uint32_t GetBits(uint64_t pos,
size_t num) const
NLIB_NOEXCEPT {
166 NLIB_ASSERT(num <= 32);
167 uint64_t idx64 = pos / detail::BLK_SIZE;
168 NLIB_ASSERT(idx64 <= SIZE_MAX);
169 size_t idx =
static_cast<size_t>(idx64);
170 size_t ofs =
static_cast<size_t>(pos % detail::BLK_SIZE);
171 if (ofs + num > 32) {
172 uint64_t b = b_[idx + 1];
175 return static_cast<uint32_t
>((b >> ofs) & ((1 << num) - 1));
177 return (b_[idx] >> ofs) & ((1 << num) - 1);
182 uint64_t bitvector_size_;
183 uint64_t lowest_idx_;
184 uint64_t highest_idx_;
185 uint32_t num_on_bits_;
194 static const size_t UNIT_SIZE = 64;
208 #ifdef __cpp_rvalue_references 213 work_[workidx_++] = x;
214 if (workidx_ == UNIT_SIZE)
return this->Build();
235 uint32_t header_size_;
236 uint32_t header_capacity_;
238 uint32_t data_capacity_;
240 uint32_t work_[UNIT_SIZE];
253 #ifdef __cpp_rvalue_references 254 #ifdef NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS 256 Map& operator=(
Map&& rhs) =
default;
260 set_ = std::move(rhs.set_);
261 value_ = std::move(rhs.value_);
274 if (value_.Size() != 0)
return false;
275 return set_.
Init(bv_size);
278 if (!set_.
TurnOn(idx))
return false;
279 value_.PushBack(data);
285 return std::make_pair(
true, value_[set_.
Rank1(idx) - 1]);
287 return std::make_pair(
false, 0);
291 return std::make_pair(
true, value_[set_.
Rank1(idx) - 1]);
293 return std::make_pair(
false, 0);
296 size_t value_size = value_.MemSize();
297 size_t set_size = set_.
MemSize();
298 return value_size + set_size;
307 if (!value_.Export(w))
return false;
308 if (!set_.
Export(w))
return false;
312 if (!value_.Import(r) || !set_.
Import(r)) {
328 NLIB_DEFINE_STD_SWAP(::nlib_ns::succinct::Set)
329 NLIB_DEFINE_STD_SWAP(::nlib_ns::succinct::Sbv)
330 NLIB_DEFINE_STD_SWAP(::nlib_ns::succinct::SparseSet)
331 NLIB_DEFINE_STD_SWAP(::nlib_ns::succinct::CompressedArray)
332 NLIB_DEFINE_STD_SWAP(::nlib_ns::succinct::Map)
334 #if defined(_MSC_VER) && defined(nx_succinct_EXPORTS) 335 #undef NLIB_VIS_PUBLIC 336 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT 339 #endif // INCLUDE_NN_NLIB_SUCCINCT_SBV_H_ uint32_t Rank1(uint32_t idx) const noexcept
Performs a Rank operation.
~Sbv() noexcept
Destructor.
bool TurnOff(uint32_t idx) noexcept
Removes a 32-bit unsigned integer from the set.
constexpr Sbv() noexcept
Instantiates the object with default parameters (default constructor).
Substitute definitions for the C++11 standard header type_traits. These substitute definitions are us...
uint32_t IdxType
typedef for the integer index type.
size_t MemSize() const noexcept
Returns the amount of memory explicitly allocated by the class.
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
bool TurnOn(uint32_t idx) noexcept
Adds a 32-bit unsigned integer to the set.
Succinct data structure to hold a set of 32-bit unsigned integers for a Rank/Select operation...
Defines the class for reading binary files from streams.
int32_t Select0(uint32_t nth) const noexcept
Returns the position of the nth 0 bit. nth starts from 0.
FindType Find(IdxType idx) noexcept
Specifies a key and gets the value in the associative array.
Set & assign(Set &rhs, move_tag)
Corresponds to a move assignment operator.
bool Init(IdxType bv_size) noexcept
Initializes an object.
~CompressedArray() noexcept
Destructor.
uint32_t Rank0(uint64_t idx) const noexcept
Performs a Rank operation.
constexpr Set() noexcept
Instantiates the object with default parameters (default constructor). Requires initialization with I...
bool Build() noexcept
Constructs the Rank dictionary.
Map & assign(Map &rhs, move_tag) noexcept
Corresponds to a move assignment operator.
Sbv & assign(Sbv &rhs, move_tag) noexcept
Corresponds to a move assignment operator.
Sbv & operator=(Sbv &&rhs) noexcept
Move assignment operator.
~SparseSet() noexcept
Destructor.
const SetType & GetKeys() const noexcept
Gets the key set.
bool TurnOn(uint32_t idx) noexcept
Adds a 32-bit unsigned integer to the set.
bool Export(BinaryWriter *w) const noexcept
Writes the object to the file.
constexpr CompressedArray() noexcept
Instantiates the object with default parameters (default constructor).
Map(Map &rhs, move_tag) noexcept
Corresponds to a move constructor.
const ArrayType & GetValues() const noexcept
Gets the set of values.
void Reset() noexcept
Resets this object to the state immediately after the default constructor was executed.
Succinct data structure to hold a set of 32-bit unsigned integers for a Rank/Select operation...
Sbv(Sbv &rhs, move_tag) noexcept
Corresponds to a move constructor.
An empty structure indicating that an argument to a function needs to be moved.
const uint32_t * GetBitVector() const noexcept
Returns the pointer to the bit vector.
uint32_t Rank1(uint32_t idx) const noexcept
Performs a Rank operation.
constexpr SparseSet() noexcept
Instantiates the object with default parameters (default constructor). Requires initialization with I...
~Set() noexcept
Destructor.
A compressed array of integers that allows appending additional data.
bool TurnOn(IdxType idx, uint32_t data) noexcept
Adds a key and value.
Succinct data structure to hold a nowhere dense set of 64-bit unsigned integers.
SetType::IdxType IdxType
Integer index.
Defines the class for writing binary files to streams.
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
void Reset() noexcept
Resets this object to the state immediately after the default constructor was executed.
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
bool Has(uint64_t idx) const noexcept
Tests to determine whether a particular value is contained in the set.
A file that contains the configuration information for each development environment.
Defines the class for handing bit streams operated on by Rank and Select.
uint64_t IdxType
typedef for the integer index type.
Sbv(Sbv &&rhs) noexcept
Instantiates the object (move constructor).
bool Build() noexcept
Builds an associative array.
bool Import(BinaryReader *r) noexcept
Reads the written object.
constexpr Map() noexcept
Instantiates the object with default parameters (default constructor). Requires initialization with I...
The class for writing binary to streams (to OutputStream).
size_t MemSize() const noexcept
Returns the amount of memory explicitly allocated by the class.
A compact integer to integer read-only associative array.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
const FindType Find(IdxType idx) const noexcept
Specifies a key and gets the value in the associative array.
bool Init(uint32_t bv_size) noexcept
Initializes an object.
bool Has(uint32_t idx) const noexcept
Tests to determine whether a particular value is contained in the set.
The class for reading binary from streams (from InputStream).
uint32_t IdxType
typedef for the integer index type.
uint32_t Rank0(uint32_t idx) const noexcept
Performs a Rank operation.
size_t Size() const noexcept
Gets the array length.
bool Export(BinaryWriter *w) const noexcept
Writes the object to the file.
bool PushBack(uint32_t x) noexcept
Adds data. Compresses data after it becomes 64 elements long.
std::pair< bool, uint32_t > FindType
Pair of boolean value and integer. If the value is not found, the boolean value is false...
~Map() noexcept
Destructor.
bool Import(BinaryReader *r) noexcept
Reads the written object.