2
* Copyright (C) 2007-2008 Anael Orlinski
4
* This file is part of Panomatic.
6
* Panomatic is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* Panomatic is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with Panomatic; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#ifndef __detectpano_boundedset_h
22
#define __detectpano_boundedset_h
27
// a container that keeps the N best elements during insertion.
28
// then the container has a maximum size of N
30
// TEMPLATE CLASS limited_multiset
31
// by default will keep the N largest values.
32
// to keep the N smallest values, use greater as comparator
42
template <typename _Key, typename _Compare = std::less<_Key> >
47
std::set< _Key, _Compare> _set;
50
typedef typename std::set<_Key, _Compare>::iterator iterator;
52
// define the constructors
53
bounded_set() : _maxSize(std::numeric_limits<size_t>::max()), _set(std::set<_Key, _Compare>()) {}
55
bounded_set(size_t iMaxSize) : _set(std::set<_Key, _Compare>()), _maxSize (iMaxSize) {}
57
/// sets the max size of bounded set
58
void setMaxSize(int iMax)
63
/// Returns the maximum size of the bounded_set
64
size_t max_size() const
69
/// Returns the size of the limited_multiset.
85
// void swap(limited_multiset<_Key,_MaxLen ,_Compare, _Alloc>& __x)
87
// multiset::swap(__x);
92
while (_set.size() > _maxSize)
93
_set.erase(_set.begin());
96
// be careful, the returned iterator is always end !!!
97
// in fact we don't know if the added value is truncated.
98
void insert(const _Key & x)
104
std::set< _Key, _Compare>& getSet()
113
#endif // __detectpano_boundedset_h