-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist.c
94 lines (84 loc) · 1.32 KB
/
list.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "comm.h"
struct buf_entry
{
struct buf_entry *next;
uint64_t data;
};
static struct buf_entry *head;
static struct buf_entry all_entry[MAX_TEST_NUM];
void find_entry(uint64_t entry)
{
struct buf_entry *t = head;
while (t)
{
if (t->data == entry)
return;
t = t->next;
}
assert(0);
}
void delete_entry(uint64_t entry)
{
struct buf_entry *pre = NULL;
struct buf_entry *t = head;
while (t)
{
if (t->data == entry)
{
if (pre)
{
pre->next = t->next;
}
else
{
head = t->next;
}
return;
}
pre = t;
t = t->next;
}
assert(0);
}
void find(uint64_t *data, int num)
{
for (int i = 0; i < num; ++i)
{
find_entry(data[i]);
}
}
void delete(uint64_t *data, int num)
{
for (int i = 0; i < num; ++i)
{
delete_entry(data[i]);
}
}
void insert(uint64_t *data, int num)
{
for (int i = 0; i < num; ++i)
{
all_entry[i].data = data[i];
all_entry[i].next = head;
head = &all_entry[i];
}
}
int main(int argc, char *argv[])
{
int num = atoi(argv[1]);
uint64_t *data = read_test_num(num);
assert(data);
uint64_t *data_r = read_rand_num(num);
assert(data_r);
time_begin();
insert(data, num);
find(data_r, num);
delete(data_r, num);
int diff = time_diff();
printf("[%d] ", diff);
return 0;
}