From eb999ee4a356462b9f7e7feb70fed00a1f4b0c05 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sun, 5 May 2019 10:12:28 +0700 Subject: [PATCH 1/4] operator== speed up --- flat_map.hpp | 2 +- flat_set.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flat_map.hpp b/flat_map.hpp index c5a5e94..2116937 100644 --- a/flat_map.hpp +++ b/flat_map.hpp @@ -388,7 +388,7 @@ namespace flat_hpp const flat_map& r) { return l.size() == r.size() - && std::equal(l.begin(), l.end(), r.begin(), r.end()); + && std::equal(l.begin(), l.end(), r.begin()); } template < typename Key diff --git a/flat_set.hpp b/flat_set.hpp index c908d1f..da77c6f 100644 --- a/flat_set.hpp +++ b/flat_set.hpp @@ -334,7 +334,7 @@ namespace flat_hpp const flat_set& r) { return l.size() == r.size() - && std::equal(l.begin(), l.end(), r.begin(), r.end()); + && std::equal(l.begin(), l.end(), r.begin()); } template < typename Key From 07f00243cf7028d8c7b696a89c7f98291aa71dc5 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sun, 5 May 2019 10:40:55 +0700 Subject: [PATCH 2/4] make default move/copy ctors and operator= --- flat_map.hpp | 24 ++++-------------------- flat_set.hpp | 24 ++++-------------------- 2 files changed, 8 insertions(+), 40 deletions(-) diff --git a/flat_map.hpp b/flat_map.hpp index 2116937..e33244a 100644 --- a/flat_map.hpp +++ b/flat_map.hpp @@ -133,27 +133,11 @@ namespace flat_hpp insert(ilist); } - flat_map(flat_map&& other) - : data_(std::move(other.data_)) - , compare_(std::move(other.compare_)) {} + flat_map(flat_map&& other) = default; + flat_map(const flat_map& other) = default; - flat_map(const flat_map& other) - : data_(other.data_) - , compare_(other.compare_) {} - - flat_map& operator=(flat_map&& other) { - if ( this != &other ) { - flat_map(std::move(other)).swap(*this); - } - return *this; - } - - flat_map& operator=(const flat_map& other) { - if ( this != &other ) { - flat_map(other).swap(*this); - } - return *this; - } + flat_map& operator=(flat_map&& other) = default; + flat_map& operator=(const flat_map& other) = default; flat_map& operator=(std::initializer_list ilist) { flat_map(ilist).swap(*this); diff --git a/flat_set.hpp b/flat_set.hpp index da77c6f..dcc4d23 100644 --- a/flat_set.hpp +++ b/flat_set.hpp @@ -111,27 +111,11 @@ namespace flat_hpp insert(ilist); } - flat_set(flat_set&& other) - : data_(std::move(other.data_)) - , compare_(std::move(other.compare_)) {} + flat_set(flat_set&& other) = default; + flat_set(const flat_set& other) = default; - flat_set(const flat_set& other) - : data_(other.data_) - , compare_(other.compare_) {} - - flat_set& operator=(flat_set&& other) { - if ( this != &other ) { - flat_set(std::move(other)).swap(*this); - } - return *this; - } - - flat_set& operator=(const flat_set& other) { - if ( this != &other ) { - flat_set(other).swap(*this); - } - return *this; - } + flat_set& operator=(flat_set&& other) = default; + flat_set& operator=(const flat_set& other) = default; flat_set& operator=(std::initializer_list ilist) { flat_set(ilist).swap(*this); From 9695c1ee6901ff07008eddf9b7529ab58b7da43e Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sun, 5 May 2019 11:45:30 +0700 Subject: [PATCH 3/4] update README API --- README.md | 133 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 91 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index eefc06f..3a9c01a 100644 --- a/README.md +++ b/README.md @@ -191,40 +191,61 @@ value_compare value_comp() const; ### Non-member functions ```cpp -template < typename K, typename C, typename A > +template < typename Key + , typename Compare + , typename Allocator + , typename Container > void swap( - flat_set& l, - flat_set& r); + flat_set& l, + flat_set& r); -template < typename K, typename C, typename A > +template < typename Key + , typename Compare + , typename Allocator + , typename Container > bool operator==( - const flat_set& l, - const flat_set& r); + const flat_set& l, + const flat_set& r); -template < typename K, typename C, typename A > +template < typename Key + , typename Compare + , typename Allocator + , typename Container > bool operator!=( - const flat_set& l, - const flat_set& r); + const flat_set& l, + const flat_set& r); -template < typename K, typename C, typename A > +template < typename Key + , typename Compare + , typename Allocator + , typename Container > bool operator<( - const flat_set& l, - const flat_set& r); + const flat_set& l, + const flat_set& r); -template < typename K, typename C, typename A > +template < typename Key + , typename Compare + , typename Allocator + , typename Container > bool operator>( - const flat_set& l, - const flat_set& r); + const flat_set& l, + const flat_set& r); -template < typename K, typename C, typename A > +template < typename Key + , typename Compare + , typename Allocator + , typename Container > bool operator<=( - const flat_set& l, - const flat_set& r); + const flat_set& l, + const flat_set& r); -template < typename K, typename C, typename A > +template < typename Key + , typename Compare + , typename Allocator + , typename Container > bool operator>=( - const flat_set& l, - const flat_set& r); + const flat_set& l, + const flat_set& r); ``` ## Flat Map @@ -402,40 +423,68 @@ value_compare value_comp() const; ### Non-member functions ```cpp -template < typename K, typename V, typename C, typename A > +template < typename Key + , typename Value + , typename Compare + , typename Allocator + , typename Container > void swap( - flat_map& l, - flat_map& r); + flat_map& l, + flat_map& r); -template < typename K, typename V, typename C, typename A > +template < typename Key + , typename Value + , typename Compare + , typename Allocator + , typename Container > bool operator==( - const flat_map& l, - const flat_map& r); + const flat_map& l, + const flat_map& r); -template < typename K, typename V, typename C, typename A > +template < typename Key + , typename Value + , typename Compare + , typename Allocator + , typename Container > bool operator!=( - const flat_map& l, - const flat_map& r); + const flat_map& l, + const flat_map& r); -template < typename K, typename V, typename C, typename A > +template < typename Key + , typename Value + , typename Compare + , typename Allocator + , typename Container > bool operator<( - const flat_map& l, - const flat_map& r); + const flat_map& l, + const flat_map& r); -template < typename K, typename V, typename C, typename A > +template < typename Key + , typename Value + , typename Compare + , typename Allocator + , typename Container > bool operator>( - const flat_map& l, - const flat_map& r); + const flat_map& l, + const flat_map& r); -template < typename K, typename V, typename C, typename A > +template < typename Key + , typename Value + , typename Compare + , typename Allocator + , typename Container > bool operator<=( - const flat_map& l, - const flat_map& r); + const flat_map& l, + const flat_map& r); -template < typename K, typename V, typename C, typename A > +template < typename Key + , typename Value + , typename Compare + , typename Allocator + , typename Container > bool operator>=( - const flat_map& l, - const flat_map& r); + const flat_map& l, + const flat_map& r); ``` ## Flat Multiset From 82e67e730024488dfd09462cf6cf13ec6b703637 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sun, 5 May 2019 21:22:52 +0700 Subject: [PATCH 4/4] remove unnecessary uber_comparer_type from flat_set --- flat_set.hpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/flat_set.hpp b/flat_set.hpp index dcc4d23..5feda61 100644 --- a/flat_set.hpp +++ b/flat_set.hpp @@ -22,15 +22,6 @@ namespace flat_hpp , typename Allocator = std::allocator , typename Container = std::vector > class flat_set final { - class uber_comparer_type : public Compare { - public: - uber_comparer_type() = default; - uber_comparer_type(const Compare& c) : Compare(c) {} - - bool operator()(const Key& l, const Key& r) const { - return Compare::operator()(l, r); - } - }; public: using key_type = Key; using value_type = Key; @@ -292,7 +283,7 @@ namespace flat_hpp } private: container_type data_; - uber_comparer_type compare_; + Compare compare_; }; }