forked from huangqundl/SketchLearn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.c
More file actions
55 lines (42 loc) · 1.14 KB
/
util.c
File metadata and controls
55 lines (42 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "util.h"
#include "tuple.h"
int cmp_lf (const void * a, const void * b) {
return (*(double*)a) < (*(double*)b);
}
int cmp_ll (const void * a, const void * b) {
return (*(long long*)a) < (*(long long*)b);
}
int cmp_int32 (const void * a, const void * b) {
return (*(int32_t*)a) < (*(int32_t*)b);
}
int cmp (const void * a, const void * b) {
tuple_t* t1 = (tuple_t*)a;
tuple_t* t2 = (tuple_t*)b;
if (t1->size != t2->size) {
return t1->size < t2->size;
}
if (t1->key.src_ip != t2->key.src_ip) {
return t1->key.src_ip < t2->key.src_ip;
}
if (t1->key.dst_ip != t2->key.dst_ip) {
return t1->key.dst_ip < t2->key.dst_ip;
}
if (t1->key.src_port != t2->key.src_port) {
return t1->key.src_port < t2->key.src_port;
}
if (t1->key.dst_port != t2->key.dst_port) {
return t1->key.dst_port < t2->key.dst_port;
}
return t1->key.proto < t2->key.proto;
}
void quitmemory(void * pointer)
// quit if a memory allocation failed
{
if (pointer==NULL) exit(1);
}
long long ll_abs(long long a) {
if (a < 0) {
return -a;
}
return a;
}