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_map<> implements the STL unique sorted associative container
16 // interface and the pair associative container interface (a.k.a map<>) using a
17 // btree. A btree_multimap<> implements the STL multiple sorted associative
18 // container interface and the pair associtive container interface (a.k.a
19 // multimap<>) using a btree. See btree.h for details of the btree
20 // implementation and caveats.
22 #ifndef UTIL_BTREE_BTREE_MAP_H__
23 #define UTIL_BTREE_BTREE_MAP_H__
32 #include "btree_container.h"
36 // The btree_map class is needed mainly for its constructors.
37 template <typename Key
, typename Value
,
38 typename Compare
= std::less
<Key
>,
39 typename Alloc
= std::allocator
<std::pair
<const Key
, Value
> >,
40 int TargetNodeSize
= 256>
41 class btree_map
: public btree_map_container
<
42 btree
<btree_map_params
<Key
, Value
, Compare
, Alloc
, TargetNodeSize
> > > {
44 typedef btree_map
<Key
, Value
, Compare
, Alloc
, TargetNodeSize
> self_type
;
45 typedef btree_map_params
<
46 Key
, Value
, Compare
, Alloc
, TargetNodeSize
> params_type
;
47 typedef btree
<params_type
> btree_type
;
48 typedef btree_map_container
<btree_type
> super_type
;
51 typedef typename
btree_type::key_compare key_compare
;
52 typedef typename
btree_type::allocator_type allocator_type
;
55 // Default constructor.
56 btree_map(const key_compare
&comp
= key_compare(),
57 const allocator_type
&alloc
= allocator_type())
58 : super_type(comp
, alloc
) {
62 btree_map(const self_type
&x
)
67 template <class InputIterator
>
68 btree_map(InputIterator b
, InputIterator e
,
69 const key_compare
&comp
= key_compare(),
70 const allocator_type
&alloc
= allocator_type())
71 : super_type(b
, e
, comp
, alloc
) {
75 template <typename K
, typename V
, typename C
, typename A
, int N
>
76 inline void swap(btree_map
<K
, V
, C
, A
, N
> &x
,
77 btree_map
<K
, V
, C
, A
, N
> &y
) {
81 // The btree_multimap class is needed mainly for its constructors.
82 template <typename Key
, typename Value
,
83 typename Compare
= std::less
<Key
>,
84 typename Alloc
= std::allocator
<std::pair
<const Key
, Value
> >,
85 int TargetNodeSize
= 256>
86 class btree_multimap
: public btree_multi_container
<
87 btree
<btree_map_params
<Key
, Value
, Compare
, Alloc
, TargetNodeSize
> > > {
89 typedef btree_multimap
<Key
, Value
, Compare
, Alloc
, TargetNodeSize
> self_type
;
90 typedef btree_map_params
<
91 Key
, Value
, Compare
, Alloc
, TargetNodeSize
> params_type
;
92 typedef btree
<params_type
> btree_type
;
93 typedef btree_multi_container
<btree_type
> super_type
;
96 typedef typename
btree_type::key_compare key_compare
;
97 typedef typename
btree_type::allocator_type allocator_type
;
98 typedef typename
btree_type::data_type data_type
;
99 typedef typename
btree_type::mapped_type mapped_type
;
102 // Default constructor.
103 btree_multimap(const key_compare
&comp
= key_compare(),
104 const allocator_type
&alloc
= allocator_type())
105 : super_type(comp
, alloc
) {
109 btree_multimap(const self_type
&x
)
113 // Range constructor.
114 template <class InputIterator
>
115 btree_multimap(InputIterator b
, InputIterator e
,
116 const key_compare
&comp
= key_compare(),
117 const allocator_type
&alloc
= allocator_type())
118 : super_type(b
, e
, comp
, alloc
) {
122 template <typename K
, typename V
, typename C
, typename A
, int N
>
123 inline void swap(btree_multimap
<K
, V
, C
, A
, N
> &x
,
124 btree_multimap
<K
, V
, C
, A
, N
> &y
) {
130 #endif // UTIL_BTREE_BTREE_MAP_H__