ng updated this revision to Diff 130812.
ng added a comment.

As per the above suggestions, enabled _multi tree search only for transparent 
comparator functions, and added tests.


https://reviews.llvm.org/D42344

Files:
  libcxx/include/map  
  libcxx/include/set  
  libcxx/test/std/containers/associative/map/map.ops/transparent_count.pass.cpp 
  
  
libcxx/test/std/containers/associative/map/map.ops/transparent_equal_range.pass.cpp
  
  libcxx/test/std/containers/associative/set/transparent_count.pass.cpp 
  libcxx/test/std/containers/associative/set/transparent_equal_range.pass.cpp

Index: libcxx/test/std/containers/associative/set/transparent_equal_range.pass.cpp
===================================================================
--- libcxx/test/std/containers/associative/set/transparent_equal_range.pass.cpp
+++ libcxx/test/std/containers/associative/set/transparent_equal_range.pass.cpp
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <set>
+
+// class set
+
+// template<typename K>
+//     pair<iterator,iterator>             equal_range(const K& x);        //
+//     C++14
+// template<typename K>
+//     pair<const_iterator,const_iterator> equal_range(const K& x) const;  //
+//     C++14
+
+#include <cassert>
+#include <set>
+#include <utility>
+
+#include "min_allocator.h"
+#include "private_constructor.hpp"
+#include "test_macros.h"
+
+#if TEST_STD_VER <= 11
+#error "This test requires is C++14 (or later)"
+#else
+
+struct Comp {
+  using is_transparent = void;
+
+  bool operator()(const std::pair<int, int> &lhs,
+                  const std::pair<int, int> &rhs) const {
+    return lhs < rhs;
+  }
+
+  bool operator()(const std::pair<int, int> &lhs, int rhs) const {
+    return lhs.first < rhs;
+  }
+
+  bool operator()(int lhs, const std::pair<int, int> &rhs) const {
+    return lhs < rhs.first;
+  }
+};
+
+int main() {
+  std::set<std::pair<int, int>, Comp> s{{2, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 2}};
+
+  auto er = s.equal_range(1);
+  long nels = 0;
+
+  for (auto it = er.first; it != er.second; it++) {
+    assert(it->first == 1);
+    nels++;
+  }
+
+  assert(nels == 3);
+}
+#endif
Index: libcxx/test/std/containers/associative/set/transparent_count.pass.cpp 
===================================================================
--- libcxx/test/std/containers/associative/set/transparent_count.pass.cpp 
+++ libcxx/test/std/containers/associative/set/transparent_count.pass.cpp 
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <set>
+
+// class set
+
+// template<typename K>
+//     iterator lower_bound(const K& x);              // C++14
+// template<typename K>
+//     const_iterator lower_bound(const K& x) const;  // C++14
+
+#include <cassert>
+#include <set>
+#include <utility>
+
+#include "min_allocator.h"
+#include "private_constructor.hpp"
+#include "test_macros.h"
+
+#if TEST_STD_VER <= 11
+#error "This test requires is C++14 (or later)"
+#else
+
+struct Comp {
+  using is_transparent = void;
+
+  bool operator()(const std::pair<int, int> &lhs,
+                  const std::pair<int, int> &rhs) const {
+    return lhs < rhs;
+  }
+
+  bool operator()(const std::pair<int, int> &lhs, int rhs) const {
+    return lhs.first < rhs;
+  }
+
+  bool operator()(int lhs, const std::pair<int, int> &rhs) const {
+    return lhs < rhs.first;
+  }
+};
+
+int main() {
+  std::set<std::pair<int, int>, Comp> s{{2, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 2}};
+
+  auto cnt = s.count(1);
+  assert(cnt == 3);
+}
+#endif
Index: libcxx/test/std/containers/associative/map/map.ops/transparent_equal_range.pass.cpp  
===================================================================
--- libcxx/test/std/containers/associative/map/map.ops/transparent_equal_range.pass.cpp  
+++ libcxx/test/std/containers/associative/map/map.ops/transparent_equal_range.pass.cpp  
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// class map
+
+// template<typename K>
+//         pair<iterator,iterator>             equal_range(const K& x); // C++14
+// template<typename K>
+//         pair<const_iterator,const_iterator> equal_range(const K& x) const;
+//         // C++14
+
+#include <cassert>
+#include <map>
+#include <utility>
+
+#include "min_allocator.h"
+#include "private_constructor.hpp"
+#include "test_macros.h"
+
+#if TEST_STD_VER <= 11
+#error "This test requires is C++14 (or later)"
+#else
+
+struct Comp {
+  using is_transparent = void;
+
+  bool operator()(const std::pair<int, int> &lhs,
+                  const std::pair<int, int> &rhs) const {
+    return lhs < rhs;
+  }
+
+  bool operator()(const std::pair<int, int> &lhs, int rhs) const {
+    return lhs.first < rhs;
+  }
+
+  bool operator()(int lhs, const std::pair<int, int> &rhs) const {
+    return lhs < rhs.first;
+  }
+};
+
+int main() {
+  std::map<std::pair<int, int>, int, Comp> s{
+      {{2, 1}, 1}, {{1, 2}, 2}, {{1, 3}, 3}, {{1, 4}, 4}, {{2, 2}, 5}};
+
+  auto er = s.equal_range(1);
+  long nels = 0;
+
+  for (auto it = er.first; it != er.second; it++) {
+    assert(it->first.first == 1);
+    nels++;
+  }
+
+  assert(nels == 3);
+}
+#endif
Index: libcxx/test/std/containers/associative/map/map.ops/transparent_count.pass.cpp   
===================================================================
--- libcxx/test/std/containers/associative/map/map.ops/transparent_count.pass.cpp   
+++ libcxx/test/std/containers/associative/map/map.ops/transparent_count.pass.cpp   
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <map>
+
+// class map
+
+// template<typename K>
+//   size_type count(const K& x) const;        // C++14
+
+#include <cassert>
+#include <map>
+#include <utility>
+
+#include "min_allocator.h"
+#include "private_constructor.hpp"
+#include "test_macros.h"
+
+#if TEST_STD_VER <= 11
+#error "This test requires is C++14 (or later)"
+#else
+
+struct Comp {
+  using is_transparent = void;
+
+  bool operator()(const std::pair<int, int> &lhs,
+                  const std::pair<int, int> &rhs) const {
+    return lhs < rhs;
+  }
+
+  bool operator()(const std::pair<int, int> &lhs, int rhs) const {
+    return lhs.first < rhs;
+  }
+
+  bool operator()(int lhs, const std::pair<int, int> &rhs) const {
+    return lhs < rhs.first;
+  }
+};
+
+int main() {
+  std::map<std::pair<int, int>, int, Comp> s{
+      {{2, 1}, 1}, {{1, 2}, 2}, {{1, 3}, 3}, {{1, 4}, 4}, {{2, 2}, 5}};
+
+  auto cnt = s.count(1);
+  assert(cnt == 3);
+}
+#endif
Index: libcxx/include/set  
===================================================================
--- libcxx/include/set  
+++ libcxx/include/set  
@@ -668,7 +668,7 @@
     template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
     typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
-    count(const _K2& __k) const                    {return __tree_.__count_unique(__k);}
+    count(const _K2& __k) const                    {return __tree_.__count_multi(__k);}
 #endif
     _LIBCPP_INLINE_VISIBILITY
     iterator lower_bound(const key_type& __k)
@@ -715,11 +715,11 @@
     template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
     typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
-    equal_range(const _K2& __k)       {return __tree_.__equal_range_unique(__k);}
+    equal_range(const _K2& __k)       {return __tree_.__equal_range_multi(__k);}
     template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
     typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
-    equal_range(const _K2& __k) const {return __tree_.__equal_range_unique(__k);}
+    equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
 #endif
 };
 
Index: libcxx/include/map  
===================================================================
--- libcxx/include/map  
+++ libcxx/include/map  
@@ -1228,7 +1228,7 @@
     template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
     typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
-    count(const _K2& __k) const {return __tree_.__count_unique(__k);}
+    count(const _K2& __k) const {return __tree_.__count_multi(__k);}
 #endif
     _LIBCPP_INLINE_VISIBILITY
     iterator lower_bound(const key_type& __k)
@@ -1275,11 +1275,11 @@
     template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
     typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
-    equal_range(const _K2& __k)       {return __tree_.__equal_range_unique(__k);}
+    equal_range(const _K2& __k)       {return __tree_.__equal_range_multi(__k);}
     template <typename _K2>
     _LIBCPP_INLINE_VISIBILITY
     typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
-    equal_range(const _K2& __k) const {return __tree_.__equal_range_unique(__k);}
+    equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
 #endif
 
 private:
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to