00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PALUDIS_GUARD_PALUDIS_REPOSITORIES_VIRTUALS_FAST_UNIQUE_COPY_HH
00021 #define PALUDIS_GUARD_PALUDIS_REPOSITORIES_VIRTUALS_FAST_UNIQUE_COPY_HH 1
00022
00023 #include <paludis/util/iterator_funcs.hh>
00024 #include <functional>
00025
00026 namespace paludis
00027 {
00028
00029
00030
00031 namespace fast_unique_copy_internals
00032 {
00033
00034
00035
00036 template <typename I_, typename O_, typename C_>
00037 void
00038 real_fast_unique_copy(const I_ & start, const I_ & end, const I_ & full_end, O_ out,
00039 C_ comp, const I_ & mbgt)
00040 {
00041 if (start != end)
00042 {
00043
00044
00045 if ((mbgt != full_end) && ((comp(*previous(end), *mbgt)) || (! comp(*mbgt, *previous(end)))))
00046 return;
00047
00048
00049
00050 if ((! comp(*start, *previous(end))) && (! comp(*previous(end), *start)))
00051 {
00052 *out = *start;
00053 ++out;
00054 }
00055 else
00056 {
00057 I_ mid = start + (std::distance(start, end) >> 1);
00058 real_fast_unique_copy(start, mid, full_end, out, comp, mbgt);
00059 real_fast_unique_copy(mid, end, full_end, out, comp, previous(mid));
00060 }
00061 }
00062 }
00063 }
00064
00065
00066
00067
00068 template <typename I_, typename O_>
00069 void
00070 fast_unique_copy(const I_ & start, const I_ & end, O_ out)
00071 {
00072 fast_unique_copy_internals::real_fast_unique_copy(start, end, end, out,
00073 std::less<typename std::iterator_traits<I_>::value_type>(),
00074 end);
00075 }
00076
00077
00078
00079
00080 template <typename I_, typename O_, typename C_>
00081 void
00082 fast_unique_copy(const I_ & start, const I_ & end, O_ out, C_ comp)
00083 {
00084 fast_unique_copy_internals::real_fast_unique_copy(start, end, end, out, comp, end);
00085 }
00086 }
00087
00088 #endif