similar low-level iterator adapter for multimap value groups
This commit is contained in:
parent
c5e4725dcb
commit
81f87ba852
3 changed files with 51 additions and 11 deletions
|
|
@ -43,9 +43,6 @@
|
|||
|
||||
#include "lib/iter-adapter.hpp"
|
||||
|
||||
/////////////////////////TODO remove
|
||||
#include "lib/itertools.hpp"
|
||||
/////////////////////////TODO remove
|
||||
|
||||
|
||||
|
||||
|
|
@ -177,6 +174,8 @@ namespace iter_stl {
|
|||
|
||||
typedef RangeIter<PickKeyIter> KeyIter;
|
||||
typedef RangeIter<PickValIter> ValIter;
|
||||
|
||||
typedef DistinctIter<KeyIter> DistinctKeys;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -243,13 +242,33 @@ namespace iter_stl {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
/** @return Lumiera Forward Iterator to yield
|
||||
* the distinct keys from a multimap
|
||||
* @warning full scan of all keys, dropping repetitions
|
||||
*/
|
||||
template<class MAP>
|
||||
inline typename _MapT<MAP>::KeyIter
|
||||
eachDistinctKey (MAP)
|
||||
inline typename _MapT<MAP>::DistinctKeys
|
||||
eachDistinctKey (MAP& map)
|
||||
{
|
||||
UNIMPLEMENTED ("each distinct key a multimap as Lumiera Forward Iterator");
|
||||
return typename _MapT<MAP>::DistinctKeys (eachKey (map));
|
||||
}
|
||||
|
||||
|
||||
/** @return Lumiera Forward Iterator to yield
|
||||
* the distinct keys from a multimap
|
||||
* @warning full scan of all keys, dropping repetitions
|
||||
*/
|
||||
template<class MMAP, typename KEY>
|
||||
inline typename _MapT<MMAP>::ValIter
|
||||
eachValForKey (MMAP& multimap, KEY key)
|
||||
{
|
||||
typedef typename _MapT<MMAP>::EntryIter Pos;
|
||||
typedef typename _MapT<MMAP>::ValIter Range;
|
||||
typedef typename _MapT<MMAP>::PickValIter PickVal;
|
||||
|
||||
std::pair<Pos,Pos> valRange = multimap.equal_range (key);
|
||||
|
||||
return Range (PickVal (valRange.first), PickVal (valRange.second));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -62,8 +62,8 @@ namespace test{
|
|||
typedef std::map<int,int> MapII;
|
||||
typedef std::multimap<int,int> MMapII;
|
||||
|
||||
typedef std::tr1::unordered_map<int,int> HMap;
|
||||
typedef std::tr1::unordered_multimap<int,int> HMMap;
|
||||
typedef std::tr1::unordered_map<int,int> HMapII;
|
||||
typedef std::tr1::unordered_multimap<int,int> HMMapII;
|
||||
|
||||
|
||||
template<class MAP>
|
||||
|
|
@ -83,7 +83,7 @@ namespace test{
|
|||
{
|
||||
MUMAP map;
|
||||
for (uint i=0; i<NUM_ELMS; ++i)
|
||||
for (uint j=NUM_ELMS; j; --j)
|
||||
for (uint j=NUM_ELMS-i; j; --j)
|
||||
map.insert (std::make_pair (i, j));
|
||||
|
||||
return map;
|
||||
|
|
|
|||
|
|
@ -94,13 +94,21 @@ namespace test{
|
|||
if (0 < arg.size()) NUM_ELMS = lexical_cast<uint> (arg[0]);
|
||||
|
||||
checkDistinctValIter();
|
||||
|
||||
iterateMapKeyVal (getTestMap_int<MapII> (NUM_ELMS));
|
||||
iterateMapKeyVal (getTestMap_int<HMapII> (NUM_ELMS));
|
||||
|
||||
iterateMapKeyVal (getTestMultiMap_int<MMapII> (NUM_ELMS));
|
||||
iterateMapKeyVal (getTestMultiMap_int<HMMapII> (NUM_ELMS));
|
||||
|
||||
iterateValues4Key (getTestMultiMap_int<MMapII> (NUM_ELMS));
|
||||
iterateValues4Key (getTestMultiMap_int<HMMapII> (NUM_ELMS));
|
||||
}
|
||||
|
||||
|
||||
template<class MAP>
|
||||
void
|
||||
iterateMapKeyVal(MAP const& map)
|
||||
iterateMapKeyVal (MAP const& map)
|
||||
{
|
||||
PRINT_FUNC (iterateMapKeyVal, MAP);
|
||||
|
||||
|
|
@ -110,6 +118,19 @@ namespace test{
|
|||
}
|
||||
|
||||
|
||||
template<class MMAP>
|
||||
void
|
||||
iterateValues4Key (MMAP const& mumap)
|
||||
{
|
||||
PRINT_FUNC (iterateValues4Key, MMAP);
|
||||
|
||||
TEST_ITER (iter::eachValForKey, (mumap, 0));
|
||||
|
||||
// non-existing key should yield empty iterator
|
||||
CHECK (! iter::eachValForKey (mumap, NUM_ELMS));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
checkDistinctValIter()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue