-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetUtility.h
More file actions
93 lines (82 loc) · 2.37 KB
/
Copy pathSetUtility.h
File metadata and controls
93 lines (82 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**************************************************
Zlib Copyright 2015 Daniel "MonzUn" Bengtsson
***************************************************/
#pragma once
#include "UtilityLibraryDefine.h"
namespace SetUtility {
template <typename t>
rVector<t> GetVectorDiff( const rVector<t>& lhs, const rVector<t>& rhs ) {
rVector<t> diff;
for ( int i = 0; i < lhs.size(); ++i ) {
bool isCopy = false;
for ( int j = 0; j < rhs.size(); ++j ) {
if ( lhs[i] == rhs[j] ) {
isCopy = true;
break;
}
}
if ( !isCopy ) {
diff.push_back( lhs[i] );
}
}
return diff;
}
template <typename t>
rVector<t> GetVectorIntersection( const rVector<t>& lhs, const rVector<t>& rhs ) { // TODODB: Make sure this cannot add copies
rVector<t> intersection;
for ( int i = 0; i < lhs.size(); ++i ) {
for ( int j = 0; j < rhs.size(); ++j ) {
if ( lhs[i] == rhs[j] ) {
intersection.push_back( lhs[i] );
break;
}
}
}
return intersection;
}
template <typename t>
rVector<t> GetVectorUnion( const rVector<t>& lhs, const rVector<t>& rhs ) { // TODODB: Test commutativity of this function
rVector<t> unionVector;
unionVector.insert( unionVector.begin(), lhs.begin(), lhs.end() );
for ( int i = 0; i < rhs.size(); ++i ) {
bool isCopy = false;
for ( int j = 0; j < lhs.size(); ++j ) {
if ( rhs[i] == lhs[j] ) {
isCopy = true;
break;
}
}
if ( !isCopy ) {
unionVector.push_back( rhs[i] );
}
}
return unionVector;
}
template <typename t>
int GetIndexOfElement( const t& element, const rVector<t>& list ) {
for ( int i = 0; i < list.size(); ++i ) {
if ( list[i] == element ) {
return i;
}
}
return -1;
}
template <typename M, typename V>
void PushMapKeysToVector( const M& map, V& vector ) {
for ( typename M::const_iterator it = map.begin(); it != map.end(); ++it ) {
vector.push_back( it->first );
}
}
template <typename M, typename V>
void PushMapValuesToVector( const M& map, V& vector ) {
for ( typename M::const_iterator it = map.begin(); it != map.end(); ++it )
vector.push_back( it->second );
}
template <typename M, typename V1, typename V2>
void PushMapToVectors( const M& map, V1& keysVector, V2& valuesVector ) {
for ( typename M::const_iterator it = map.begin(); it != map.end(); ++it ) {
keysVector.push_back( it->first );
valuesVector.push_back( it->second );
}
}
}