aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/ext/pb_assoc/tree_policy.hpp
blob: 67a37a1fc3b002e43adc3cc97c6f1d05b96ff2fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// -*- C++ -*-

// Copyright (C) 2005 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING.  If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.

// As a special exception, you may use this file as part of a free software
// library without restriction.  Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License.  This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.

// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.

// Permission to use, copy, modify, sell, and distribute this software
// is hereby granted without fee, provided that the above copyright
// notice appears in all copies, and that both that copyright notice and
// this permission notice appear in supporting documentation. None of
// the above authors, nor IBM Haifa Research Laboratories, make any
// representation about the suitability of this software for any
// purpose. It is provided "as is" without express or implied warranty.

/*
 * @file tree_policy.hpp
 * Contains tree-related policies.
 */

#ifndef TREE_POLICY_HPP
#define TREE_POLICY_HPP

#include <functional>
#include <ext/pb_assoc/ms_trait.hpp>

namespace pb_assoc
{
  struct null_node_updator
  {
    inline void
    swap(null_node_updator& r_other);
  };

#include <ext/pb_assoc/detail/tree_policy/null_node_updator_imp.hpp>

  template<typename Key, typename Allocator = std::allocator<char> >
    class order_statistics_key
    {
    public:
      typedef Allocator 			allocator;
      typedef Key 				key_type;
      typedef typename allocator::template rebind<Key>::other::const_reference
      						const_key_reference;
      typedef typename allocator::template rebind<Key>::other::reference
      						key_reference;
      typedef typename allocator::size_type 	size_type;
      
      inline explicit
      order_statistics_key(const_key_reference r_key = Key());
      
      inline
      operator key_reference();
      
      inline
      operator key_type() const;
      
    private:
      // The logical key of the entry.
      key_type m_key;
      
      // The number of entries in the subtree rooted at the node of
      // this element.
      mutable size_type m_rank;

      template<typename Cntnr>
        friend class order_by_key;
      
      template<typename Some_Cmp_Fn, typename Some_Allocator>
        friend class order_statistics_key_cmp;
      
      template<typename Some_Key, typename Some_Allocator>
        friend class order_statistics_node_updator;
      
      template<typename Cntnr>
        friend class find_by_order;
      
      template<typename Cntnr, typename Some_Allocator>
        friend class order_statistics_key_verifier;
  };

  template<typename Cmp_Fn, typename Allocator = std::allocator<char> >
    class order_statistics_key_cmp 
    : public std::binary_function<
      order_statistics_key<typename Cmp_Fn::first_argument_type, Allocator>,
      order_statistics_key<typename Cmp_Fn::second_argument_type, Allocator>, bool>, 
    private Cmp_Fn
    {
    public:
      typedef Allocator allocator;
      typedef Cmp_Fn cmp_fn;
      
      typedef 
      order_statistics_key<typename Cmp_Fn::first_argument_type, Allocator>
      key_type;
      
      typedef
      typename allocator::template rebind<key_type>::other::const_reference
      const_key_reference;
      
      inline
      order_statistics_key_cmp();
      
      inline
      order_statistics_key_cmp(const Cmp_Fn& r_cmp_fn);
      
      inline bool
      operator()(const_key_reference, const_key_reference) const;
      
      inline cmp_fn& 
      get_cmp_fn();
      
      inline const cmp_fn& 
      get_cmp_fn() const;
    };
  
#define PB_ASSOC_CLASS_C_DEC \
	order_statistics_node_updator<Key, Allocator>

  template<typename Key, typename Allocator = std::allocator<char> >
    class order_statistics_node_updator
    {
    public:
      typedef Allocator allocator;
      typedef order_statistics_key< Key, Allocator> key_type;

      typedef
      typename Allocator::template rebind<key_type>::other::const_pointer
      const_key_pointer;
      
      inline void
      swap(PB_ASSOC_CLASS_C_DEC& r_other);

      inline void
      operator()(const_key_pointer, const_key_pointer, const_key_pointer);

    private:
      typedef typename Allocator::size_type size_type;
    };

#undef PB_ASSOC_CLASS_C_DEC

  template<class Cntnr>
    class find_by_order
    {
    public:
      typedef Cntnr 				cntnr;
      typedef typename cntnr::iterator 		iterator;
      typedef typename cntnr::const_iterator	const_iterator;
      typedef typename cntnr::size_type 	size_type;
      
      inline iterator
      operator()(Cntnr& r_c, size_type order) const;
      
      inline const_iterator
      operator()(const Cntnr& r_c, size_type order) const;
      
    private:
      typedef typename Cntnr::node_iterator 	node_iterator;
      typedef typename Cntnr::const_iterator 	cntnr_const_it;
      typedef typename Cntnr::iterator 		cntnr_it;
      
      inline static iterator
      find(Cntnr& r_c, size_type order);
      
      inline static const_iterator
      find(const Cntnr& r_c, size_type order);
    };

  template<class Cntnr>
    class order_by_key
    {
    public:
      typedef Cntnr 				cntnr;
      typedef typename Cntnr::key_type 		order_statistics_key_type;
      typedef typename order_statistics_key_type::key_type
      						underlying_key_type;
      typedef typename cntnr::size_type 	size_type;
      
      inline size_type
      operator()(const Cntnr& r_c, const underlying_key_type& r_key) const;
      
    private:
      typedef typename cntnr::const_iterator cntnr_const_it;
      typedef typename cntnr::iterator cntnr_it;
    };
  
#include <ext/pb_assoc/detail/tree_policy/order_statistics_imp.hpp>
} // namespace pb_assoc

#endif // #ifndef TREE_POLICY_HPP