24 #ifndef PPL_swapping_sort_templates_hh
25 #define PPL_swapping_sort_templates_hh 1
32 namespace Implementation {
34 template <
typename RA_Container,
typename Compare>
40 Compare comp = Compare())
53 template <
typename RA_Container>
69 template <
typename RA_Container>
86 template <
typename RA_Container1,
typename RA_Container2>
88 typedef typename RA_Container1::size_type
size_type;
104 template <
typename Sort_Comparer,
typename Unique_Comparer,
typename Swapper>
105 typename Sort_Comparer::size_type
107 Sort_Comparer sort_cmp,
108 Unique_Comparer unique_cmp,
109 Swapper indirect_swap) {
110 typedef typename Sort_Comparer::size_type index_type;
112 PPL_ASSERT(num_elems >= 2);
113 std::vector<index_type> iv;
114 iv.reserve(num_elems);
115 for (index_type i = 0, i_end = num_elems; i != i_end; ++i) {
119 typedef typename std::vector<index_type>::iterator Iter;
120 const Iter iv_begin = iv.begin();
121 Iter iv_end = iv.end();
124 std::sort(iv_begin, iv_end, sort_cmp);
129 for (index_type i = num_elems; i-- > 0; ) {
132 index_type src = iv[i];
134 indirect_swap(src, dst);
144 for (index_type i = num_elems; i-- > 0; ) {
149 iv_end = std::unique(iv_begin, iv_end, unique_cmp);
151 const index_type num_sorted =
static_cast<index_type
>(iv_end - iv_begin);
152 const index_type num_duplicates = num_elems - num_sorted;
153 if (num_duplicates == 0) {
159 while (dst < num_sorted && dst == iv[dst]) {
162 if (dst == num_sorted) {
163 return num_duplicates;
166 const index_type src = iv[dst];
167 indirect_swap(src, dst);
170 while (dst < num_sorted);
171 return num_duplicates;
174 template <
typename Iter>
184 #endif // !defined(PPL_swapping_sort_templates_hh)
Indirect_Swapper(RA_Container &cont, size_type base=0)
RA_Container1::size_type size_type
RA_Container::size_type size_type
void swap(CO_Tree &x, CO_Tree &y)
RA_Container::size_type size_type
bool operator()(size_type i, size_type j) const
const size_type base_index
const RA_Container & container
void operator()(size_type i, size_type j) const
const size_type base_index
void operator()(size_type i, size_type j) const
Indirect_Unique_Compare(const RA_Container &cont, size_type base=0)
const RA_Container & container
RA_Container::size_type size_type
RA_Container1 & container1
The entire library is confined to this namespace.
const size_type base_index
Indirect_Swapper2(RA_Container1 &cont1, RA_Container2 &cont2)
Sort_Comparer::size_type indirect_sort_and_unique(typename Sort_Comparer::size_type num_elems, Sort_Comparer sort_cmp, Unique_Comparer unique_cmp, Swapper indirect_swap)
RA_Container2 & container2
Indirect_Sort_Compare(const RA_Container &cont, size_type base=0, Compare comp=Compare())
Iter swapping_unique(Iter first, Iter last)
bool operator()(size_type i, size_type j) const