-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_list.cc
84 lines (64 loc) · 1.67 KB
/
test_list.cc
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
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <unistd.h>
#include <lace/singleton.h>
#include <lace/random.h>
#include "queue.h"
#include "list.h"
struct node {
int value;
node(int v) : value(v) { }
lite::queue_link<node> queue_link;
lite::list_link<node> list_link;
bool
bound() const {
return false
|| queue_link.bound()
|| list_link.bound()
;;
}
void kill() { if (!bound()) delete this; }
typedef lite::queue<node, &node::queue_link> queue_t;
typedef lite::list<node, &node::list_link> list_t;
typedef queue_t::sorter<typeof(value), &node::value> sorter_t;
};
int
main(int, char*[]) {
lace::random & rng = lace::singleton<lace::random>::instance();
node::queue_t queue;
node::list_t list;
static const unsigned n = 16;
for (unsigned i = 0 ; i < n ; ++i) {
node* x = new node(rng.l() % n);
list.enlist(x);
queue.enqueue(x);
}
{{
node* t = new node(n);
for (node * n = list.last() ; n ; n = list.previous(n))
list.enlist(t, n).delist(t);
std::cout << "ring" << '\t';
for (node * n = list.enlist(t).first() ; n != t ; n = list.prograde()) {
assert(n == list.first());
std::cout << ' ' << n->value;
}
std::cout << std::endl;
list.delist(t)->kill();
}}
node::sorter_t::sort(queue);
std::cout << "list" << '\t';
for (node * n = list.first() ; n ; n = list.next(n))
std::cout << ' ' << n->value;
std::cout << std::endl;
std::cout << "queue" << '\t';
while (!queue.empty()) {
node* x = queue.dequeue();
std::cout << ' ' << x->value;
list.delist(x);
x->kill();
}
std::cout << std::endl;
return EXIT_SUCCESS;
}
//