Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
Permutation.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <ext/random>
9#include <ext/algorithm>
10#include <ext/foreach>
11
12#include <alib/set>
13#include <alib/vector>
14#include <alib/map>
15
16#include <global/GlobalData.h>
17
18namespace common {
19
21public:
22 template < class T >
24 ext::vector < T > dataVector ( data.begin ( ), data.end ( ) );
25
26 std::shuffle ( dataVector.begin ( ), dataVector.end ( ), ext::random_devices::semirandom );
27 ext::map < T, T > permutation;
28 for ( const ext::tuple < const T &, const T & > & fromToPair : ext::make_tuple_foreach ( data, dataVector ) ) {
29 permutation.insert ( std::make_pair ( std::get < 0 > ( fromToPair ), std::get < 1 > ( fromToPair ) ) );
30 }
31
33 common::Streams::log << "permutation map: " << permutation << std::endl;
34
35 return permutation;
36 }
37};
38
39} /* namespace common */
40
static bool verbose
Verbose flag. Some algorithms print additional runtime information about internal datastructures or t...
Definition: GlobalData.h:24
Definition: Permutation.hpp:20
static ext::map< T, T > permutationMap(const ext::set< T > &data)
Definition: Permutation.hpp:23
static ext::reference_wrapper< ext::ostream > log
Standard loging stream. Mapped to descriptor 4.
Definition: GlobalData.h:78
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
std::pair< iterator, bool > insert(const T &key, const R &value)
Insert variant with explicit key and value parameters.
Definition: map.hpp:118
static semirandom_device & semirandom
The reference to singleton semirandom device.
Definition: random.hpp:147
Definition: set.hpp:44
auto begin() &
Inherited behavior of begin for non-const instance.
Definition: set.hpp:99
auto end() &
Inherited behavior of end for non-const instance.
Definition: set.hpp:129
Class extending the tuple class from the standard library. Original reason is to allow printing of th...
Definition: tuple.hpp:42
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
auto begin() &
Inherited behavior of begin for non-const instance.
Definition: vector.hpp:125
auto end() &
Inherited behavior of end for non-const instance.
Definition: vector.hpp:155
Definition: Permutation.hpp:18
const_tuple_foreach< Types ... > make_tuple_foreach(const Types &... args)
Function construction of foreach tuple pack helper.
Definition: foreach.hpp:280
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79