This repository was archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathlinked_list.js
193 lines (168 loc) · 5.32 KB
/
linked_list.js
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
export class _LinkedListItem {
static _initialize(item) {
// TODO: Traceur assertions
// assert(typeof item._previous === "undefined");
// assert(typeof item._next === "undefined");
item._next = item._previous = null;
}
}
export class _LinkedList {
static _initialize(list) {
// TODO: Traceur assertions
// assert(typeof list._head === "undefined");
// assert(typeof list._tail === "undefined");
list._tail = list._head = null;
}
static _add(list, item) {
// TODO: Traceur assertions
// assert(item._next === null);
// assert(item._previous === null);
if (list._tail === null) {
list._head = list._tail = item;
} else {
item._previous = list._tail;
list._tail._next = item;
list._tail = item;
}
return item;
}
static _isEmpty(list) {
return list._head === null;
}
static _remove(list, item) {
var previous = item._previous;
var next = item._next;
if (previous === null) list._head = next;
else previous._next = next;
if (next === null) list._tail = previous;
else next._previous = previous;
}
}
export class _WatchList {
static _initialize(list) {
// TODO: Traceur assertions
// assert(typeof list._watchHead === "undefined");
// assert(typeof list._watchTail === "undefined");
list._watchHead = list._watchTail = null;
}
static _add(list, item) {
// TODO: Traceur assertions
// assert(item._nextWatch === null);
// assert(item._previousWatch === null);
if (list._watchTail === null) {
list._watchHead = list._watchTail = item;
} else {
item._previousWatch = list._watchTail;
list._watchTail._nextWatch = item;
list._watchTail = item;
}
return item;
}
static _isEmpty(list) {
return list._watchHead === null;
}
static _remove(list, item) {
var previous = item._previousWatch;
var next = item._nextWatch;
if (previous === null) list._watchHead = next;
else previous._nextWatch = next;
if (next === null) list._watchTail = previous;
else next._previousWatch = previous;
}
}
export class _WatchGroupList {
static _add(list, item) {
// TODO(caitp): Traceur assertions
// assert(item._nextWatchGroup === null);
// assert(item._prevWatchGroup === null);
if (list._watchGroupTail === null) {
list._watchGroupHead = list._watchGroupTail = item;
} else {
item._prevWatchGroup = list._watchGroupTail;
list._watchGroupTail._nextWatchGroup = item;
list._watchGroupTail = item;
}
return item;
}
static _isEmpty(list) {
return list._watchGroupHead === null;
}
static _remove(list, item) {
var previous = item._prevWatchGroup;
var next = item._nextWatchGroup;
if (previous === null) list._watchGroupHead = next;
else previous._nextWatchGroup = next;
if (next === null) list._watchGroupTail = previous;
else next._prevWatchGroup = previous;
}
}
export class _ArgHandlerList {
static _initialize(list) {
list._argHandlerHead = list._argHandlerTail = null;
}
static _add(list, item) {
// TODO: Traceur assertions
// assert(item._nextArgHandler === null);
// assert(item._previousArgHandler === null);
if (list._argHandlerTail === null) {
list._argHandlerHead = list._argHandlerTail = item;
} else {
item._previousArgHandler = list._argHandlerTail;
list._argHandlerTail._nextArgHandler = item;
list._argHandlerTail = item;
}
return item;
}
static _isEmpty(list) {
return list._argHandlerHead === null;
}
static _remove(list, item) {
var previous = item._previousArgHandler;
var next = item._nextArgHandler;
if (previous === null) list._argHandlerHead = next;
else previous._nextArgHandler = next;
if (next === null) list._argHandlerTail = previous;
else next._previousArgHandler = previous;
}
}
export class _EvalWatchList {
static _add(list, item) {
// TODO: Traceur assertions
// assert(item._nextEvalWatch === null);
// assert(item._prevEvalWatch === null);
var prev = list._evalWatchTail;
var next = prev._nextEvalWatch;
if (prev === list._marker) {
list._evalWatchHead = list._evalWatchTail = item;
prev = prev._prevEvalWatch;
list._marker._prevEvalWatch = null;
list._marker._nextEvalWatch = null;
}
item._nextEvalWatch = next;
item._prevEvalWatch = prev;
if (prev !== null) prev._nextEvalWatch = item;
if (next !== null) next._prevEvalWatch = item;
return (list._evalWatchTail = item);
}
static _isEmpty(list) {
return list._evalWatchHead === null;
}
static _remove(list, item) {
// TODO: Traceur assertions
// assert(item.watchGrp === list);
var prev = item._prevEvalWatch;
var next = item._nextEvalWatch;
if (list._evalWatchHead === list._evalWatchTail) {
list._evalWatchHead = list._evalWatchTail = list._marker;
list._marker._nextEvalWatch = next;
list._marker._prevEvalWatch = prev;
if (prev !== null) prev._nextEvalWatch = list._marker;
if (next !== null) next._prevEvalWatch = list._marker;
} else {
if (item === list._evalWatchHead) list._evalWatchHead = next;
if (item === list._evalWatchTail) list._evalWatchTail = prev;
if (prev !== null) prev._nextEvalWatch = next;
if (next !== null) next._prevEvalWatch = prev;
}
}
}