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
Rank操作を行います。
bool TurnOff(uint32_t idx) noexcept
集合から32bit符号なし整数を取り除きます。
constexpr Sbv() noexcept
デフォルトコンストラクタです。
C++11の標準ヘッダとなるtype_traitsの代用定義です。 コンパイラや標準ライブラリによってサポートされてい...
uint32_t IdxType
インデックスとなる整数型のtypedefです。
size_t MemSize() const noexcept
このクラスが明示的に確保するメモリ量を返します。
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
bool TurnOn(uint32_t idx) noexcept
集合に32bit符号なし整数を追加します。
Rank/Select操作つきの32bit符号なし整数の集合を保持する簡潔データ構造です。
ストリームからバイナリファイルを読み込むクラスを定義しています。
int32_t Select0(uint32_t nth) const noexcept
nth 番目の0ビットの場所を返します。nth は0から開始します。
FindType Find(IdxType idx) noexcept
キーを指定して連想配列から値を取得します。
Set & assign(Set &rhs, move_tag)
ムーブ代入演算子に相当します。
bool Init(IdxType bv_size) noexcept
オブジェクトを初期化します。
~CompressedArray() noexcept
デストラクタです。
uint32_t Rank0(uint64_t idx) const noexcept
Rank操作を行います。
constexpr Set() noexcept
デフォルトコンストラクタです。実行後Init()による初期化を必要とします。
bool Build() noexcept
Rank辞書を構築します。
Map & assign(Map &rhs, move_tag) noexcept
ムーブ代入演算子に相当します。
Sbv & assign(Sbv &rhs, move_tag) noexcept
ムーブ代入演算子に相当します。
Sbv & operator=(Sbv &&rhs) noexcept
ムーブ代入演算子です。
~SparseSet() noexcept
デストラクタです。
const SetType & GetKeys() const noexcept
キーの集合を取得します。
bool TurnOn(uint32_t idx) noexcept
集合に32bit符号なし整数を追加します。
bool Export(BinaryWriter *w) const noexcept
オブジェクトを(ファイルに)書き出します。
constexpr CompressedArray() noexcept
デフォルトコンストラクタです。
Map(Map &rhs, move_tag) noexcept
ムーブコンストラクタに相当します。
const ArrayType & GetValues() const noexcept
値の集合を取得します。
void Reset() noexcept
このオブジェクトをデフォルトコンストラクタの実行直後の状態にリセットします。
Rank/Select操作つきの32bit符号なし整数の集合を保持する簡潔データ構造です。
Sbv(Sbv &rhs, move_tag) noexcept
ムーブコンストラクタに相当します。
空の構造体で、関数の引数をムーブすべきことを示すために利用されます。
const uint32_t * GetBitVector() const noexcept
ビットベクトルへのポインタを返します。
uint32_t Rank1(uint32_t idx) const noexcept
Rank操作を行います。
constexpr SparseSet() noexcept
デフォルトコンストラクタです。実行後Init()による初期化を必要とします。
bool TurnOn(IdxType idx, uint32_t data) noexcept
キーと値を追加します。
疎な64bit符号なし整数の集合を保持する簡潔データ構造です。
SetType::IdxType IdxType
整数インデックスです。
ストリームにバイナリファイルを書き込むクラスを定義しています。
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
void Reset() noexcept
このオブジェクトをデフォルトコンストラクタの実行直後の状態にリセットします。
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
bool Has(uint64_t idx) const noexcept
値が集合に含まれているかどうかをテストします。
Rank/Select操作つきのビット列を扱うクラスが定義されています。
uint64_t IdxType
インデックスとなる整数型のtypedefです。
Sbv(Sbv &&rhs) noexcept
ムーブコンストラクタです。
bool Build() noexcept
連想配列を構築します。
bool Import(BinaryReader *r) noexcept
書き出されたオブジェクトを読み出します。
constexpr Map() noexcept
デフォルトコンストラクタです。実行後Init()による初期化を必要とします。
ストリーム(OutputStream)にバイナリを書き込むクラスです。
size_t MemSize() const noexcept
このクラスが明示的に確保するメモリ量を返します。
整数から整数へのコンパクトなリードオンリーの連想配列です。
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
const FindType Find(IdxType idx) const noexcept
キーを指定して連想配列から値を取得します。
bool Init(uint32_t bv_size) noexcept
オブジェクトを初期化します。
bool Has(uint32_t idx) const noexcept
値が集合に含まれているかどうかをテストします。
ストリーム(InputStream)からバイナリを読み込むクラスです。
uint32_t IdxType
インデックスとなる整数型のtypedefです。
uint32_t Rank0(uint32_t idx) const noexcept
Rank操作を行います。
size_t Size() const noexcept
配列の長さを取得します。
bool Export(BinaryWriter *w) const noexcept
オブジェクトを(ファイルに)書き出します。
bool PushBack(uint32_t x) noexcept
データを追加します。64個単位の長さになるとデータを圧縮します。
std::pair< bool, uint32_t > FindType
ブール値と整数のペアです。値が見つからなかった場合はブール値がfalseです。
bool Import(BinaryReader *r) noexcept
書き出されたオブジェクトを読み出します。