-
Notifications
You must be signed in to change notification settings - Fork 0
/
record.c
51 lines (34 loc) · 802 Bytes
/
record.c
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
#include <stdlib.h>
#include "./record.h"
NAT_Record* NAT_createRecord(int value) {
NAT_Record *r = malloc(sizeof(*r));
static int record_count = 0;
r->id = record_count;
record_count++;
r->value = value;
return r;
}
void NAT_freeRecord(NAT_Record *r) {
if (r == NULL) {
return;
}
free(r);
}
int NAT_recordsCompare1(NAT_Record *r1, NAT_Record *r2) {
if ((r1 == NULL) && (r2 == NULL)) {
return 0;
} else if (r1 == NULL) {
return -1;
} else if (r2 == NULL) {
return 1;
}
int value_diff = r1->value - r2->value;
int id_diff = r1->id - r2->id;
if (value_diff != 0) {
return id_diff;
} else if (id_diff != 0) {
return id_diff;
} else {
return 0;
}
}