ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change
on this file since 3895b8b5 was
87c5f40,
checked in by Aaron Moss <a3moss@…>, 7 years ago
|
Update benchmarks to include stack of pairs
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | #include <stdlib> |
---|
2 | #include "cfa-stack.h" |
---|
3 | |
---|
4 | forall(otype T) struct stack_node { |
---|
5 | T value; |
---|
6 | stack_node(T)* next; |
---|
7 | }; |
---|
8 | |
---|
9 | forall(otype T) void ?{}(stack(T)* s) { |
---|
10 | (&s->head){ 0 }; |
---|
11 | } |
---|
12 | |
---|
13 | forall(otype T) void copy(stack(T)* s, stack(T)* t) { |
---|
14 | stack_node(T)** crnt = &s->head; |
---|
15 | stack_node(T)* next = t->head; |
---|
16 | while ( next ) { |
---|
17 | *crnt = ((stack_node(T)*)malloc()){ next->value }; |
---|
18 | stack_node(T)* acrnt = *crnt; |
---|
19 | crnt = &acrnt->next; |
---|
20 | next = next->next; |
---|
21 | } |
---|
22 | *crnt = 0; |
---|
23 | } |
---|
24 | |
---|
25 | forall(otype T) void ?{}(stack(T)* s, stack(T) t) { |
---|
26 | stack_node(T)** crnt = &s->head; |
---|
27 | stack_node(T)* next = t.head; |
---|
28 | while ( next ) { |
---|
29 | *crnt = ((stack_node(T)*)malloc()){ next->value }; |
---|
30 | stack_node(T)* acrnt = *crnt; |
---|
31 | crnt = &acrnt->next; |
---|
32 | next = next->next; |
---|
33 | } |
---|
34 | *crnt = 0; |
---|
35 | } |
---|
36 | |
---|
37 | forall(otype T) stack(T) ?=?(stack(T)* s, stack(T) t) { |
---|
38 | if ( s->head == t.head ) return *s; |
---|
39 | clear(s); |
---|
40 | s{ t }; |
---|
41 | return *s; |
---|
42 | } |
---|
43 | |
---|
44 | forall(otype T) void ^?{}(stack(T)* s) { |
---|
45 | clear(s); |
---|
46 | } |
---|
47 | |
---|
48 | forall(otype T) _Bool empty(const stack(T)* s) { |
---|
49 | return s->head == 0; |
---|
50 | } |
---|
51 | |
---|
52 | forall(otype T) void push(stack(T)* s, T value) { |
---|
53 | s->head = ((stack_node(T)*)malloc()){ value, s->head }; |
---|
54 | } |
---|
55 | |
---|
56 | forall(otype T) T pop(stack(T)* s) { |
---|
57 | stack_node(T)* n = s->head; |
---|
58 | s->head = n->next; |
---|
59 | T x = n->value; |
---|
60 | ^n{}; |
---|
61 | free(n); |
---|
62 | return x; |
---|
63 | } |
---|
64 | |
---|
65 | forall(otype T) void clear(stack(T)* s) { |
---|
66 | stack_node(T)* next = s->head; |
---|
67 | while ( next ) { |
---|
68 | stack_node(T)* crnt = next; |
---|
69 | next = crnt->next; |
---|
70 | delete(crnt); |
---|
71 | } |
---|
72 | s->head = 0; |
---|
73 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.