-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeList.js
More file actions
99 lines (96 loc) · 1.96 KB
/
NodeList.js
File metadata and controls
99 lines (96 loc) · 1.96 KB
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
define([], function(){
"use strict";
function NodeList(){
this.first = null;
this.last = null;
};
NodeList.prototype.add = function( _node ){
if( null == this.first ){
this.first = _node;
this.last = _node;
_node.next = null;
_node.previous = null;
}
else{
this.last.next = _node;
_node.previous = this.last;
_node.next = null;
this.last = _node;
}
}
NodeList.prototype.addSorted = function( _node ){
if( null == this.first ){
this.first = _node;
this.last = _node;
_node.next = null;
_node.previous = null;
}
else{
var n = this.last;
while(n != null){
if(n.pIndex <= _node.pIndex){
break;
}
n = n.previous;
}
if(n == this.last){
//console.log("n == this.last");
this.last.next = _node;
_node.previous = this.last;
_node.next = null;
this.last = _node;
}
else if(null == n){
//console.log("null == n");
_node.next = this.first;
_node.previous = null;
this.first.previous = _node;
this.first = _node;
}
else{
//console.log();
_node.next = n.next;
_node.previous = n;
n.next.previous = _node;
n.next = _node;
}
}
}
NodeList.prototype.addFirst = function( _node ){
if( null == this.first ){
this.first = _node;
this.last = _node;
_node.next = null;
_node.previous = null;
}
else{
_node.next = this.first;
this.first.previous = _node;
this.first = _node;
}
}
NodeList.prototype.remove = function( _node ){
if( this.first == _node ){
this.first = this.first.next;
}
if( this.last == _node){
this.last = this.last.previous;
}
if( _node.previous != null ){
_node.previous.next = _node.next;
}
if( _node.next != null ){
_node.next.previous = _node.previous;
}
}
NodeList.prototype.clear = function(){
while( null != this.first ){
var node = this.first;
this.first = node.next;
node.previous = null;
node.next = null;
}
this.last = null;
}
return NodeList;
});