Mercurial > projects > dynamin
annotate dynamin/core/list.d @ 83:3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Also, update controls to work with the new API.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Sun, 18 Jul 2010 22:20:50 -0500 |
parents | de94552446ab |
children | 7653269724db |
rev | line source |
---|---|
0 | 1 // Written in the D programming language |
2 // www.digitalmars.com/d/ | |
3 | |
4 /* | |
5 * The contents of this file are subject to the Mozilla Public License Version | |
6 * 1.1 (the "License"); you may not use this file except in compliance with | |
7 * the License. You may obtain a copy of the License at | |
8 * http://www.mozilla.org/MPL/ | |
9 * | |
10 * Software distributed under the License is distributed on an "AS IS" basis, | |
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
12 * for the specific language governing rights and limitations under the | |
13 * License. | |
14 * | |
15 * The Original Code is the Dynamin library. | |
16 * | |
17 * The Initial Developer of the Original Code is Jordan Miner. | |
18 * Portions created by the Initial Developer are Copyright (C) 2006-2009 | |
19 * the Initial Developer. All Rights Reserved. | |
20 * | |
21 * Contributor(s): | |
22 * Jordan Miner <jminer7@gmail.com> | |
23 * | |
24 */ | |
25 | |
26 module dynamin.core.list; | |
27 | |
28 import dynamin.core.global; | |
29 import dynamin.core.string; | |
30 import dynamin.core.math; | |
31 import tango.io.Stdout; | |
32 | |
33 // TODO: QuickSearch() | |
34 // TODO: BinarySearch() | |
35 // MUST use (high + low) >>> 1 to find the average | |
36 // TODO: Search() | |
37 // TODO: QuickSort() | |
38 // TODO: HeapSort() | |
39 // TODO: Sort() - calls HeapSort() so stable sort is default | |
83
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
40 |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
41 /// Represents the ways items can be changed in a list. |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
42 enum ListChangeType { |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
43 /// An item was added to the list. |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
44 Added, |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
45 /// An item was removed from the list. |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
46 Removed, |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
47 /// An item was replaced with another item. |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
48 Replaced |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
49 } |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
50 |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
51 class List(T, bool changeNotification = false) { |
0 | 52 protected: |
53 T[] _data; | |
54 uint _count; | |
83
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
55 static if(changeNotification) |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
56 void delegate(ListChangeType, T, T, uint) whenChanged; |
80
f1e176a76c00
Rearrange List constructors and add a constant for the default capacity.
Jordan Miner <jminer7@gmail.com>
parents:
56
diff
changeset
|
57 const int DefaultCapacity = 16; |
0 | 58 public: |
83
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
59 static if(changeNotification) { |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
60 /// whenChanged is called right after an item is added, removed, or replaced |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
61 this(void delegate(ListChangeType, T, T, uint) whenChanged) { |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
62 this(DefaultCapacity, whenChanged); |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
63 } |
80
f1e176a76c00
Rearrange List constructors and add a constant for the default capacity.
Jordan Miner <jminer7@gmail.com>
parents:
56
diff
changeset
|
64 this(uint capacity, |
83
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
65 void delegate(ListChangeType, T, T, uint) whenChanged) { |
80
f1e176a76c00
Rearrange List constructors and add a constant for the default capacity.
Jordan Miner <jminer7@gmail.com>
parents:
56
diff
changeset
|
66 _data = new T[capacity]; |
83
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
67 this.whenChanged = whenChanged; |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
68 } |
80
f1e176a76c00
Rearrange List constructors and add a constant for the default capacity.
Jordan Miner <jminer7@gmail.com>
parents:
56
diff
changeset
|
69 } else { |
f1e176a76c00
Rearrange List constructors and add a constant for the default capacity.
Jordan Miner <jminer7@gmail.com>
parents:
56
diff
changeset
|
70 this() { |
f1e176a76c00
Rearrange List constructors and add a constant for the default capacity.
Jordan Miner <jminer7@gmail.com>
parents:
56
diff
changeset
|
71 this(DefaultCapacity); |
f1e176a76c00
Rearrange List constructors and add a constant for the default capacity.
Jordan Miner <jminer7@gmail.com>
parents:
56
diff
changeset
|
72 } |
f1e176a76c00
Rearrange List constructors and add a constant for the default capacity.
Jordan Miner <jminer7@gmail.com>
parents:
56
diff
changeset
|
73 this(uint capacity) { |
f1e176a76c00
Rearrange List constructors and add a constant for the default capacity.
Jordan Miner <jminer7@gmail.com>
parents:
56
diff
changeset
|
74 _data = new T[capacity]; |
f1e176a76c00
Rearrange List constructors and add a constant for the default capacity.
Jordan Miner <jminer7@gmail.com>
parents:
56
diff
changeset
|
75 } |
0 | 76 } |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
77 static List!(T) fromArray(T[] arr...) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
78 auto list = new List!(T)(); |
0 | 79 list._data = arr.dup; |
80 list._count = arr.length; | |
81 return list; | |
82 } | |
83 uint count() { | |
84 return _count; | |
85 } | |
86 uint capacity() { | |
87 return _data.length; | |
88 } | |
89 T[] toArray() { | |
90 return _data[0.._count].dup; | |
91 } | |
92 T[] data() { | |
93 return _data[0.._count]; | |
94 } | |
95 /*string toString() { | |
96 string str = "["; | |
97 if(Count > 0) | |
98 str ~= ToString(this[0]); | |
99 foreach(item; this) { | |
100 str ~= ", "; | |
101 str ~= ToString(item); | |
102 } | |
103 str ~= "]"; | |
104 return str; | |
105 }*/ | |
106 protected void maybeEnlarge(uint neededCap) { | |
107 if(neededCap <= capacity) | |
108 return; | |
109 _data.length = max(neededCap, (capacity+1)*2); | |
110 } | |
111 T opIndex(uint index) { | |
112 return _data[0.._count][index]; | |
113 } | |
83
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
114 void opIndexAssign(T item, uint index) { |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
115 T oldItem = _data[0.._count][index]; |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
116 _data[0.._count][index] = item; |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
117 static if(changeNotification) |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
118 whenChanged(ListChangeType.Replaced, oldItem, item, index); |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
119 } |
0 | 120 void push(T item) { |
121 add(item); | |
122 } | |
123 T pop() { | |
124 if(_count < 1) | |
56
c2566ab82535
Edit comments and fix a typo.
Jordan Miner <jminer7@gmail.com>
parents:
55
diff
changeset
|
125 throw new Exception("List.pop() - List is empty"); |
0 | 126 T item = _data[_count-1]; |
127 // must null out to allow to be collected | |
128 static if(is(T == class) || is(T == interface)) | |
129 _data[_count-1] = cast(T)null; | |
130 --_count; | |
83
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
131 static if(changeNotification) |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
132 whenChanged(ListChangeType.Removed, item, T.init, _count); |
0 | 133 return item; |
134 } | |
135 void add(T item) { | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
136 insert(item, _count); |
0 | 137 } |
138 void remove(T item) { | |
139 uint i = find(item); | |
140 if(i == -1) | |
141 return; | |
81
de94552446ab
Add List.removeAt() and tests for it.
Jordan Miner <jminer7@gmail.com>
parents:
80
diff
changeset
|
142 removeAt(i); |
de94552446ab
Add List.removeAt() and tests for it.
Jordan Miner <jminer7@gmail.com>
parents:
80
diff
changeset
|
143 } |
de94552446ab
Add List.removeAt() and tests for it.
Jordan Miner <jminer7@gmail.com>
parents:
80
diff
changeset
|
144 void removeAt(uint index) { |
de94552446ab
Add List.removeAt() and tests for it.
Jordan Miner <jminer7@gmail.com>
parents:
80
diff
changeset
|
145 T item = _data[index]; |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
146 |
81
de94552446ab
Add List.removeAt() and tests for it.
Jordan Miner <jminer7@gmail.com>
parents:
80
diff
changeset
|
147 for(uint i = index + 1; i < _count; ++i) |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
148 _data[i-1] = _data[i]; |
0 | 149 // must null out to allow to be collected |
150 static if(is(T == class) || is(T == interface)) | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
151 _data[_count-1] = cast(T)null; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
152 --_count; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
153 |
83
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
154 static if(changeNotification) |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
155 whenChanged(ListChangeType.Removed, item, T.init, index); |
0 | 156 } |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
157 void insert(T item, uint index) { |
0 | 158 maybeEnlarge(_count+1); |
159 arrayCopy!(T)(_data, index, _data, index+1, _count - index); | |
160 _data[index] = item; | |
161 ++_count; | |
83
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
162 static if(changeNotification) |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
163 whenChanged(ListChangeType.Added, T.init, item, index); |
0 | 164 } |
165 void clear() { | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
166 for(; _count > 0; --_count) { |
83
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
167 static if(changeNotification) |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
168 whenChanged(ListChangeType.Removed, _data[_count-1], T.init, _count-1); |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
169 // must null out to allow to be collected |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
170 static if(is(T == class) || is(T == interface)) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
171 data[_count-1] = cast(T)null; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
172 } |
0 | 173 } |
174 uint find(T item) { | |
175 foreach(i, item2; _data) | |
176 if(item == item2) // if(item2 == item) would crash on a null item | |
177 return i; | |
178 return -1; | |
179 } | |
180 //trimCapacity() | |
181 //opIndex | |
182 //opIndexAssign | |
183 //opConcat | |
184 //opEquals | |
185 //opSlice | |
186 //opSliceAssign | |
187 int opApply(int delegate(inout T item) dg) { | |
188 for(uint i = 0; i < _count; ++i) { | |
189 if(int result = dg(_data[i])) | |
190 return result; | |
191 } | |
192 return 0; | |
193 } | |
194 //so you can do: | |
195 //foreach(i, item; list) | |
196 int opApply(int delegate(inout uint index, inout T item) dg) { | |
197 for(uint i = 0; i < _count; ++i) { | |
198 if(int result = dg(i, _data[i])) | |
199 return result; | |
200 } | |
201 return 0; | |
202 } | |
203 | |
204 } | |
205 unittest { | |
206 auto list = List!(char).fromArray("Hello, Mat"); | |
207 list.add('t'); | |
208 assert(list.data == "Hello, Matt"); | |
209 assert(list.pop() == 't'); | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
210 assert(list.data == "Hello, Mat"); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
211 list.insert('!', 5); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
212 assert(list.data == "Hello!, Mat"); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
213 list.remove('l'); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
214 assert(list.data == "Helo!, Mat"); |
81
de94552446ab
Add List.removeAt() and tests for it.
Jordan Miner <jminer7@gmail.com>
parents:
80
diff
changeset
|
215 list.removeAt(0); |
de94552446ab
Add List.removeAt() and tests for it.
Jordan Miner <jminer7@gmail.com>
parents:
80
diff
changeset
|
216 assert(list.data == "elo!, Mat"); |
de94552446ab
Add List.removeAt() and tests for it.
Jordan Miner <jminer7@gmail.com>
parents:
80
diff
changeset
|
217 list.removeAt(8); |
de94552446ab
Add List.removeAt() and tests for it.
Jordan Miner <jminer7@gmail.com>
parents:
80
diff
changeset
|
218 assert(list.data == "elo!, Ma"); |
de94552446ab
Add List.removeAt() and tests for it.
Jordan Miner <jminer7@gmail.com>
parents:
80
diff
changeset
|
219 list.removeAt(1); |
de94552446ab
Add List.removeAt() and tests for it.
Jordan Miner <jminer7@gmail.com>
parents:
80
diff
changeset
|
220 assert(list.data == "eo!, Ma"); |
0 | 221 list.clear(); |
222 assert(list.data == ""); | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
223 |
83
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
224 int a = 0, r = 0, r2 = 0; |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
225 void changed(ListChangeType t, string o, string n, uint) { |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
226 if(t == ListChangeType.Added) { |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
227 a++; |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
228 assert(o == "" && n != ""); |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
229 } |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
230 if(t == ListChangeType.Removed) { |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
231 r++; |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
232 assert(n == "" && o != ""); |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
233 } |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
234 if(t == ListChangeType.Replaced) { |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
235 r2++; |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
236 } |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
237 }; |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
238 auto list2 = new List!(string, true)(&changed); |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
239 assert(a == 0 && r == 0 && r2 == 0); |
0 | 240 list2.add("hello"); |
83
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
241 assert(a == 1 && r == 0 && r2 == 0); |
0 | 242 assert(list2.pop() == "hello"); |
83
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
243 assert(a == 1 && r == 1 && r2 == 0); |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
244 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
245 list2.add("Hi"); |
83
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
246 list2.add("Jacob"); |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
247 assert(a == 3 && r == 1 && r2 == 0); |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
248 list2[1] = "Matt"; |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
249 assert(a == 3 && r == 1 && r2 == 1); |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
250 list2.insert("John", 1); |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
251 list2.insert("Pete", 3); |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
252 assert(list2.data == ["Hi", "John", "Matt", "Pete"]); |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
253 assert(a == 5 && r == 1 && r2 == 1); |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
254 list2.removeAt(0); |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
255 assert(list2.data == ["John", "Matt", "Pete"]); |
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
256 assert(a == 5 && r == 2 && r2 == 1); |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
257 list2.clear(); |
83
3cfc83a99cbc
Add List.opIndexAssign and switch to one callback for change notification.
Jordan Miner <jminer7@gmail.com>
parents:
81
diff
changeset
|
258 assert(a == 5 && r == 5 && r2 == 1); |
0 | 259 } |
260 |