Click
Loading...
Searching...
No Matches
algorithm.hh
1#ifndef CLICK_ALGORITHM_HH
2#define CLICK_ALGORITHM_HH
3CLICK_DECLS
4
5template <typename T>
6inline T *find(T *begin, T *end, const T &val)
7{
8 while (begin < end && *begin != val)
9 ++begin;
10 return begin;
11}
12
13template <typename T>
14inline const T *find(const T *begin, const T *end, const T &val)
15{
16 while (begin < end && *begin != val)
17 ++begin;
18 return begin;
19}
20
21template <typename T>
22inline void ignore_result(T result)
23{
24 (void) result;
25}
26
31template <typename T>
32inline void click_swap(T &a, T &b)
33{
34 T tmp(a);
35 a = b;
36 b = tmp;
37}
38
43template <typename T>
44inline void clear_by_swap(T &x)
45{
46 T tmp;
47 click_swap(x, tmp);
48}
49
54template <typename T, typename V>
55inline void assign_consume(T &x, const V &y)
56{
57 x = y;
58}
59
60#ifndef min
63template<typename _Tp>
64 inline const _Tp&
65 min(const _Tp& __a, const _Tp& __b)
66 {
67 if (__b < __a)
68 return __b;
69 return __a;
70 }
71
74template<typename _Tp>
75 inline const _Tp&
76 max(const _Tp& __a, const _Tp& __b)
77 {
78 if (__b > __a)
79 return __b;
80 return __a;
81 }
82#endif
83
84template <typename T, typename U = void> struct do_nothing;
85
87template <typename T, typename U>
88struct do_nothing {
89 typedef T first_argument_type;
90 typedef U second_argument_type;
91 typedef void result_type;
92 void operator()(const T &, const U &) {
93 }
94};
95
97template <typename T>
98struct do_nothing<T, void> {
99 typedef T argument_type;
100 typedef void result_type;
101 void operator()(const T &) {
102 }
103};
104
106template <typename T>
107struct less {
108 typedef T first_argument_type;
109 typedef T second_argument_type;
110 typedef bool result_type;
111 bool operator()(const T &x, const T &y) {
112 return x < y;
113 }
114};
115
119#define is_pow2(n) (((n) & ((n) - 1)) == 0)
120
124inline unsigned char next_msb(uint64_t x) {
125 return x <= 1 ? 1 : (64-__builtin_clzl(x-1));
126}
127
128
132inline uint64_t next_pow2(uint64_t x) {
133 return x == 1 ? 1 : 1<<(64-__builtin_clzl(x-1));
134}
135
136inline unsigned cantor(unsigned a, unsigned b) {
137 return ((a + b) * (a + b + 1))/2 + b;
138}
139
140CLICK_ENDDECLS
141#endif
Binary function object that does nothing when called.
Definition algorithm.hh:88
Function object that encapsulates operator<().
Definition algorithm.hh:107