Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hopscotch Hashing [Ready] #128

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
1e97fbe
init
AndreyFdrv Dec 11, 2018
783a4a6
unit/striped-map/gtest-striped-map-hopscotch build errors fix
AndreyFdrv Dec 24, 2018
2e07cd8
fix build errors in test function of unit/striped-map/gtest-striped-m…
AndreyFdrv Dec 27, 2018
a6cf677
ASSERT_CONTAINER_SIZE build error fix in unit/striped-map/gtest-strip…
AndreyFdrv Dec 27, 2018
0575e84
m.contains(i.nKey) build error fix in unit/striped-map/gtest-striped-…
AndreyFdrv Dec 27, 2018
95b4288
alignment fix
AndreyFdrv Dec 27, 2018
def1a11
m.contains(key_type i) build error fix in unit/striped-map/gtest-stri…
AndreyFdrv Dec 27, 2018
3e8c52e
m.insert build error fix in unit/striped-map/gtest-striped-map-hopscotch
AndreyFdrv Dec 28, 2018
91a193e
m.insert(i.nKey) build error fix in unit/striped-map/gtest-striped-ma…
AndreyFdrv Dec 28, 2018
7e69d52
m.insert(std::string) build error fix in unit/striped-map/gtest-strip…
AndreyFdrv Dec 28, 2018
06ce084
m.insert_with build error fix in unit/striped-map/gtest-striped-map-h…
AndreyFdrv Dec 28, 2018
a2adfaa
m.update build error fix in unit/striped-map/gtest-striped-map-hopscotch
AndreyFdrv Dec 28, 2018
18e04f1
all build error fix in unit/striped-map/gtest-striped-map-hopscotch
AndreyFdrv Dec 28, 2018
80ed7ac
find_with(K const& key, Predicate pred, Func f) error fix in hopscotc…
AndreyFdrv Dec 29, 2018
cccfc0a
calc_hash(std::string) error fix in hopscotch-hasmmap
AndreyFdrv Dec 31, 2018
fe06050
update error fix in hopscotch-hashmap
AndreyFdrv Dec 31, 2018
c146974
erase error fix in hopscotch-hashmap
AndreyFdrv Dec 31, 2018
630c86e
build errors fix in stress/map/stress-map-del3
AndreyFdrv Jan 1, 2019
4f7534a
CDSSTRESS_HopscotchHashmap_case build error fix in stress/map/stress-…
AndreyFdrv Jan 1, 2019
ef742d6
key_thread to int operator in stress/map/stress-map-del3
AndreyFdrv Jan 1, 2019
d52fd11
Traits template parameter in hopscotch-map
AndreyFdrv Jan 2, 2019
fc939cc
statistics() in hopscotch-map
AndreyFdrv Jan 2, 2019
1bbd918
mutex_policy_statistics() in hopscotch-map
AndreyFdrv Jan 2, 2019
e99bd91
all build errors fix in stress/map/stress-map-del3
AndreyFdrv Jan 3, 2019
de637b4
infinity loop fix in stress/map/stress-map-del3
AndreyFdrv Jan 4, 2019
f216d0a
all stress tests errors fix in hopscotch-map
AndreyFdrv Jan 4, 2019
315a7cf
all unit tests errors fix in hopscotch-map
AndreyFdrv Jan 4, 2019
3bc2e7c
stress/set/stress-set-del3
AndreyFdrv Jan 6, 2019
0e7d7b6
stress/map/stress-map-delodd
AndreyFdrv Jan 8, 2019
4f51d2a
stress/set/stress-set-delodd
AndreyFdrv Jan 8, 2019
b1cc236
stress/map/stress-map-find_string
AndreyFdrv Jan 8, 2019
9bb8e50
stress/map/stress-map-insdelfind
AndreyFdrv Jan 8, 2019
0de1e8d
stress/set/stress-set-insdelfind
AndreyFdrv Jan 8, 2019
cd4dbc8
stress/map/stress-map-insdel-func
AndreyFdrv Jan 8, 2019
6e176ca
stress/set/stress-set-insdel-func
AndreyFdrv Jan 8, 2019
38a0b3d
stress/map/stress-map-insdel-item-int
AndreyFdrv Jan 8, 2019
6e2e715
stress/map/stress-map-insdel-string
AndreyFdrv Jan 8, 2019
108a90f
stress/set/stress-set-insdel-string
AndreyFdrv Jan 8, 2019
ce6e074
allignment fix
AndreyFdrv Jan 8, 2019
8813345
fix empty s_arrKeys in stress/map/stress-map-insdel-string
AndreyFdrv Jan 11, 2019
5cf9d88
allignment fix
AndreyFdrv Jan 11, 2019
191a1d0
undo changes in stress/set/stress-set-insdel-string
AndreyFdrv Jan 11, 2019
c3b017e
allignment fix
AndreyFdrv Jan 11, 2019
0e375fe
allignment fix
AndreyFdrv Jan 11, 2019
248acc4
undo changes in stress/map/stress-map-insdel-string
AndreyFdrv Jan 11, 2019
45f4880
undo changes in stress/map/stress-map-find_string
AndreyFdrv Jan 12, 2019
0023994
undo changes in stress/map/stress-map-find_string
AndreyFdrv Jan 12, 2019
7560e32
CMakeLists.txt fix
AndreyFdrv Jan 19, 2019
ed5be92
fix build error for CDS_BUILD_BITS=64 in test/stress/set/set_type_hop…
AndreyFdrv Jan 20, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
269 changes: 269 additions & 0 deletions cds/container/details/hopscotch_hashmap_base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
/*
This file is a part of libcds - Concurrent Data Structures library

(C) Copyright Maxim Khizhinsky ([email protected]) 2006-2017

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:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
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.
*/

#ifndef CDSLIB_CONTAINER_DETAILS_HOPSCOTCH_HASHMAP_BASE_H
#define CDSLIB_CONTAINER_DETAILS_HOPSCOTCH_HASHMAP_BASE_H

#include <cds/intrusive/hopscotch_hashset.h>

namespace cds { namespace container {

/// Hopscotch hashmap related definitions
/** @ingroup cds_nonintrusive_helper
*/
namespace hopscotch_hashmap_ns {
#ifdef CDS_DOXYGEN_INVOKED
/// Lock striping concurrent access policy. This is typedef for intrusive::hopscotch_hashset::striping template
class striping
{};
#else
using intrusive::hopscotch_hashset::striping;
#endif

#ifdef CDS_DOXYGEN_INVOKED
/// Refinable concurrent access policy. This is typedef for intrusive::hopscotch_hashset::refinable template
class refinable
{};
#else
using intrusive::hopscotch_hashset::refinable;
#endif

#ifdef CDS_DOXYGEN_INVOKED
/// Striping internal statistics. This is typedef for intrusive::hopscotch_hashset::striping_stat
class striping_stat
{};
#else
using intrusive::hopscotch_hashset::striping_stat;
#endif

#ifdef CDS_DOXYGEN_INVOKED
/// Empty striping internal statistics. This is typedef for intrusive::hopscotch_hashset::empty_striping_stat
class empty_striping_stat
{};
#else
using intrusive::hopscotch_hashset::empty_striping_stat;
#endif

#ifdef CDS_DOXYGEN_INVOKED
/// Refinable internal statistics. This is typedef for intrusive::hopscotch_hashset::refinable_stat
class refinable_stat
{};
#else
using intrusive::hopscotch_hashset::refinable_stat;
#endif

#ifdef CDS_DOXYGEN_INVOKED
/// Empty refinable internal statistics. This is typedef for intrusive::hopscotch_hashset::empty_refinable_stat
class empty_refinable_stat
{};
#else
using intrusive::hopscotch_hashset::empty_refinable_stat;
#endif

#ifdef CDS_DOXYGEN_INVOKED
/// Hopscotch hashmap statistics. This is typedef for intrusive::hopscotch_hashset::stat
class stat
{};
#else
using intrusive::hopscotch_hashset::stat;
#endif

#ifdef CDS_DOXYGEN_INVOKED
/// Hopscotch hashmap empty statistics.This is typedef for intrusive::hopscotch_hashset::empty_stat
class empty_stat
{};
#else
using intrusive::hopscotch_hashset::empty_stat;
#endif

/// Option specifying whether to store hash values in the node
/**
This option reserves additional space in the hook to store the hash value of the object once it's introduced in the container.
When this option is used, the unordered container will store the calculated hash value in the hook and rehashing operations won't need
to recalculate the hash of the value. This option will improve the performance of unordered containers
when rehashing is frequent or hashing the value is a slow operation

The \p Enable template parameter toggles the feature:
- the value \p true enables storing the hash values
- the value \p false disables storing the hash values
*/
template <bool Enable>
struct store_hash
{
//@cond
template <typename Base>
struct pack: public Base {
static bool const store_hash = Enable;
};
//@endcond
};

#ifdef CDS_DOXYGEN_INVOKED
/// Probe set type option
/**
@copydetails cds::intrusive::hopscotch_hashset::probeset_type
*/
template <typename Type>
struct probeset_type
{};
#else
using intrusive::hopscotch_hashset::probeset_type;
#endif

using intrusive::hopscotch_hashset::list;
using intrusive::hopscotch_hashset::vector;

/// Type traits for hopscotch hashmap class
struct traits
{
/// Hash functors tuple
/**
This is mandatory type and has no predefined one.

At least, two hash functors should be provided. All hash functor
should be orthogonal (different): for each <tt> i,j: i != j => h[i](x) != h[j](x) </tt>.
The hash functors are defined as <tt> std::tuple< H1, H2, ... Hn > </tt>:
\@code cds::opt::hash< std::tuple< h1, h2 > > \@endcode
The number of hash functors specifies the number \p k - the count of hash tables in hopscotch hashing.

To specify hash tuple in traits you should use \p cds::opt::hash_tuple:
\code
struct my_traits: public cds::container::hopscotch_hashmap::traits {
typedef cds::opt::hash_tuple< hash1, hash2 > hash;
};
\endcode
*/
typedef cds::opt::none hash;

/// Concurrent access policy
/**
Available opt::mutex_policy types:
- hopscotch_hashmap::striping - simple, but the lock array is not resizable
- hopscotch_hashmap::refinable - resizable lock array, but more complex access to set data.

Default is hopscotch_hashmap::striping.
*/
typedef hopscotch_hashmap_ns::striping<> mutex_policy;

/// Key equality functor
/**
Default is <tt>std::equal_to<T></tt>
*/
typedef opt::none equal_to;

/// Key comparison functor
/**
No default functor is provided. If the option is not specified, the \p less is used.
*/
typedef opt::none compare;

/// specifies binary predicate used for key comparison.
/**
Default is \p std::less<T>.
*/
typedef opt::none less;

/// Item counter
/**
The type for item counting feature.
Default is cds::atomicity::item_counter

Only atomic item counter type is allowed.
*/
typedef cds::intrusive::hopscotch_hashset::traits::item_counter item_counter;

/// Allocator type
/**
The allocator type for allocating bucket tables.
Default is \p CDS_DEFAULT_ALLOCATOR that is \p std::allocator
*/
typedef CDS_DEFAULT_ALLOCATOR allocator;

/// Node allocator type
/**
If this type is not set explicitly, the \ref allocator type is used.
*/
typedef opt::none node_allocator;

/// Store hash value into items. See hopscotch_hashmap::store_hash for explanation
static bool const store_hash = false;

/// Probe-set type. See \ref probeset_type option for explanation
typedef hopscotch_hashmap_ns::list probeset_type;

/// Internal statistics
typedef empty_stat stat;
};

/// Metafunction converting option list to hopscotch hashmap traits
/**
Template argument list \p Options... are:
- \p opt::hash - hash functor tuple, mandatory option. At least, two hash functors should be provided. All hash functor
should be orthogonal (different): for each <tt> i,j: i != j => h[i](x) != h[j](x) </tt>.
The hash functors are passed as <tt> std::tuple< H1, H2, ... Hn > </tt>. The number of hash functors specifies
the number \p k - the count of hash tables in hopscotch hashing.
- \p opt::mutex_policy - concurrent access policy.
Available policies: \p hopscotch_hashmap::striping, \p hopscotch_hashmap::refinable.
Default is \p %hopscotch_hashmap::striping.
- \p opt::equal_to - key equality functor like \p std::equal_to.
If this functor is defined then the probe-set will be unordered.
If \p %opt::compare or \p %opt::less option is specified too, then the probe-set will be ordered
and \p %opt::equal_to will be ignored.
- \p opt::compare - key comparison functor. No default functor is provided.
If the option is not specified, the \p %opt::less is used.
If \p %opt::compare or \p %opt::less option is specified, then the probe-set will be ordered.
- \p opt::less - specifies binary predicate used for key comparison. Default is \p std::less<T>.
If \p %opt::compare or \p %opt::less option is specified, then the probe-set will be ordered.
- \p opt::item_counter - the type of item counting feature. Default is \p opt::v::sequential_item_counter.
- \p opt::allocator - the allocator type using for allocating bucket tables.
Default is \ref CDS_DEFAULT_ALLOCATOR
- \p opt::node_allocator - the allocator type using for allocating set's items. If this option
is not specified then the type defined in \p %opt::allocator option is used.
- \p hopscotch_hashmap::store_hash - this option reserves additional space in the node to store the hash value
of the object once it's introduced in the container. When this option is used,
the unordered container will store the calculated hash value in the node and rehashing operations won't need
to recalculate the hash of the value. This option will improve the performance of unordered containers
when rehashing is frequent or hashing the value is a slow operation. Default value is \p false.
- \ref intrusive::hopscotch_hashset::probeset_type "hopscotch_hashset::probeset_type" - type of probe set, may be \p hopscotch_hashmap::list or <tt>hopscotch_hashmap::vector<Capacity></tt>,
Default is \p hopscotch_hashmap::list.
- \p opt::stat - internal statistics. Possibly types: \p hopscotch_hashmap::stat, \p hopscotch_hashmap::empty_stat.
Default is \p %hopscotch_hashmap::empty_stat
*/
template <typename... Options>
struct make_traits {
typedef typename cds::opt::make_options<
typename cds::opt::find_type_traits< hopscotch_hashmap_ns::traits, Options... >::type
,Options...
>::type type ; ///< Result of metafunction
};
} // namespace hopscotch_hashmap
}} // namespace cds::container

#endif // #ifndef CDSLIB_CONTAINER_DETAILS_HOPSCOTCH_HASHMAP_BASE_H
Loading