14#ifndef ORDERED_VECTOR_H
15#define ORDERED_VECTOR_H
22template<
class Key,
class Compare = std::less<
int>,
class Vector = pvector<Key> >
class ov_multiset
26template<
class Key,
class Compare = std::less<
int>,
class Vector = pvector<Key> >
class ov_set
30template<
class Key,
class Compare = std::less<
int>,
class Vector = pvector<Key> >
class ordered_vector
55#define KEY_TYPE key_type_0
56#define VALUE_TYPE value_type_0
57#define REFERENCE reference_0
58#define CONST_REFERENCE const_reference_0
59#define KEY_COMPARE key_compare_0
60#define VALUE_COMPARE value_compare_0
61#define ITERATOR iterator_0
62#define CONST_ITERATOR const_iterator_0
63#define REVERSE_ITERATOR reverse_iterator_0
64#define CONST_REVERSE_ITERATOR const_reverse_iterator_0
65#define DIFFERENCE_TYPE difference_type_0
66#define SIZE_TYPE size_type_0
94template<
class Key,
class Compare = std::less<Key>,
class Vector = pvector<Key> >
99 typedef Key VALUE_TYPE;
100 typedef Key &REFERENCE;
101 typedef const Key &CONST_REFERENCE;
102 typedef Compare KEY_COMPARE;
103 typedef Compare VALUE_COMPARE;
108 typedef typename Vector::iterator ITERATOR;
109 typedef typename Vector::const_iterator CONST_ITERATOR;
110 typedef typename Vector::reverse_iterator REVERSE_ITERATOR;
111 typedef typename Vector::const_reverse_iterator CONST_REVERSE_ITERATOR;
113 typedef typename Vector::difference_type DIFFERENCE_TYPE;
114 typedef typename Vector::size_type SIZE_TYPE;
119 typedef KEY_TYPE key_type;
120 typedef VALUE_TYPE value_type;
121 typedef REFERENCE reference;
122 typedef CONST_REFERENCE const_reference;
123 typedef KEY_COMPARE key_compare;
124 typedef VALUE_COMPARE value_compare;
125 typedef ITERATOR iterator;
126 typedef CONST_ITERATOR const_iterator;
127 typedef REVERSE_ITERATOR reverse_iterator;
128 typedef CONST_REVERSE_ITERATOR const_reverse_iterator;
129 typedef DIFFERENCE_TYPE difference_type;
130 typedef SIZE_TYPE size_type;
135 INLINE ordered_vector(
TypeHandle type_handle = ov_set_type_handle);
136 INLINE ordered_vector(
const Compare &compare,
143 INLINE REVERSE_ITERATOR
rend();
145 INLINE CONST_ITERATOR
begin()
const;
146 INLINE CONST_ITERATOR
end()
const;
147 INLINE CONST_REVERSE_ITERATOR
rbegin()
const;
148 INLINE CONST_REVERSE_ITERATOR
rend()
const;
151 INLINE CONST_ITERATOR
cend()
const;
152 INLINE CONST_REVERSE_ITERATOR
crbegin()
const;
153 INLINE CONST_REVERSE_ITERATOR
crend()
const;
156 INLINE reference operator [] (SIZE_TYPE n);
157 INLINE const_reference operator [] (SIZE_TYPE n)
const;
160 INLINE const_reference
front()
const;
163 INLINE const_reference
back()
const;
171 INLINE
bool operator == (
const ordered_vector<Key, Compare, Vector> &other)
const;
172 INLINE
bool operator != (
const ordered_vector<Key, Compare, Vector> &other)
const;
174 INLINE
bool operator < (
const ordered_vector<Key, Compare, Vector> &other)
const;
175 INLINE
bool operator > (
const ordered_vector<Key, Compare, Vector> &other)
const;
176 INLINE
bool operator <= (
const ordered_vector<Key, Compare, Vector> &other)
const;
177 INLINE
bool operator >= (
const ordered_vector<Key, Compare, Vector> &other)
const;
180 ITERATOR insert_unique(ITERATOR position,
const VALUE_TYPE &key);
181 ITERATOR insert_nonunique(ITERATOR position,
const VALUE_TYPE &key);
182 INLINE std::pair<ITERATOR, bool> insert_unique(
const VALUE_TYPE &key);
183 INLINE ITERATOR insert_nonunique(
const VALUE_TYPE &key);
187 INLINE ITERATOR erase(ITERATOR position);
188 INLINE SIZE_TYPE erase(
const KEY_TYPE &key);
189 INLINE
void erase(ITERATOR first, ITERATOR last);
193 INLINE ITERATOR find(
const KEY_TYPE &key);
194 INLINE CONST_ITERATOR find(
const KEY_TYPE &key)
const;
195 INLINE ITERATOR find_particular(
const KEY_TYPE &key);
196 INLINE CONST_ITERATOR find_particular(
const KEY_TYPE &key)
const;
197 INLINE SIZE_TYPE
count(
const KEY_TYPE &key)
const;
199 INLINE ITERATOR lower_bound(
const KEY_TYPE &key);
200 INLINE CONST_ITERATOR lower_bound(
const KEY_TYPE &key)
const;
201 INLINE ITERATOR upper_bound(
const KEY_TYPE &key);
202 INLINE CONST_ITERATOR upper_bound(
const KEY_TYPE &key)
const;
203 INLINE std::pair<ITERATOR, ITERATOR> equal_range(
const KEY_TYPE &key);
204 INLINE std::pair<CONST_ITERATOR, CONST_ITERATOR> equal_range(
const KEY_TYPE &key)
const;
207 INLINE
void swap(ordered_vector<Key, Compare, Vector> &other);
211 bool verify_list_unique()
const;
212 bool verify_list_nonunique()
const;
217 INLINE
void resize(SIZE_TYPE n);
218 INLINE
void resize(SIZE_TYPE n,
const VALUE_TYPE &value);
221 INLINE ITERATOR nci(CONST_ITERATOR i);
222 INLINE ITERATOR find_insert_position(ITERATOR first, ITERATOR last,
223 const KEY_TYPE &key);
224 ITERATOR r_find_insert_position(ITERATOR first, ITERATOR last,
225 const KEY_TYPE &key);
226 CONST_ITERATOR r_find(CONST_ITERATOR first, CONST_ITERATOR last,
227 CONST_ITERATOR not_found,
228 const KEY_TYPE &key)
const;
229 CONST_ITERATOR r_find_particular(CONST_ITERATOR first, CONST_ITERATOR last,
230 CONST_ITERATOR not_found,
231 const KEY_TYPE &key)
const;
232 SIZE_TYPE r_count(CONST_ITERATOR first, CONST_ITERATOR last,
233 const KEY_TYPE &key)
const;
234 CONST_ITERATOR r_lower_bound(CONST_ITERATOR first, CONST_ITERATOR last,
235 const KEY_TYPE &key)
const;
236 CONST_ITERATOR r_upper_bound(CONST_ITERATOR first, CONST_ITERATOR last,
237 const KEY_TYPE &key)
const;
238 std::pair<CONST_ITERATOR, CONST_ITERATOR>
239 r_equal_range(CONST_ITERATOR first, CONST_ITERATOR last,
240 const KEY_TYPE &key)
const;
244 class EquivalentTest {
250 INLINE EquivalentTest(
const Compare &compare) :
251 _compare(compare) { }
252 INLINE
bool operator () (
const KEY_TYPE &a,
const KEY_TYPE &b) {
253 nassertr(!_compare(b, a),
false);
254 return !_compare(a, b);
268template<
class Key,
class Compare = std::less<Key>,
class Vector = pvector<Key> >
269class ov_set :
public ordered_vector<Key, Compare, Vector> {
271 typedef typename ordered_vector<Key, Compare, Vector>::ITERATOR ITERATOR;
272 typedef typename ordered_vector<Key, Compare, Vector>::VALUE_TYPE VALUE_TYPE;
274 INLINE ov_set(
TypeHandle type_handle = ov_set_type_handle);
275 INLINE ov_set(
const Compare &compare,
278 INLINE ITERATOR insert(ITERATOR position,
const VALUE_TYPE &key0);
279 INLINE std::pair<ITERATOR, bool> insert(
const VALUE_TYPE &key0);
289template<
class Key,
class Compare = std::less<Key>,
class Vector = pvector<Key> >
290class ov_multiset :
public ordered_vector<Key, Compare, Vector> {
292 typedef typename ordered_vector<Key, Compare, Vector>::ITERATOR ITERATOR;
293 typedef typename ordered_vector<Key, Compare, Vector>::VALUE_TYPE VALUE_TYPE;
295 INLINE ov_multiset(
TypeHandle type_handle = ov_set_type_handle);
296 INLINE ov_multiset(
const Compare &compare,
299 INLINE ITERATOR insert(ITERATOR position,
const VALUE_TYPE &key);
300 INLINE ITERATOR insert(
const VALUE_TYPE &key);
307#include "ordered_vector.T"
TypeHandle is the identifier used to differentiate C++ class types.
This template class presents an interface similar to the STL set or multiset (and ov_set and ov_multi...
reference back()
Returns a reference to the first element.
void reserve(size_type_0 n)
Informs the vector of a planned change in size; ensures that the capacity of the vector is greater th...
reference front()
Returns a reference to the first element.
size_type_0 max_size() const
Returns the maximum number of elements that can possibly be stored in an ordered vector.
const_reverse_iterator_0 crbegin() const
Returns the iterator that marks the first element in the ordered vector, when viewed in reverse order...
const_iterator_0 cbegin() const
Returns the iterator that marks the first element in the ordered vector.
size_type_0 count(const key_type_0 &key) const
Returns the number of elements that sort equivalent to the key that are in the vector.
const_iterator_0 cend() const
Returns the iterator that marks the end of the ordered vector.
reverse_iterator_0 rend()
Returns the iterator that marks the end of the ordered vector, when viewed in reverse order.
bool operator>=(const ordered_vector< Key, Compare, Vector > &other) const
Returns true if this ordered vector sorts lexicographically after the other one or is equivalent,...
const_reverse_iterator_0 rbegin() const
Returns the iterator that marks the first element in the ordered vector, when viewed in reverse order...
bool operator!=(const ordered_vector< Key, Compare, Vector > &other) const
Returns true if the two ordered vectors are not memberwise equivalent, false if they are.
bool operator==(const ordered_vector< Key, Compare, Vector > &other) const
Returns true if the two ordered vectors are memberwise equivalent, false otherwise.
void sort_unique()
Ensures that the vector is properly sorted after a potentially damaging operation.
bool operator<(const ordered_vector< Key, Compare, Vector > &other) const
Returns true if this ordered vector sorts lexicographically before the other one, false otherwise.
iterator_0 begin()
Returns the iterator that marks the first element in the ordered vector.
bool operator>(const ordered_vector< Key, Compare, Vector > &other) const
Returns true if this ordered vector sorts lexicographically after the other one, false otherwise.
const_reference back() const
Returns a const reference to the last element.
void push_back(const value_type_0 &key)
Adds the new element to the end of the vector without regard for proper sorting.
const_iterator_0 end() const
Returns the iterator that marks the end of the ordered vector.
reverse_iterator_0 rbegin()
Returns the iterator that marks the first element in the ordered vector, when viewed in reverse order...
void swap(ordered_vector< Key, Compare, Vector > &other)
Exchanges the contents of this vector and the other vector, in constant time (e.g....
bool operator<=(const ordered_vector< Key, Compare, Vector > &other) const
Returns true if this ordered vector sorts lexicographically before the other one or is equivalent,...
void sort_nonunique()
Ensures that the vector is properly sorted after a potentially damaging operation.
size_type_0 size() const
Returns the number of elements in the ordered vector.
bool empty() const
Returns true if the ordered vector is empty, false otherwise.
const_iterator_0 begin() const
Returns the iterator that marks the first element in the ordered vector.
iterator_0 end()
Returns the iterator that marks the end of the ordered vector.
const_reverse_iterator_0 crend() const
Returns the iterator that marks the end of the ordered vector, when viewed in reverse order.
const_reverse_iterator_0 rend() const
Returns the iterator that marks the end of the ordered vector, when viewed in reverse order.
void pop_back()
Removes the last element at the end of the vector.
iterator_0 insert_unverified(iterator_0 position, const value_type_0 &key)
Inserts the indicated key into the ordered vector at the indicated place.
const_reference front() const
Returns a const reference to the first element.
void push_back(value_type_0 &&key)
Adds the new element to the end of the vector without regard for proper sorting.
void clear()
Removes all elements from the ordered vector.
A specialization of ordered_vector that emulates a standard STL set: many copies of each element are ...
bool verify_list() const
Maps to verify_list_nonunique().
void sort()
Maps to sort_nonunique().
A specialization of ordered_vector that emulates a standard STL set: one copy of each element is allo...
void sort()
Maps to sort_unique().
bool verify_list() const
Maps to verify_list_unique().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.