-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsertion_policies.hpp
83 lines (76 loc) · 2.53 KB
/
insertion_policies.hpp
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
#ifndef _INSERTION_POLICIES_HPP_
#define _INSERTION_POLICIES_HPP_
#include <algorithm>
struct push_back_gamete
//! An insertion policy for the mutate function.
{
template< typename gamete_type,
typename vector_type_allocator,
typename list_type_allocator,
template<typename,typename> class vector_type,
template<typename,typename> class list_type>
inline void operator()( const gamete_type & ng,
vector_type<gamete_type,vector_type_allocator > * gametes,
const size_t current_num_gametes,
const list_type<typename gamete_type::mutation_type,list_type_allocator> * mutations) const
{
gametes->push_back(ng);
}
};
struct insert_unique
//! An insertion policy
{
template<typename gamete_type,
typename vector_type_allocator,
typename list_type_allocator,
template<typename,typename> class vector_type,
template<typename,typename> class list_type>
inline void operator()(const gamete_type & ng,
vector_type<gamete_type,vector_type_allocator > * gametes,
const size_t current_num_gametes,
const list_type<typename gamete_type::mutation_type,list_type_allocator> * mutations) const
{
typedef typename vector_type<gamete_type,vector_type_allocator >::iterator vtype_iterator;
vtype_iterator itr=std::find(gametes->begin(),gametes->end(),ng);
if(itr == gametes->end())
{
gametes->push_back(ng);
}
else
{
itr->n++;
}
}
template< typename gamete_type,
typename vector_type_allocator,
template<typename,typename> class vector_type >
inline void operator()(const gamete_type & ng,
vector_type<gamete_type, vector_type_allocator > * gametes) const
{
typedef typename vector_type<gamete_type, vector_type_allocator >::iterator vtype_iterator;
vtype_iterator itr=std::find(gametes->begin(),gametes->end(),ng);
if(itr == gametes->end())
{
gametes->push_back(ng);
}
else
{
itr->n++;
}
}
};
template<typename mutation_type,typename list_type>
inline typename list_type::iterator insert_mutation_at_end(list_type * mutations, const mutation_type & m)
{
return (mutations->insert(mutations->end(),m));
}
template<typename mutation_type,
typename list_type>
inline typename list_type::iterator
insert_unique_mutation(list_type * mutations, const mutation_type & m)
{
typename list_type::iterator itr = std::find(mutations->begin(),mutations->end(),m);
if( itr != mutations->end() ) return (itr);
return (mutations->insert(mutations->end(),m));
}
#endif /* _INSERTION_POLICIES_HPP_ */