From d128866086035caa5f046c2af3a6f99d8efa1c73 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Fri, 15 Jan 2016 13:07:18 +0000 Subject: [PATCH] Added load_factor, key_eq & hash_function member functions. No tests added at this point. --- iunordered_map.h | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/iunordered_map.h b/iunordered_map.h index a81828c8..a313bd98 100644 --- a/iunordered_map.h +++ b/iunordered_map.h @@ -130,7 +130,7 @@ namespace etl typedef const value_type* const_pointer; typedef size_t size_type; - + typedef typename parameter_type::type key_value_parameter_t; // The nodes that store the elements. @@ -151,7 +151,7 @@ namespace etl typedef etl::ivector bucket_list_t; typedef typename bucket_list_t::iterator bucket_list_iterator; - + public: // Local iterators iterate over one bucket. @@ -586,7 +586,7 @@ namespace etl //********************************************************************* size_type bucket(key_value_parameter_t key) const { - return hash_function(key) % pbuckets->size(); + return key_hash_function(key) % pbuckets->size(); } //********************************************************************* @@ -747,9 +747,9 @@ namespace etl } //********************************************************************* - // Inserts a value to the unordered_map. - // If asserts or exceptions are enabled, emits unordered_map_full if the unordered_map is already full. - //\param value The value to insert. + /// Inserts a value to the unordered_map. + /// If asserts or exceptions are enabled, emits unordered_map_full if the unordered_map is already full. + ///\param value The value to insert. //********************************************************************* std::pair insert(const value_type& key_value_pair) { @@ -1084,6 +1084,33 @@ namespace etl return pnodepool->available(); } + //************************************************************************* + /// Returns the load factor = size / bucket_count. + ///\return The load factor = size / bucket_count. + //************************************************************************* + float load_factor() const + { + return static_cast(size()) / static_cast(bucket_count()); + } + + //************************************************************************* + /// Returns the function that hashes the keys. + ///\return The function that hashes the keys.. + //************************************************************************* + hasher hash_function() const + { + return key_hash_function; + } + + //************************************************************************* + /// Returns the function that compares the keys. + ///\return The function that compares the keys.. + //************************************************************************* + key_equal key_eq() const + { + return key_equal_function; + } + //************************************************************************* /// Assignment operator. //************************************************************************* @@ -1146,7 +1173,7 @@ namespace etl last = ibucket; } } - + // Disable copy construction. iunordered_map(const iunordered_map&); @@ -1161,7 +1188,7 @@ namespace etl bucket_list_iterator last; /// The function that creates the hashes. - hasher hash_function; + hasher key_hash_function; /// The function that compares the keys for equality. key_equal key_equal_function;