-
首页
-
C4D R23.110 C++ SDK
BurstTrieMap< K, V, GROUP_BITS, BUCKET_SIZE, SORT, POOL > Class Template Reference
Data Structures
#include <bursttriemap.h>
详细描述
template<typename K, typename V, Int GROUP_BITS = 4, Int BUCKET_SIZE = 16, BURSTTRIE_SORT SORT = BURSTTRIE_SORT::LINEAR_SEARCH, template< typename, typename > class POOL = PointerBurstTriePool>
class maxon::BurstTrieMap< K, V, GROUP_BITS, BUCKET_SIZE, SORT, POOL >
A
BurstTrieMap
maps unsigned integral keys to values using three levels:
-
At first, keys are divided based on their number of leading zero bits.
-
Then, a tree is traversed using groups of GROUP_BITS bits as indices into child nodes.
-
Finally, a leaf node contains a small array-map-like map of at most BUCKET_SIZE entries. When a full leaf node (BUCKET_SIZE entries) needs to get a further entry, it is split into an inner node with children. Likewise, if after erasure an inner node has less than two-thirds of BUCKET_SIZE key-value-pairs in its descendants, those pairs will be combined to a single leaf node which then replaces the inner node and its descendants.
Performance characteristics: Like an
ArrayMap
,
BurstTrieMap
allows an iteration in the order of the keys. But it performs much better than an
ArrayMap
when the number of entries gets large (say, more than 100): The number of inner nodes to visit is bounded by the maximum bit length of a key, so operations like insertion, erasure or searching are bounded by a constant time cost, too: O(1).
见
HashMap
for more examples on how to use maps in general.
-
Template Parameters
-
K
|
Type of keys. This must be an unsigned integral type.
|
V
|
Type of values.
|
GROUP_BITS
|
Number of bits which shall be grouped to form an index into the children array of an inner node. This shouldn't exceed 4.
|
BUCKET_SIZE
|
Maximum size of a bucket of a leaf node. Reasonable values are between 4 and 40.
|
SORT
|
Mode for sorting of the buckets.
|
POOL
|
Memory pool for the nodes.
|
-
另请参阅
-
$ref maps
Public Types
|
using
|
IsBurstTrieMap
= std::true_type
|
using
|
Bucket
=
BurstTrieBucket
< K, V, BUCKET_SIZE >
|
using
|
节点
=
BurstTrieNode
< GROUP_BITS, typename POOL<
Int
,
Int
>::
索引
>
|
using
|
Pool
= POOL<
节点
,
Bucket
>
|
using
|
索引
= typename Pool::Index
|
using
|
Super
=
MapBase
<
BurstTrieMap
< K, V, GROUP_BITS, BUCKET_SIZE, SORT, POOL >, K, V,
Pool
,
DefaultCompare
>
|
using
|
Iterator
=
IteratorTemplate
< false,
EntryIteratorBase
>
|
using
|
ConstIterator
=
IteratorTemplate
< true,
EntryIteratorBase
>
|
using
|
KeyIterator
=
IteratorTemplate
< false,
KeyIteratorBase
>
|
using
|
ConstKeyIterator
=
IteratorTemplate
< true,
KeyIteratorBase
>
|
using
|
ValueIterator
=
IteratorTemplate
< false,
ValueIteratorBase
>
|
using
|
ConstValueIterator
=
IteratorTemplate
< true,
ValueIteratorBase
>
|
using
|
MapType
=
BurstTrieMap
< K, V, 4, 16,
BURSTTRIE_SORT::LINEAR_SEARCH
,
PointerBurstTriePool
>
|
using
|
Super
=
BaseCollection
<
BurstTrieMap
< K, V, 4, 16,
BURSTTRIE_SORT::LINEAR_SEARCH
,
PointerBurstTriePool
>,
PointerBurstTriePool
<
BurstTrieNode
< 4,
PointerBurstTriePool
<
Int
,
Int
>::
索引
>,
BurstTrieBucket
< K, V, 16 > > >
|
using
|
KeyType
= K
|
using
|
ValueType
= V
|
using
|
IsCollection
= std::true_type
|
using
|
索引
= void *
|
公共成员函数
|
|
BurstTrieMap
()
|
|
BurstTrieMap
(
Pool
&&a)
|
|
BurstTrieMap
(const
Pool
&a)
|
|
BurstTrieMap
(
BurstTrieMap
&&
src
)
|
|
MAXON_OPERATOR_MOVE_ASSIGNMENT
(
BurstTrieMap
)
|
|
~BurstTrieMap
()
|
template<typename MAP >
|
SFINAEHelper
<
Result
< void >, typename std::remove_reference< MAP >::type::IsBurstTrieMap >::type
|
CopyFromImpl
(MAP &&
src
,
COLLECTION_RESIZE_FLAGS
resizeFlags,
OverloadRank1
)
|
void
|
重置
()
|
void
|
Flush
()
|
ResultMem
|
SetCapacityHint
(
Int
,
COLLECTION_RESIZE_FLAGS
resizeFlags=
COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY
)
|
Int
|
GetCount
() const
|
Int
|
GetOperationCountForSearch
() const
|
Int
|
GetDepth
() const
|
Int
|
GetMemorySize
() const
|
Iterator
|
Begin
()
|
Iterator
|
End
()
|
ConstIterator
|
Begin
() const
|
ConstIterator
|
End
() const
|
KeyIterator
|
GetKeys
()
|
ConstKeyIterator
|
GetKeys
() const
|
ValueIterator
|
GetValues
()
|
ConstValueIterator
|
GetValues
() const
|
ResultMemT
<
Iterator
>
|
InsertEntry
(K key,
Bool
&created=
BoolLValue
())
|
ResultMemT
<
Iterator
>
|
Insert
(K key, const V &value,
Bool
&created=
BoolLValue
())
|
ResultMemT
<
Iterator
>
|
Insert
(K key, V &&value,
Bool
&created=
BoolLValue
())
|
ResultRef
< V >
|
InsertKey
(K key,
Bool
&created=
BoolLValue
())
|
const V *
|
FindValue
(K key) const
|
V *
|
FindValue
(K key)
|
Iterator
|
Find
(K key)
|
ConstIterator
|
Find
(K key) const
|
Iterator
|
FindFloor
(K key)
|
ConstIterator
|
FindFloor
(K key) const
|
ResultOk
<
Bool
>
|
Erase
(K key)
|
template<template< Bool > class SUPER>
|
IteratorTemplate
< false, SUPER >
|
Erase
(const
IteratorTemplate
< false, SUPER > &position,
Int
eraseCnt=1)
|
MAXON_ATTRIBUTE_FORCE_INLINE
|
MapBase
(ARGS &&... args)
|
MapImpl
<
BurstTrieMap
< K, V, 4, 16,
BURSTTRIE_SORT::LINEAR_SEARCH
,
PointerBurstTriePool
> & >
|
ToMap
()
|
MapImpl
< const
BurstTrieMap
< K, V, 4, 16,
BURSTTRIE_SORT::LINEAR_SEARCH
,
PointerBurstTriePool
> & >
|
ToMap
() const
|
MAXON_ATTRIBUTE_FORCE_INLINE
|
operator MapImpl< BurstTrieMap< K, V, 4, 16, BURSTTRIE_SORT::LINEAR_SEARCH, PointerBurstTriePool > & >
()
|
MAXON_ATTRIBUTE_FORCE_INLINE
|
operator MapImpl< const BurstTrieMap< K, V, 4, 16, BURSTTRIE_SORT::LINEAR_SEARCH, PointerBurstTriePool > & >
() const
|
MAXON_ATTRIBUTE_FORCE_INLINE
|
MapBase0
(ARGS &&... args)
|
MAXON_ATTRIBUTE_FORCE_INLINE
Bool
|
Contains
(typename
ByValueParam
< K >::type key) const
|
MAXON_ATTRIBUTE_FORCE_INLINE
SFINAEHelper
<
Bool
, typename PAIR::KeyType >::type
|
Contains
(const PAIR &pair) const
|
ResultRef
< V >
|
Append
(const K &key)
|
SFINAEHelper
<
ResultRef
< V >, typename PAIR::KeyType >::type
|
Append
(const PAIR &pair)
|
Result
< void >
|
添加
(COLLECTION2 &&other,
COLLECTION_RESIZE_FLAGS
resizeFlags=
COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY
)
|
Result
< void >
|
AppendAll
(COLLECTION2 &&other,
COLLECTION_RESIZE_FLAGS
resizeFlags=
COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY
)
|
Result
< void >
|
AppendAllInverse
(COLLECTION2 &&other)
|
Bool
|
ContainsAllImpl
(COLLECTION2 &&other,
OverloadRank0
) const
|
Result
< void >
|
SubtractImpl
(COLLECTION2 &&other,
OverloadRank0
)
|
Bool
|
IsEqualImpl
(const COLLECTION2 &other, COMPARE &&cmp,
OverloadRank0
) const
|
HashInt
|
GetHashCode
() const
|
MAXON_ATTRIBUTE_FORCE_INLINE
|
BaseCollection
(ARGS &&... args)
|
MAXON_ATTRIBUTE_FORCE_INLINE
std::enable_if< maxon::IsCollection< COLLECTION2 >::value,
Bool
>::type
|
operator==
(const COLLECTION2 &other) const
|
MAXON_ATTRIBUTE_FORCE_INLINE
std::enable_if< maxon::IsCollection< COLLECTION2 >::value,
Bool
>::type
|
operator!=
(const COLLECTION2 &other) const
|
MAXON_ATTRIBUTE_FORCE_INLINE
std::enable_if< maxon::IsCollection< COLLECTION2 >::value &&!
STD_IS_REPLACEMENT
(same, typename std::decay< COMPARE >::type,
EQUALITY
),
Bool
>::type
|
IsEqual
(const COLLECTION2 &other, COMPARE &&cmp=COMPARE()) const
|
MAXON_ATTRIBUTE_FORCE_INLINE
Result
< void >
|
AppendAll
(COLLECTION2 &&other,
COLLECTION_RESIZE_FLAGS
resizeFlags=
COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY
)
|
MAXON_ATTRIBUTE_FORCE_INLINE
Result
< void >
|
CopyFrom
(COLLECTION2 &&other,
COLLECTION_RESIZE_FLAGS
resizeFlags=
COLLECTION_RESIZE_FLAGS::FIT_TO_SIZE
)
|
MAXON_ATTRIBUTE_FORCE_INLINE
Result
< void >
|
Subtract
(COLLECTION2 &&other)
|
MAXON_ATTRIBUTE_FORCE_INLINE
Result
< void >
|
Intersect
(const COLLECTION2 &other)
|
Bool
|
Intersects
(const COLLECTION2 &other) const
|
MAXON_ATTRIBUTE_FORCE_INLINE
Result
< void >
|
CopyFromImpl
(COLLECTION2 &&other,
COLLECTION_RESIZE_FLAGS
resizeFlags,
OverloadRank0
)
|
Result
< void >
|
AppendAllImpl
(COLLECTION2 &&other,
COLLECTION_RESIZE_FLAGS
resizeFlags,
Bool
overwrite,
OverloadRank0
)
|
Result
< void >
|
IntersectImpl
(COLLECTION2 &&other,
OverloadRank0
)
|
MAXON_ATTRIBUTE_FORCE_INLINE
Bool
|
IsEmpty
() const
|
MAXON_ATTRIBUTE_FORCE_INLINE
Bool
|
IsPopulated
() const
|
String
|
ToString
(const
FormatStatement
*formatStatement=nullptr) const
|
MAXON_ATTRIBUTE_FORCE_INLINE
Bool
|
ContainsAll
(COLLECTION2 &&other) const
|
Bool
|
ContainsAllImpl
(COLLECTION2 &&other,
OverloadRank0
) const
|
Member Typedef Documentation
◆
IsBurstTrieMap
◆
Bucket
◆
节点
◆
Pool
◆
索引
using
索引
= typename Pool::Index
|
◆
Super
◆
Iterator
◆
ConstIterator
◆
KeyIterator
◆
ConstKeyIterator
◆
ValueIterator
◆
ConstValueIterator
构造函数 & 析构函数文档编制
◆
BurstTrieMap()
[1/4]
◆
BurstTrieMap()
[2/4]
◆
BurstTrieMap()
[3/4]
◆
BurstTrieMap()
[4/4]
◆
~BurstTrieMap()
成员函数文档编制
◆
MAXON_OPERATOR_MOVE_ASSIGNMENT()
MAXON_OPERATOR_MOVE_ASSIGNMENT
|
(
|
BurstTrieMap
< K, V, GROUP_BITS, BUCKET_SIZE, SORT, POOL >
|
|
)
|
|
◆
CopyFromImpl()
◆
Reset()
Resets the map. This destructs all entries and frees any memory held by the map, so the map will be in a state as if it had been newly constructed.
◆
Flush()
Flushes the map. For a
BurstTrieMap
, this does the same as
Reset()
, namely it destructs all entries and frees any memory held by the map.
◆
SetCapacityHint()
Does nothing for a
BurstTrieMap
.
-
返回
-
Always
true
.
◆
GetCount()
Returns the number of entries in this map.
-
返回
-
Number of entries.
◆
GetOperationCountForSearch()
Int
GetOperationCountForSearch
|
(
|
|
)
|
const
|
Returns an estimate of the number of operations needed to locate a given key in this map. This is used when two collections are compared: The iteration goes over the collection which would require more operations for search, and each entry is searched in the other collection.
-
返回
-
Estimate for the number of operations.
◆
GetDepth()
Returns the maximum depth of this trie.
-
返回
-
Maximum trie depth.
◆
GetMemorySize()
Int
GetMemorySize
|
(
|
|
)
|
const
|
Returns the memory usage of this map.
-
返回
-
Memory size in bytes.
◆
Begin()
[1/2]
Returns an iterator pointing to the first entry of this map. Unless the sorting mode is
BURSTTRIE_SORT::NONE
, the iteration order corresponds to the order of the keys.
-
返回
-
Iterator for this map pointing to the first element.
◆
End()
[1/2]
Returns an iterator pointing just behind the last entry of this map. Unless the sorting mode is
BURSTTRIE_SORT::NONE
, the iteration order corresponds to the order of the keys.
-
返回
-
Iterator for this map pointing behind the last element.
◆
Begin()
[2/2]
Returns an iterator pointing to the first entry of this map. Unless the sorting mode is
BURSTTRIE_SORT::NONE
, the iteration order corresponds to the order of the keys.
-
返回
-
Iterator for this map pointing to the first element.
◆
End()
[2/2]
Returns an iterator pointing just behind the last entry of this map. Unless the sorting mode is
BURSTTRIE_SORT::NONE
, the iteration order corresponds to the order of the keys.
-
返回
-
Iterator for this map pointing behind the last element.
◆
GetKeys()
[1/2]
Returns a foreach iterator to iterate over all keys of this map. Unless the sorting mode is
BURSTTRIE_SORT::NONE
, this will yield all keys in ascending order.
-
返回
-
Foreach iterator over all keys.
◆
GetKeys()
[2/2]
Returns a foreach iterator to iterate over all keys of this map. Unless the sorting mode is
BURSTTRIE_SORT::NONE
, this will yield all keys in ascending order.
-
返回
-
Foreach iterator over all keys.
◆
GetValues()
[1/2]
Returns a foreach iterator to iterate over all values of this map. Unless the sorting mode is
BURSTTRIE_SORT::NONE
, this will yield all values in ascending order of the corresponding keys.
-
返回
-
Foreach iterator over all values.
◆
GetValues()
[2/2]
Returns a foreach iterator to iterate over all values of this map. Unless the sorting mode is
BURSTTRIE_SORT::NONE
, this will yield all values in ascending order of the corresponding keys.
-
返回
-
Foreach iterator over all values.
◆
InsertEntry()
Finds the entry with the given key, or creates such an entry if it doesn't exist yet, and returns an iterator pointing to the entry. The value of a new entry has to be initialized afterwards (but its default constructor has already been invoked).
-
参数
-
[in]
|
key
|
Key of the entry to find or create.
|
[out]
|
created
|
This will be set to true if a new entry has been created successfully, otherwise it will be set to false.
|
-
返回
-
Iterator to the entry for the given key or OutOfMemoryError if the allocation failed.
◆
Insert()
[1/2]
Finds the entry with the given key, or creates such an entry if it doesn't exist yet, Then the value of the entry is set to the given value, whether the entry existed before or not.
-
参数
-
[in]
|
key
|
Key of the value to find or create.
|
[in]
|
value
|
Value to which the key shall map.
|
[out]
|
created
|
This will be set to true if a new entry has been created successfully, otherwise it will be set to false.
|
-
返回
-
Iterator to the entry for the given key or OutOfMemoryError if the allocation failed.
◆
Insert()
[2/2]
Finds the entry with the given key, or creates such an entry if it doesn't exist yet, Then the value of the entry is set to the given value, whether the entry existed before or not.
-
参数
-
[in]
|
key
|
Key of the value to find or create.
|
[in]
|
value
|
Value to which the key shall map. It will be moved into the map.
|
[out]
|
created
|
This will be set to true if a new entry has been created successfully, otherwise it will be set to false.
|
-
返回
-
Iterator to the entry for the given key or OutOfMemoryError if the allocation failed.
◆
InsertKey()
Finds the value associated with the given key, or creates a corresponding entry if it doesn't exist yet. The value of a new entry has to be initialized afterwards (but its default constructor has already been invoked).
-
参数
-
[in]
|
key
|
Key of the value to find or create.
|
[out]
|
created
|
This will be set to true if a new entry has been created successfully, otherwise it will be set to false.
|
-
返回
-
Pointer to value for the given key, or nullptr if an entry didn't exist and allocation of a new entry failed.
◆
FindValue()
[1/2]
const V* FindValue
|
(
|
K
|
key
|
)
|
const
|
Finds the value associated with the given key in this map.
-
参数
-
[in]
|
key
|
Key to search for.
|
-
返回
-
Pointer to value for the given key, or nullptr if no entry exists for the key.
◆
FindValue()
[2/2]
Finds the value associated with the given key in this map.
-
参数
-
[in]
|
key
|
Key to search for.
|
-
返回
-
Pointer to value for the given key, or nullptr if no entry exists for the key.
◆
Find()
[1/2]
Finds the entry for the given key in this map.
-
参数
-
[in]
|
key
|
Key to search for.
|
-
返回
-
Iterator pointing to the entry with the given
key
, or an invalid iterator if this doesn't exist.
◆
Find()
[2/2]
Finds the entry for the given key in this map.
-
参数
-
[in]
|
key
|
Key to search for.
|
-
返回
-
Iterator pointing to the entry with the given
key
, or an invalid iterator if this doesn't exist.
◆
FindFloor()
[1/2]
Finds the entry with the greatest key less than or equal to the given
key
. If no such entry exists, the returned iterator will be invalid (its
operator Bool
will return false). This function is not supported when the sorting mode is
BURSTTRIE_SORT::NONE
.
-
参数
-
[in]
|
key
|
Key to search for.
|
-
返回
-
Iterator pointing to the entry with greatest key less than or equal to the given
key
, or an invalid iterator if this doesn't exist.
◆
FindFloor()
[2/2]
Finds the entry with the greatest key less than or equal to the given
key
. If no such entry exists, the returned iterator will be invalid (its
operator Bool
will return false). This function is not supported when the sorting mode is
BURSTTRIE_SORT::NONE
.
-
参数
-
[in]
|
key
|
Key to search for.
|
-
返回
-
Iterator pointing to the entry with greatest key less than or equal to the given
key
, or an invalid iterator if this doesn't exist.
◆
Erase()
[1/2]
Removes an entry with the given key from this map (if possible).
-
参数
-
[in]
|
key
|
Key of the map entry to be be removed.
|
-
返回
-
True if an entry was found and removed for #key, otherwise false.
◆
Erase()
[2/2]
Removes
eraseCnt
elements from this map starting at the position given by
position
. The returned iterator will point to the element behind the last removed element.
-
参数
-
[in]
|
position
|
Iterator pointing to the first element to be removed.
|
[in]
|
eraseCnt
|
Number of elements to remove.
|
-
返回
-
Iterator pointing to the element behind the last removed element.
◆
MAXON_DISALLOW_COPY_AND_ASSIGN()
MAXON_DISALLOW_COPY_AND_ASSIGN
|
(
|
BurstTrieMap
< K, V, GROUP_BITS, BUCKET_SIZE, SORT, POOL >
|
|
)
|
|
|
private
|
◆
ClearRoots()
◆
GetDepthImpl()
Int
GetDepthImpl
|
(
|
索引
|
idx
|
)
|
const
|
|
private
|
◆
GetMemorySizeImpl()
Int
GetMemorySizeImpl
|
(
|
索引
|
idx
|
)
|
const
|
|
private
|
◆
DestructNodes()
void DestructNodes
|
(
|
索引
|
idx
|
)
|
|
|
private
|
◆
CopyNodes()
Result
<void> CopyNodes
|
(
|
索引
&
|
dest
,
|
|
|
const
BurstTrieMap
< K, V, GROUP_BITS, BUCKET_SIZE, SORT, POOL > &
|
srcMap
,
|
|
|
索引
|
src
|
|
)
|
|
|
|
private
|
Friends And Related Function Documentation
◆
BurstTrieMapUtils
friend class BurstTrieMapUtils
|
friend
|
Member Data Documentation
◆
GROUP_SIZE
const
Int
GROUP_SIZE
static
|
|
◆
GROUP_MASK
const
Int
GROUP_MASK
static
|
|
◆
MAX_LEN
◆
Pool
◆
_roots
Trie roots, indexed by the position of the highest non-zero group of the key.
◆
_size
Total number of key-value entries.