src/cx/compare.h

changeset 890
54565fd74e74
parent 786
b0ebb3d88407
equal deleted inserted replaced
889:f549fd9fbd8f 890:54565fd74e74
46 #define CX_COMPARE_FUNC_DEFINED 46 #define CX_COMPARE_FUNC_DEFINED
47 /** 47 /**
48 * A comparator function comparing two collection elements. 48 * A comparator function comparing two collection elements.
49 */ 49 */
50 typedef int(*cx_compare_func)( 50 typedef int(*cx_compare_func)(
51 void const *left, 51 const void *left,
52 void const *right 52 const void *right
53 ); 53 );
54 #endif // CX_COMPARE_FUNC_DEFINED 54 #endif // CX_COMPARE_FUNC_DEFINED
55 55
56 /** 56 /**
57 * Compares two integers of type int. 57 * Compares two integers of type int.
59 * @param i1 pointer to integer one 59 * @param i1 pointer to integer one
60 * @param i2 pointer to integer two 60 * @param i2 pointer to integer two
61 * @return -1, if *i1 is less than *i2, 0 if both are equal, 61 * @return -1, if *i1 is less than *i2, 0 if both are equal,
62 * 1 if *i1 is greater than *i2 62 * 1 if *i1 is greater than *i2
63 */ 63 */
64 int cx_cmp_int(void const *i1, void const *i2); 64 int cx_cmp_int(const void *i1, const void *i2);
65 65
66 /** 66 /**
67 * Compares two integers of type long int. 67 * Compares two integers of type long int.
68 * 68 *
69 * @param i1 pointer to long integer one 69 * @param i1 pointer to long integer one
70 * @param i2 pointer to long integer two 70 * @param i2 pointer to long integer two
71 * @return -1, if *i1 is less than *i2, 0 if both are equal, 71 * @return -1, if *i1 is less than *i2, 0 if both are equal,
72 * 1 if *i1 is greater than *i2 72 * 1 if *i1 is greater than *i2
73 */ 73 */
74 int cx_cmp_longint(void const *i1, void const *i2); 74 int cx_cmp_longint(const void *i1, const void *i2);
75 75
76 /** 76 /**
77 * Compares two integers of type long long. 77 * Compares two integers of type long long.
78 * 78 *
79 * @param i1 pointer to long long one 79 * @param i1 pointer to long long one
80 * @param i2 pointer to long long two 80 * @param i2 pointer to long long two
81 * @return -1, if *i1 is less than *i2, 0 if both are equal, 81 * @return -1, if *i1 is less than *i2, 0 if both are equal,
82 * 1 if *i1 is greater than *i2 82 * 1 if *i1 is greater than *i2
83 */ 83 */
84 int cx_cmp_longlong(void const *i1, void const *i2); 84 int cx_cmp_longlong(const void *i1, const void *i2);
85 85
86 /** 86 /**
87 * Compares two integers of type int16_t. 87 * Compares two integers of type int16_t.
88 * 88 *
89 * @param i1 pointer to int16_t one 89 * @param i1 pointer to int16_t one
90 * @param i2 pointer to int16_t two 90 * @param i2 pointer to int16_t two
91 * @return -1, if *i1 is less than *i2, 0 if both are equal, 91 * @return -1, if *i1 is less than *i2, 0 if both are equal,
92 * 1 if *i1 is greater than *i2 92 * 1 if *i1 is greater than *i2
93 */ 93 */
94 int cx_cmp_int16(void const *i1, void const *i2); 94 int cx_cmp_int16(const void *i1, const void *i2);
95 95
96 /** 96 /**
97 * Compares two integers of type int32_t. 97 * Compares two integers of type int32_t.
98 * 98 *
99 * @param i1 pointer to int32_t one 99 * @param i1 pointer to int32_t one
100 * @param i2 pointer to int32_t two 100 * @param i2 pointer to int32_t two
101 * @return -1, if *i1 is less than *i2, 0 if both are equal, 101 * @return -1, if *i1 is less than *i2, 0 if both are equal,
102 * 1 if *i1 is greater than *i2 102 * 1 if *i1 is greater than *i2
103 */ 103 */
104 int cx_cmp_int32(void const *i1, void const *i2); 104 int cx_cmp_int32(const void *i1, const void *i2);
105 105
106 /** 106 /**
107 * Compares two integers of type int64_t. 107 * Compares two integers of type int64_t.
108 * 108 *
109 * @param i1 pointer to int64_t one 109 * @param i1 pointer to int64_t one
110 * @param i2 pointer to int64_t two 110 * @param i2 pointer to int64_t two
111 * @return -1, if *i1 is less than *i2, 0 if both are equal, 111 * @return -1, if *i1 is less than *i2, 0 if both are equal,
112 * 1 if *i1 is greater than *i2 112 * 1 if *i1 is greater than *i2
113 */ 113 */
114 int cx_cmp_int64(void const *i1, void const *i2); 114 int cx_cmp_int64(const void *i1, const void *i2);
115 115
116 /** 116 /**
117 * Compares two integers of type unsigned int. 117 * Compares two integers of type unsigned int.
118 * 118 *
119 * @param i1 pointer to unsigned integer one 119 * @param i1 pointer to unsigned integer one
120 * @param i2 pointer to unsigned integer two 120 * @param i2 pointer to unsigned integer two
121 * @return -1, if *i1 is less than *i2, 0 if both are equal, 121 * @return -1, if *i1 is less than *i2, 0 if both are equal,
122 * 1 if *i1 is greater than *i2 122 * 1 if *i1 is greater than *i2
123 */ 123 */
124 int cx_cmp_uint(void const *i1, void const *i2); 124 int cx_cmp_uint(const void *i1, const void *i2);
125 125
126 /** 126 /**
127 * Compares two integers of type unsigned long int. 127 * Compares two integers of type unsigned long int.
128 * 128 *
129 * @param i1 pointer to unsigned long integer one 129 * @param i1 pointer to unsigned long integer one
130 * @param i2 pointer to unsigned long integer two 130 * @param i2 pointer to unsigned long integer two
131 * @return -1, if *i1 is less than *i2, 0 if both are equal, 131 * @return -1, if *i1 is less than *i2, 0 if both are equal,
132 * 1 if *i1 is greater than *i2 132 * 1 if *i1 is greater than *i2
133 */ 133 */
134 int cx_cmp_ulongint(void const *i1, void const *i2); 134 int cx_cmp_ulongint(const void *i1, const void *i2);
135 135
136 /** 136 /**
137 * Compares two integers of type unsigned long long. 137 * Compares two integers of type unsigned long long.
138 * 138 *
139 * @param i1 pointer to unsigned long long one 139 * @param i1 pointer to unsigned long long one
140 * @param i2 pointer to unsigned long long two 140 * @param i2 pointer to unsigned long long two
141 * @return -1, if *i1 is less than *i2, 0 if both are equal, 141 * @return -1, if *i1 is less than *i2, 0 if both are equal,
142 * 1 if *i1 is greater than *i2 142 * 1 if *i1 is greater than *i2
143 */ 143 */
144 int cx_cmp_ulonglong(void const *i1, void const *i2); 144 int cx_cmp_ulonglong(const void *i1, const void *i2);
145 145
146 /** 146 /**
147 * Compares two integers of type uint16_t. 147 * Compares two integers of type uint16_t.
148 * 148 *
149 * @param i1 pointer to uint16_t one 149 * @param i1 pointer to uint16_t one
150 * @param i2 pointer to uint16_t two 150 * @param i2 pointer to uint16_t two
151 * @return -1, if *i1 is less than *i2, 0 if both are equal, 151 * @return -1, if *i1 is less than *i2, 0 if both are equal,
152 * 1 if *i1 is greater than *i2 152 * 1 if *i1 is greater than *i2
153 */ 153 */
154 int cx_cmp_uint16(void const *i1, void const *i2); 154 int cx_cmp_uint16(const void *i1, const void *i2);
155 155
156 /** 156 /**
157 * Compares two integers of type uint32_t. 157 * Compares two integers of type uint32_t.
158 * 158 *
159 * @param i1 pointer to uint32_t one 159 * @param i1 pointer to uint32_t one
160 * @param i2 pointer to uint32_t two 160 * @param i2 pointer to uint32_t two
161 * @return -1, if *i1 is less than *i2, 0 if both are equal, 161 * @return -1, if *i1 is less than *i2, 0 if both are equal,
162 * 1 if *i1 is greater than *i2 162 * 1 if *i1 is greater than *i2
163 */ 163 */
164 int cx_cmp_uint32(void const *i1, void const *i2); 164 int cx_cmp_uint32(const void *i1, const void *i2);
165 165
166 /** 166 /**
167 * Compares two integers of type uint64_t. 167 * Compares two integers of type uint64_t.
168 * 168 *
169 * @param i1 pointer to uint64_t one 169 * @param i1 pointer to uint64_t one
170 * @param i2 pointer to uint64_t two 170 * @param i2 pointer to uint64_t two
171 * @return -1, if *i1 is less than *i2, 0 if both are equal, 171 * @return -1, if *i1 is less than *i2, 0 if both are equal,
172 * 1 if *i1 is greater than *i2 172 * 1 if *i1 is greater than *i2
173 */ 173 */
174 int cx_cmp_uint64(void const *i1, void const *i2); 174 int cx_cmp_uint64(const void *i1, const void *i2);
175 175
176 /** 176 /**
177 * Compares two real numbers of type float with precision 1e-6f. 177 * Compares two real numbers of type float with precision 1e-6f.
178 * 178 *
179 * @param f1 pointer to float one 179 * @param f1 pointer to float one
180 * @param f2 pointer to float two 180 * @param f2 pointer to float two
181 * @return -1, if *f1 is less than *f2, 0 if both are equal, 181 * @return -1, if *f1 is less than *f2, 0 if both are equal,
182 * 1 if *f1 is greater than *f2 182 * 1 if *f1 is greater than *f2
183 */ 183 */
184 184
185 int cx_cmp_float(void const *f1, void const *f2); 185 int cx_cmp_float(const void *f1, const void *f2);
186 186
187 /** 187 /**
188 * Compares two real numbers of type double with precision 1e-14. 188 * Compares two real numbers of type double with precision 1e-14.
189 * 189 *
190 * @param d1 pointer to double one 190 * @param d1 pointer to double one
191 * @param d2 pointer to double two 191 * @param d2 pointer to double two
192 * @return -1, if *d1 is less than *d2, 0 if both are equal, 192 * @return -1, if *d1 is less than *d2, 0 if both are equal,
193 * 1 if *d1 is greater than *d2 193 * 1 if *d1 is greater than *d2
194 */ 194 */
195 int cx_cmp_double( 195 int cx_cmp_double(
196 void const *d1, 196 const void *d1,
197 void const *d2 197 const void *d2
198 ); 198 );
199 199
200 /** 200 /**
201 * Compares the integer representation of two pointers. 201 * Compares the integer representation of two pointers.
202 * 202 *
203 * @param ptr1 pointer to pointer one (intptr_t const*) 203 * @param ptr1 pointer to pointer one (const intptr_t*)
204 * @param ptr2 pointer to pointer two (intptr_t const*) 204 * @param ptr2 pointer to pointer two (const intptr_t*)
205 * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal, 205 * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal,
206 * 1 if *ptr1 is greater than *ptr2 206 * 1 if *ptr1 is greater than *ptr2
207 */ 207 */
208 int cx_cmp_intptr( 208 int cx_cmp_intptr(
209 void const *ptr1, 209 const void *ptr1,
210 void const *ptr2 210 const void *ptr2
211 ); 211 );
212 212
213 /** 213 /**
214 * Compares the unsigned integer representation of two pointers. 214 * Compares the unsigned integer representation of two pointers.
215 * 215 *
216 * @param ptr1 pointer to pointer one (uintptr_t const*) 216 * @param ptr1 pointer to pointer one (const uintptr_t*)
217 * @param ptr2 pointer to pointer two (uintptr_t const*) 217 * @param ptr2 pointer to pointer two (const uintptr_t*)
218 * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal, 218 * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal,
219 * 1 if *ptr1 is greater than *ptr2 219 * 1 if *ptr1 is greater than *ptr2
220 */ 220 */
221 int cx_cmp_uintptr( 221 int cx_cmp_uintptr(
222 void const *ptr1, 222 const void *ptr1,
223 void const *ptr2 223 const void *ptr2
224 ); 224 );
225 225
226 /** 226 /**
227 * Compares the pointers specified in the arguments without de-referencing. 227 * Compares the pointers specified in the arguments without de-referencing.
228 * 228 *
230 * @param ptr2 pointer two 230 * @param ptr2 pointer two
231 * @return -1 if ptr1 is less than ptr2, 0 if both are equal, 231 * @return -1 if ptr1 is less than ptr2, 0 if both are equal,
232 * 1 if ptr1 is greater than ptr2 232 * 1 if ptr1 is greater than ptr2
233 */ 233 */
234 int cx_cmp_ptr( 234 int cx_cmp_ptr(
235 void const *ptr1, 235 const void *ptr1,
236 void const *ptr2 236 const void *ptr2
237 ); 237 );
238 238
239 #ifdef __cplusplus 239 #ifdef __cplusplus
240 } // extern "C" 240 } // extern "C"
241 #endif 241 #endif

mercurial