diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-03-20 13:11:19 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-03-20 13:17:28 +0000 |
commit | b7489abc1e241b276a1736fce9d3f9b4e160867d (patch) | |
tree | f3840e70014bd53df2f5a6f9973aa2dd524e4732 | |
parent | d6e56c260949a445e04dbe5429126907bddc994c (diff) |
Since the most important aspect our use of hash maps/sets is for speed we change from
using prime numbers as table size and modulo to using 2^N and using simple AND.
5 files changed, 24 insertions, 24 deletions
diff --git a/staging_vespalib/src/vespa/vespalib/stllike/lrucache_map.h b/staging_vespalib/src/vespa/vespalib/stllike/lrucache_map.h index 07137263cf6..777230566f2 100644 --- a/staging_vespalib/src/vespa/vespalib/stllike/lrucache_map.h +++ b/staging_vespalib/src/vespa/vespalib/stllike/lrucache_map.h @@ -28,32 +28,32 @@ struct LinkedValue : public LinkedValueBase template<typename K, typename V, typename H = vespalib::hash<K>, typename EQ = std::equal_to<K> > struct LruParam { - typedef LinkedValue<V> LV; - typedef std::pair< K, LV > value_type; - typedef vespalib::Select1st< value_type > select_key; - typedef K Key; - typedef V Value; - typedef H Hash; - typedef EQ Equal; - typedef hashtable< Key, value_type, Hash, Equal, select_key > HashTable; + using LV = LinkedValue<V>; + using value_type = std::pair< K, LV >; + using select_key = vespalib::Select1st< value_type >; + using Key = K; + using Value = V; + using Hash = H; + using Equal = EQ; + using HashTable = hashtable< Key, value_type, Hash, Equal, select_key >; }; template< typename P > class lrucache_map : private P::HashTable { private: - typedef typename P::HashTable HashTable; - typedef typename P::Value V; - typedef typename P::Key K; - typedef typename P::value_type value_type; - typedef typename P::LV LV; - typedef typename HashTable::iterator internal_iterator; - typedef typename HashTable::next_t next_t; - typedef typename HashTable::NodeStore NodeStore; + using HashTable = typename P::HashTable; + using V = typename P::Value; + using K = typename P::Key; + using value_type = typename P::value_type; + using LV = typename P::LV; + using internal_iterator = typename HashTable::iterator; + using next_t = typename HashTable::next_t; + using NodeStore = typename HashTable::NodeStore; protected: static constexpr size_t UNLIMITED = std::numeric_limits<size_t>::max(); public: - typedef typename HashTable::insert_result insert_result; + using insert_result = typename HashTable::insert_result; class iterator { public: @@ -177,8 +177,8 @@ public: void swap(lrucache_map & rhs); private: - typedef std::pair<uint32_t, uint32_t> MoveRecord; - typedef std::vector<MoveRecord> MoveRecords; + using MoveRecord = std::pair<uint32_t, uint32_t>; + using MoveRecords = std::vector<MoveRecord>; /** * Implements the resize of the hashtable */ diff --git a/staging_vespalib/src/vespa/vespalib/stllike/lrucache_map.hpp b/staging_vespalib/src/vespa/vespalib/stllike/lrucache_map.hpp index 61147229497..d8d55c9b8c4 100644 --- a/staging_vespalib/src/vespa/vespalib/stllike/lrucache_map.hpp +++ b/staging_vespalib/src/vespa/vespalib/stllike/lrucache_map.hpp @@ -74,7 +74,7 @@ lrucache_map<P>::lrucache_map(size_t maxElems) : { } template< typename P > -lrucache_map<P>::~lrucache_map() { } +lrucache_map<P>::~lrucache_map() = default; template< typename P > void diff --git a/vespalib/src/vespa/vespalib/stllike/hash_map.h b/vespalib/src/vespa/vespalib/stllike/hash_map.h index 3dc5de65285..29a5ef01a9f 100644 --- a/vespalib/src/vespa/vespalib/stllike/hash_map.h +++ b/vespalib/src/vespa/vespalib/stllike/hash_map.h @@ -7,7 +7,7 @@ namespace vespalib { -template< typename K, typename V, typename H = vespalib::hash<K>, typename EQ = std::equal_to<>, typename M=hashtable_base::prime_modulator > +template< typename K, typename V, typename H = vespalib::hash<K>, typename EQ = std::equal_to<>, typename M=hashtable_base::and_modulator > class hash_map { public: diff --git a/vespalib/src/vespa/vespalib/stllike/hash_set.h b/vespalib/src/vespa/vespalib/stllike/hash_set.h index 08288086bf3..0c3f2dcb220 100644 --- a/vespalib/src/vespa/vespalib/stllike/hash_set.h +++ b/vespalib/src/vespa/vespalib/stllike/hash_set.h @@ -8,7 +8,7 @@ namespace vespalib { -template< typename K, typename H = vespalib::hash<K>, typename EQ = std::equal_to<>, typename M=hashtable_base::prime_modulator> +template< typename K, typename H = vespalib::hash<K>, typename EQ = std::equal_to<>, typename M=hashtable_base::and_modulator> class hash_set { private: diff --git a/vespalib/src/vespa/vespalib/stllike/hash_set.hpp b/vespalib/src/vespa/vespalib/stllike/hash_set.hpp index 19114798806..3e48e62f2c7 100644 --- a/vespalib/src/vespa/vespalib/stllike/hash_set.hpp +++ b/vespalib/src/vespa/vespalib/stllike/hash_set.hpp @@ -85,11 +85,11 @@ hash_set<K, H, EQ, M>::insert(K &&value) { #define VESPALIB_HASH_SET_INSTANTIATE(K) \ template class vespalib::hash_set<K>; \ - template class vespalib::hashtable<K, K, vespalib::hash<K>, std::equal_to<>, vespalib::Identity>; \ + template class vespalib::hashtable<K, K, vespalib::hash<K>, std::equal_to<>, vespalib::Identity, vespalib::hashtable_base::and_modulator>; \ template class vespalib::Array<vespalib::hash_node<K>>; #define VESPALIB_HASH_SET_INSTANTIATE_H(K, H) \ template class vespalib::hash_set<K, H>; \ - template class vespalib::hashtable<K, K, H, std::equal_to<>, vespalib::Identity>; \ + template class vespalib::hashtable<K, K, H, std::equal_to<>, vespalib::Identity, vespalib::hashtable_base::and_modulator>; \ template class vespalib::Array<vespalib::hash_node<K>>; |