use this to get the distinct keys of a multimap
This commit is contained in:
parent
ff2113e61f
commit
665bd19f8a
4 changed files with 50 additions and 7 deletions
|
|
@ -51,6 +51,7 @@
|
|||
#include "lib/iter-adapter.hpp"
|
||||
#include "lib/itertools.hpp"
|
||||
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <tr1/memory>
|
||||
|
||||
|
|
@ -259,8 +260,8 @@ namespace lib {
|
|||
{
|
||||
typedef typename MAP::key_type Key;
|
||||
typedef typename MAP::value_type::second_type Val;
|
||||
typedef typename IterSource<const Key>::iterator KeyIter;
|
||||
typedef typename IterSource< Val>::iterator ValIter;
|
||||
typedef typename IterSource<Key>::iterator KeyIter;
|
||||
typedef typename IterSource<Val>::iterator ValIter;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -275,8 +276,12 @@ namespace lib {
|
|||
struct _PairIterT
|
||||
{
|
||||
typedef typename IT::value_type PairType;
|
||||
typedef typename PairType::first_type KeyType;
|
||||
typedef typename PairType::second_type ValType;
|
||||
typedef typename PairType::first_type ConstKeyType;
|
||||
|
||||
// since we're returning the keys always by value,
|
||||
// we can strip the const added by the STL map types
|
||||
typedef typename boost::remove_const<ConstKeyType>::type KeyType;
|
||||
|
||||
typedef TransformIter<IT,KeyType> KeyIter;
|
||||
typedef TransformIter<IT,ValType> ValIter;
|
||||
|
|
@ -347,12 +352,17 @@ namespace lib {
|
|||
|
||||
/** @return a Lumiera Forward Iterator to yield
|
||||
* all \em distinct keys of a Multimap
|
||||
* @warning we do a full table scan to find
|
||||
* the distinct keys
|
||||
*/
|
||||
template<class MAP>
|
||||
typename _MapT<MAP>::KeyIter
|
||||
eachDistinctKey (MAP&) // map)
|
||||
eachDistinctKey (MAP& map)
|
||||
{
|
||||
UNIMPLEMENTED ("standard iter wrapper yielding all distinct keys of a multimap");
|
||||
typedef RangeIter<typename MAP::iterator> Range;
|
||||
|
||||
Range contents (map.begin(), map.end());
|
||||
return wrapIter (filterRepetitions (takePairFirst(contents)));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -305,7 +305,7 @@ namespace session {
|
|||
|
||||
/* == access for self-test == */
|
||||
|
||||
typedef lib::IterSource<const PID>::iterator IDIter;
|
||||
typedef lib::IterSource<PID>::iterator IDIter;
|
||||
|
||||
PlacementMO* _root_4check () { return root_.get(); }
|
||||
PlacementMO* _element_4check (ID id){ return base_entry(id).element.get();}
|
||||
|
|
|
|||
|
|
@ -363,6 +363,7 @@ out: (::X...........){13}$
|
|||
out: (::00:0.:....00){13}$
|
||||
out: (::X...........){13}$
|
||||
out: (::00:0.:....00){13}$
|
||||
out: distinct_keys::0::1::2::3::4::5::6::7::8::9::10::11::12
|
||||
END
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
#include <boost/noncopyable.hpp>
|
||||
#include <tr1/unordered_map>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
|
@ -50,8 +51,10 @@ namespace test{
|
|||
using lib::test::randTime;
|
||||
using util::isnil;
|
||||
using util::cStr;
|
||||
using std::make_pair;
|
||||
using std::string;
|
||||
using std::list;
|
||||
using std::rand;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
|
|
@ -149,12 +152,16 @@ namespace test{
|
|||
|
||||
typedef IterSource<int>::iterator IntIter;
|
||||
typedef IterSource<CStr>::iterator StrIter;
|
||||
typedef IterSource<const string>::iterator StringIter;
|
||||
typedef IterSource<string>::iterator StringIter;
|
||||
typedef IterSource<Time>::iterator TimeIter;
|
||||
|
||||
typedef std::map<string,Time> TreeMap;
|
||||
typedef std::tr1::unordered_map<string,Time> HashMap;
|
||||
|
||||
typedef std::multimap<int,int> TreeMultimap;
|
||||
typedef std::tr1::unordered_multimap<int,int>HashMultimap;
|
||||
|
||||
|
||||
virtual void
|
||||
run (Arg arg)
|
||||
{
|
||||
|
|
@ -164,6 +171,9 @@ namespace test{
|
|||
|
||||
verify_MapWrappers<TreeMap>();
|
||||
verify_MapWrappers<HashMap>();
|
||||
|
||||
verify_MultimapKeyIter<TreeMultimap>();
|
||||
verify_MultimapKeyIter<HashMultimap>();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -217,8 +227,30 @@ namespace test{
|
|||
ASSERT (!sIter && !tIter);
|
||||
}
|
||||
|
||||
|
||||
template<class MAP>
|
||||
void
|
||||
verify_MultimapKeyIter() ///< @see IterTools_test#verify_filterRepetitions
|
||||
{
|
||||
MAP testMap;
|
||||
for (uint i=0; i<NUM_ELMS; ++i)
|
||||
{
|
||||
uint n = 1 + rand() % 100;
|
||||
do testMap.insert (make_pair (i,n));
|
||||
while (--n);
|
||||
}
|
||||
ASSERT (NUM_ELMS < testMap.size(), "no repetition in test data??");
|
||||
|
||||
IntIter keys = eachDistinctKey (testMap);
|
||||
|
||||
cout << "distinct_keys";
|
||||
ASSERT (keys);
|
||||
pullOut (keys);
|
||||
ASSERT (!keys);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
LAUNCHER (IterSource_test, "unit common");
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue