|
| trie_base () |
| 空のコンテナを構築する
|
|
| trie_base (allocator_type const &alloc) |
| アロケータを指定して空のコンテナを構築する [詳解]
|
|
template<typename InputIterator , typename std::enable_if_t< std::is_integral_v< typename std::iterator_traits< InputIterator >::value_type >, std::nullptr_t > = nullptr> |
| trie_base (InputIterator first, InputIterator last, allocator_type const &alloc=allocator_type()) |
| 直列化データからの構築 [詳解]
|
|
template<typename ForwardIterator , typename std::enable_if_t< std::negation_v< std::is_integral< typename std::iterator_traits< ForwardIterator >::value_type >>, std::nullptr_t > = nullptr> |
| trie_base (ForwardIterator first, ForwardIterator last, allocator_type const &alloc=allocator_type()) |
| 文字列リストからの構築 [詳解]
|
|
| trie_base (std::initializer_list< trie_node > il, allocator_type const &alloc=allocator_type()) |
| 初期化子リストからの構築 [詳解]
|
|
template<typename InputIterator , typename std::enable_if_t< std::is_integral_v< typename std::iterator_traits< InputIterator >::value_type >, std::nullptr_t > = nullptr> |
void | assign (InputIterator first, InputIterator last) |
| 直列化データからの割り当て [詳解]
|
|
template<typename ForwardIterator , typename std::enable_if_t< std::negation_v< std::is_integral< typename std::iterator_traits< ForwardIterator >::value_type >>, std::nullptr_t > = nullptr> |
void | assign (ForwardIterator first, ForwardIterator last) |
| 文字列リストからの割り当て [詳解]
|
|
reference | at (const_iterator pos) |
| 葉の値への参照を返す [詳解]
|
|
const_reference | at (const_iterator pos) const |
| 葉の値への参照を返す [詳解]
|
|
template<typename InputIterator > |
reference | at (InputIterator first, InputIterator last) |
| 葉の値への参照を返す [詳解]
|
|
template<typename InputIterator > |
const_reference | at (InputIterator first, InputIterator last) const |
| 葉の値への参照を返す [詳解]
|
|
template<typename Key > |
reference | at (Key const &key) |
| 葉の値への参照を返す [詳解]
|
|
template<typename Key > |
const const_reference | at (Key const &key) const |
| 葉の値への参照を返す [詳解]
|
|
template<typename Key > |
reference | operator[] (Key const &key) |
| 葉の値への参照を返す [詳解]
|
|
const_iterator | begin () const noexcept |
| 根を指すイテレータを返す [詳解]
|
|
const_iterator | cbegin () const noexcept |
| 根を指すイテレータを返す [詳解]
|
|
const_iterator | end () const noexcept |
| 根の終端を指すイテレータを返す [詳解]
|
|
const_iterator | cend () const noexcept |
| 根の終端を指すイテレータを返す [詳解]
|
|
bool | empty () const noexcept |
| キー文字列を格納していないことを調べる [詳解]
|
|
size_type | size () const noexcept |
| 格納しているキー文字列数を調べる [詳解]
|
|
template<typename InputIterator > |
const_iterator | insert (InputIterator first, InputIterator last, value_type value=0) |
| キー文字列を挿入する [詳解]
|
|
template<typename Key > |
const_iterator | insert (Key const &key, value_type value=0) |
| キー文字列を挿入する [詳解]
|
|
void | erase (const_iterator pos) |
| キー文字列を削除する [詳解]
|
|
template<typename InputIterator > |
void | erase (InputIterator first, InputIterator last) |
| キー文字列を削除する [詳解]
|
|
template<typename Key > |
void | erase (Key const &key) |
| キー文字列を削除する [詳解]
|
|
void | swap (trie_base &other) |
|
template<typename InputIterator > |
auto | lookup (InputIterator first, InputIterator last) const |
| 部分一致検索 [詳解]
|
|
template<typename InputIterator > |
const_iterator | search (InputIterator first, InputIterator last) const |
| 前方一致検索 [詳解]
|
|
template<typename Key > |
const_iterator | search (Key const &key) const |
| 前方一致検索 [詳解]
|
|
template<typename InputIterator > |
const_iterator | find (InputIterator first, InputIterator last) const |
| 完全一致検索 [詳解]
|
|
template<typename Key > |
const_iterator | find (Key const &key) const |
| 完全一致検索 [詳解]
|
|
template<typename InputIterator > |
bool | contains (InputIterator first, InputIterator last) const |
| キー文字列が格納されているか調べる [詳解]
|
|
template<typename Key > |
bool | contains (Key const &key) const |
| キー文字列が格納されているか調べる [詳解]
|
|
allocator_type | get_allocator () const |
| コンテナに関連付けられているアロケータを返す [詳解]
|
|
serialize_iterator | ibegin () const |
| 直列化用のイテレータを返す [詳解]
|
|
serialize_iterator | iend () const |
| 直列化用のイテレータを返す [詳解]
|
|
void | clear () noexcept |
| すべての要素を削除する [詳解]
|
|
allocator_type | get_allocator () const |
| コンテナに関連付けられているアロケータを返す [詳解]
|
|
void | assign (InputIterator first, InputIterator last) |
| 直列化データから割り当てる [詳解]
|
|
serialize_iterator | ibegin () const |
| 直列化用のイテレータを返す [詳解]
|
|
serialize_iterator | iend () const |
| 直列化用のイテレータを返す [詳解]
|
|
void | clear () noexcept |
| すべての要素を削除する [詳解]
|
|
void | swap (trie_heap &other) |
|
|
template<typename InputIterator > |
auto | lookup (InputIterator first, InputIterator last, std::uint32_t &i) const |
| 部分一致検索 [詳解]
|
|
template<typename InputIterator , typename std::enable_if_t< std::is_integral_v< typename std::iterator_traits< InputIterator >::value_type >, std::nullptr_t > = nullptr> |
void | assign (InputIterator first, InputIterator last) |
| 直列化データから割り当てる [詳解]
|
|
index_type | limit () const |
|
index_type | free (index_type idx, index_type before=0) |
|
void | free (index_type base, label_vector const &labels, index_type before=0) |
|
bool | is_tail (index_type idx) const |
|
bool | has_child (index_type parent) const |
|
bool | has_null (index_type parent) const |
|
bool | has_sibling (index_type idx) const |
|
bool | has_sibling (index_type parent, index_type idx) const |
|
index_type | at (index_type parent, std::uint16_t label) const |
|
index_type | add (index_type parent, std::uint16_t label) |
|
index_type | add (index_type parent, label_vector const &labels) |
|
| trie_heap (allocator_type const &alloc) |
|
| trie_heap (std::initializer_list< trie_node > il, allocator_type const &alloc=allocator_type()) |
| 初期化子リストから構築する [詳解]
|
|
index_type | limit () const |
|
void | reserve (std::size_t n, index_type before=0) |
|
void | allocate (index_type idx, index_type before=0) |
|
void | allocate (index_type base, label_vector const &labels, index_type before=0) |
|
index_type | relocate (index_type parent, index_type from, label_vector const &labels) |
|
index_type | free (index_type idx, index_type before=0) |
|
void | free (index_type base, label_vector const &labels, index_type before=0) |
|
index_type | locate (label_vector const &labels, index_type &before) const |
|
bool | is_free (index_type base, label_vector const &labels) const |
|
bool | is_free (index_type parent, index_type base, label_vector const &labels) const |
|
bool | is_tail (index_type idx) const |
|
bool | has_child (index_type parent) const |
|
bool | has_null (index_type parent) const |
|
bool | has_sibling (index_type idx) const |
|
bool | has_sibling (index_type parent, index_type idx) const |
|
index_type | at (index_type parent, std::uint16_t label) const |
|
index_type | add (index_type parent, std::uint16_t label) |
|
index_type | add (index_type parent, label_vector const &labels) |
|
template<typename Allocator = std::allocator<trie_node>>
class wordring::detail::trie_base< Allocator >
終端の空遷移を併合したTrie木の実装
- テンプレート引数
-
ダブルアレイの制約により、labelの型は8ビット固定。 挿入や削除による衝突によってすべてのイテレータが無効となる。
- 内部構造
下図には実際の木構造とダブル・アレイのデータ配置が含まれる。
BASEが0以下の場合、子が無い、つまり葉であることを示す。 値を反転させ負の値とすることで、葉に数値を格納できる(省略時は0)。
検索によって返されるイテレータは文字列の末尾を指す。 上図で、文字列「ac」の遷移途中のノードに文字列「a」の葉がある。 こういう場合は、nullによる遷移を追加して葉を表現する。
イテレータが文字列末尾を指しているか確認するには、イテレータの operator bool() あるいは operator !() を使う。 値にアクセスするにはコンテナの at() あるいは operator[]() を使う。
以下の表に位置を示す。
格納されている文字列 | find() が返す位置 | 値の格納位置 |
a | 98 | 258 |
ac | 101 | 101 |
b | 99 | 99 |
cab | 103 | 103 |
cd | 105 | 105 |
- 参照
- wordring::basic_trie
template<typename Allocator = std::allocator<trie_node>>
template<typename InputIterator , typename std::enable_if_t< std::is_integral_v< typename std::iterator_traits< InputIterator >::value_type >, std::nullptr_t > = nullptr>
void wordring::detail::trie_heap< Allocator >::assign |
( |
typename InputIterator |
, |
|
|
typename std::enable_if_t< std::is_integral_v< typename std::iterator_traits< InputIterator >::value_type >, std::nullptr_t > |
= nullptr |
|
) |
| |
|
inlineprotected |
直列化データから割り当てる
- 引数
-
[in] | first | 直列化データの先頭を指すイテレータ |
[in] | last | 直列化データの終端を指すイテレータ |
直列化データは[ibegin(), iend())から作成された整数値のリストを想定する。 整数の型(ビットの大きさ)は指定されず、適切に処理される。 [ibegin(), iend())から返される32ビット整数のコンテナでも、ファイルから読み込まれた8ビット整数のコンテナでも構わない。
- 参照
- ibegin() const
iend() const
- 例
※trie_heapは単独で構築できないため、サンプルはtrieを使用。
std::vector<std::string> v1{ "a", "ac", "b", "cab", "cd" };
auto t1 = trie<char>(v1.begin(), v1.end());
std::vector<std::int32_t> v2{ t1.ibegin(), t1.iend() };
trie<char> t2;
t2.assign(v2.begin(), v2.end());