Source code repo: http://github.com/khizmax/libcds/
Download: http://sourceforge.net/projects/libcds/files/
-
+
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CDSLIB_CONTAINER_CUCKOO_MAP_H
template <typename K>
node_type( K const& key )
- : m_val( std::make_pair( key_type(key), mapped_type() ))
+ : m_val( std::make_pair( key_type(key), mapped_type()))
{}
template <typename K, typename Q>
node_type( K const& key, Q const& v )
- : m_val( std::make_pair( key_type(key), mapped_type(v) ))
+ : m_val( std::make_pair( key_type(key), mapped_type(v)))
{}
template <typename K, typename... Args>
node_type( K&& key, Args&&... args )
- : m_val( std::forward<K>(key), std::move( mapped_type(std::forward<Args>(args)...)) )
+ : m_val( std::forward<K>(key), std::move( mapped_type(std::forward<Args>(args)...)))
{}
};
<b>About Cuckoo hashing</b>
[From "The Art of Multiprocessor Programming"]
- Cuckoo hashing is a hashing algorithm in which a newly added item displaces any earlier item
+ <a href="https://en.wikipedia.org/wiki/Cuckoo_hashing">Cuckoo hashing</a> is a hashing algorithm in which a newly added item displaces any earlier item
occupying the same slot. For brevity, a table is a k-entry array of items. For a hash set f size
N = 2k we use a two-entry array of tables, and two independent hash functions,
<tt> h0, h1: KeyRange -> 0,...,k-1</tt>
the average search complexity is <tt>O(PROBE_SET/2)</tt>.
However, the overhead of sorting can eliminate a gain of ordered search.
- The probe set is ordered if opt::compare or opt::less is specified in \p %CuckooSet
- declaration. Otherwise, the probe set is unordered and \p %CuckooSet must contain
- opt::equal_to option.
+ The probe set is ordered if \p compare or \p less is specified in \p Traits
+ template parameter. Otherwise, the probe set is unordered and \p Traits must contain
+ \p equal_to predicate.
Template arguments:
- \p Key - key type
- \p T - the type stored in the map.
- - \p Traits - map traits., default is \p cuckoo::traits.
+ - \p Traits - map traits, default is \p cuckoo::traits.
It is possible to declare option-based set with \p cuckoo::make_traits metafunction
result as \p Traits template argument.
CuckooMap(
hash_tuple_type&& h ///< hash functor tuple of type <tt>std::tuple<H1, H2, ... Hn></tt> where <tt> n == \ref c_nArity </tt>
)
- : base_class( std::forward<hash_tuple_type>(h) )
+ : base_class( std::forward<hash_tuple_type>(h))
{}
/// Constructs a map with given probe set properties and hash functor tuple (move semantics)
, unsigned int nProbesetThreshold ///< probe set threshold, <tt>nProbesetThreshold < nProbesetSize</tt>. If 0, nProbesetThreshold = nProbesetSize - 1
, hash_tuple_type&& h ///< hash functor tuple of type <tt>std::tuple<H1, H2, ... Hn></tt> where <tt> n == \ref c_nArity </tt>
)
- : base_class( nInitialSize, nProbesetSize, nProbesetThreshold, std::forward<hash_tuple_type>(h) )
+ : base_class( nInitialSize, nProbesetSize, nProbesetThreshold, std::forward<hash_tuple_type>(h))
{}
/// Destructor clears the map
- \p bNew - \p true if the item has been inserted, \p false otherwise
- \p item - an item of the map for \p key
- Returns std::pair<bool, bool> where \p first is \p true if operation is successfull,
+ Returns std::pair<bool, bool> where \p first is \p true if operation is successful,
i.e. the node has been inserted or updated,
\p second is \p true if new item has been added or \p false if the item with \p key
already exists.
bool erase_with( K const& key, Predicate pred, Func f )
{
CDS_UNUSED( pred );
- node_type * pNode = base_class::erase_with( key, cds::details::predicate_wrapper<node_type, Predicate, key_accessor>() );
+ node_type * pNode = base_class::erase_with( key, cds::details::predicate_wrapper<node_type, Predicate, key_accessor>());
if ( pNode ) {
f( pNode->m_val );
free_node( pNode );
bool contains( K const& key, Predicate pred )
{
CDS_UNUSED( pred );
- return base_class::contains( key, cds::details::predicate_wrapper<node_type, Predicate, key_accessor>() );
+ return base_class::contains( key, cds::details::predicate_wrapper<node_type, Predicate, key_accessor>());
}
//@cond
template <typename K, typename Predicate>
/// Clears the map
void clear()
{
- base_class::clear_and_dispose( node_disposer() );
+ base_class::clear_and_dispose( node_disposer());
}
/// Checks if the map is empty