Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef _GLIBCXX_PROFILE_PROFILER_ALGOS_H
00041 #define _GLIBCXX_PROFILE_PROFILER_ALGOS_H 1
00042
00043 namespace __gnu_profile
00044 {
00045
00046 template<typename _Container>
00047 void
00048 __insert_top_n(_Container& __output,
00049 const typename _Container::value_type& __value,
00050 typename _Container::size_type __n)
00051 {
00052 typename _Container::iterator __it = __output.begin();
00053 typename _Container::size_type __count = 0;
00054
00055
00056
00057 while (true)
00058 {
00059 if (__count >= __n)
00060
00061 return;
00062
00063 if (__it == __output.end())
00064 break;
00065
00066 if (*__it < __value)
00067 break;
00068
00069 ++__it;
00070 ++__count;
00071 }
00072
00073 __output.insert(__it, __value);
00074 }
00075
00076
00077 template<typename _Container>
00078 void
00079 __top_n(const _Container& __input, _Container& __output,
00080 typename _Container::size_type __n)
00081 {
00082 __output.clear();
00083 typename _Container::const_iterator __it;
00084 for (__it = __input.begin(); __it != __input.end(); ++__it)
00085 __insert_top_n(__output, *__it, __n);
00086 }
00087
00088
00089 template<typename _InputIterator, typename _Function>
00090 _Function
00091 __for_each(_InputIterator __first, _InputIterator __last, _Function __f)
00092 {
00093 for (; __first != __last; ++__first)
00094 __f(*__first);
00095 return __f;
00096 }
00097
00098
00099 template<typename _ForwardIterator, typename _Tp>
00100 _ForwardIterator
00101 __remove(_ForwardIterator __first, _ForwardIterator __last,
00102 const _Tp& __value)
00103 {
00104 if(__first == __last)
00105 return __first;
00106 _ForwardIterator __result = __first;
00107 ++__first;
00108 for(; __first != __last; ++__first)
00109 if(!(*__first == __value))
00110 {
00111 *__result = *__first;
00112 ++__result;
00113 }
00114 return __result;
00115 }
00116 }
00117
00118 #endif