1 #ifndef __DIADES__UTILS__SELECTION__HH 2 #define __DIADES__UTILS__SELECTION__HH 20 using std::stringstream;
29 template<
typename Item>
62 unsigned index) : _unselectedItemPool(unselectedItemPool),
69 return _unselectedItemPool[
_index];
74 return &_unselectedItemPool[
_index];
92 return(_unselectedItemPool == it._unselectedItemPool) && (_index == it._index);
97 return !(*
this == it);
108 _unselectedItemPool(items.size()),
109 _position(items.size()),
110 _selectedIndexStart(items.size())
112 for(
unsigned index = 0; index < _items.size(); ++index)
114 _unselectedItemPool[index] = index;
115 _position[index] = index;
142 return IndexIterator(_unselectedItemPool, _unselectedItemPool.size());
178 return _items.size();
191 return IndexIterator(_unselectedItemPool, _selectedIndexStart);
204 return IndexIterator(_unselectedItemPool, _unselectedItemPool.size());
230 return IndexIterator(_unselectedItemPool, _selectedIndexStart);
240 typename ItemVector::const_iterator
253 typename ItemVector::const_iterator
266 typename ItemVector::const_iterator
269 return _items.begin();
279 typename ItemVector::const_iterator
309 return _selectedIndexStart == 0;
324 unsigned result = _unselectedItemPool[0];
325 select(_unselectedItemPool[0]);
339 return _items[index];
351 unsigned theSelectedToSwap = _unselectedItemPool[_position[index]];
352 unsigned oldPositionOfTheSelectedToSwap = _position[index];
354 _unselectedItemPool[oldPositionOfTheSelectedToSwap] = theNonSelectedToSwap;
357 _position[theNonSelectedToSwap] = oldPositionOfTheSelectedToSwap;
367 cout <<
"*******************************************************************************" << endl;
368 cout <<
"CURRENT TABLES:" << endl;
370 for(
unsigned i = 0; i < _items.size(); ++i)
372 cout << _items[i] <<
"\t";
376 for(
unsigned i = 0; i < _items.size(); ++i)
378 cout << _unselectedItemPool[i] <<
"\t";
382 for(
unsigned i = 0; i < _items.size(); ++i)
384 cout << _position[i] <<
"\t";
388 cout <<
"SELECTED ITEMS:" << endl;
390 for(
unsigned i = _selectedIndexStart; i < _items.size(); ++i)
392 cout << _items[_unselectedItemPool[i]] <<
"\t";
395 cout <<
"UNSELECTED ITEMS:" << endl;
399 cout << _items[_unselectedItemPool[i]] <<
"\t";
403 cout <<
"POSITIONS (should be exactly the same as the first table:" << endl;
405 for(
unsigned i = 0; i < _items.size(); ++i)
407 cout << _items[_unselectedItemPool[_position[i]]] <<
"\t";
410 cout <<
"*******************************************************************************" << endl;
IndexIterator selectedIndexEnd() const
const ItemVector & _items
unsigned _selectedIndexStart
ItemVector::const_iterator nonSelectedBegin() const
IndexIterator(const vector< unsigned > &unselectedItemPool, unsigned index)
IndexIterator nonSelectedIndexBegin() const
IndexIterator nonSelectedIndexEnd() const
ItemVector::const_iterator nonSelectedEnd() const
IndexIterator indexEnd() const
bool hasBeenAlreadySelectedOnce(unsigned index) const
reference operator*() const
unsigned numberOfItems() const
vector< unsigned > _position
void select(unsigned index)
std::forward_iterator_tag iterator_category
vector< unsigned > _unselectedItemPool
const Item & getItem(unsigned index) const
Namespace of the Diades project.
bool operator==(const self &it) const
pointer operator->() const
std::ptrdiff_t difference_type
const vector< unsigned > & _unselectedItemPool
unsigned numberOfSelectedItems() const
ItemVector::const_iterator selectedEnd() const
IndexIterator indexBegin() const
ItemVector::const_iterator selectedBegin() const
IndexIterator selectedIndexBegin() const
bool operator!=(const self &it) const
unsigned numberOfNonSelectedItems() const
vector< Item > ItemVector
const unsigned & reference
Selection(const vector< Item > &items)