1 // Copyright 2013 Google Inc. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 // A btree_set<> implements the STL unique sorted associative container
16 // interface (a.k.a set<>) using a btree. A btree_multiset<> implements the STL
17 // multiple sorted associative container interface (a.k.a multiset<>) using a
18 // btree. See btree.h for details of the btree implementation and caveats.
20 #ifndef UTIL_BTREE_BTREE_SET_H__
21 #define UTIL_BTREE_BTREE_SET_H__
28 #include "btree_container.h"
32 // The btree_set class is needed mainly for its constructors.
33 template <typename Key
,
34 typename Compare
= std::less
<Key
>,
35 typename Alloc
= std::allocator
<Key
>,
36 int TargetNodeSize
= 256>
37 class btree_set
: public btree_unique_container
<
38 btree
<btree_set_params
<Key
, Compare
, Alloc
, TargetNodeSize
> > > {
40 typedef btree_set
<Key
, Compare
, Alloc
, TargetNodeSize
> self_type
;
41 typedef btree_set_params
<Key
, Compare
, Alloc
, TargetNodeSize
> params_type
;
42 typedef btree
<params_type
> btree_type
;
43 typedef btree_unique_container
<btree_type
> super_type
;
46 typedef typename
btree_type::key_compare key_compare
;
47 typedef typename
btree_type::allocator_type allocator_type
;
50 // Default constructor.
51 btree_set(const key_compare
&comp
= key_compare(),
52 const allocator_type
&alloc
= allocator_type())
53 : super_type(comp
, alloc
) {
57 btree_set(const self_type
&x
)
62 btree_set(self_type
&&x
)
67 // Copy/move assignment
68 self_type
& operator=(self_type x
) {
74 template <class InputIterator
>
75 btree_set(InputIterator b
, InputIterator e
,
76 const key_compare
&comp
= key_compare(),
77 const allocator_type
&alloc
= allocator_type())
78 : super_type(b
, e
, comp
, alloc
) {
82 template <typename K
, typename C
, typename A
, int N
>
83 inline void swap(btree_set
<K
, C
, A
, N
> &x
, btree_set
<K
, C
, A
, N
> &y
) {
87 // The btree_multiset class is needed mainly for its constructors.
88 template <typename Key
,
89 typename Compare
= std::less
<Key
>,
90 typename Alloc
= std::allocator
<Key
>,
91 int TargetNodeSize
= 256>
92 class btree_multiset
: public btree_multi_container
<
93 btree
<btree_set_params
<Key
, Compare
, Alloc
, TargetNodeSize
> > > {
95 typedef btree_multiset
<Key
, Compare
, Alloc
, TargetNodeSize
> self_type
;
96 typedef btree_set_params
<Key
, Compare
, Alloc
, TargetNodeSize
> params_type
;
97 typedef btree
<params_type
> btree_type
;
98 typedef btree_multi_container
<btree_type
> super_type
;
101 typedef typename
btree_type::key_compare key_compare
;
102 typedef typename
btree_type::allocator_type allocator_type
;
105 // Default constructor.
106 btree_multiset(const key_compare
&comp
= key_compare(),
107 const allocator_type
&alloc
= allocator_type())
108 : super_type(comp
, alloc
) {
112 btree_multiset(const self_type
&x
)
117 btree_multiset(self_type
&&x
)
122 // Copy/move assignment
123 self_type
& operator=(self_type x
) {
128 // Range constructor.
129 template <class InputIterator
>
130 btree_multiset(InputIterator b
, InputIterator e
,
131 const key_compare
&comp
= key_compare(),
132 const allocator_type
&alloc
= allocator_type())
133 : super_type(b
, e
, comp
, alloc
) {
137 template <typename K
, typename C
, typename A
, int N
>
138 inline void swap(btree_multiset
<K
, C
, A
, N
> &x
,
139 btree_multiset
<K
, C
, A
, N
> &y
) {
145 #endif // UTIL_BTREE_BTREE_SET_H__