Mercurial > projects > dynamin
comparison dynamin/core/list.d @ 56:c2566ab82535
Edit comments and fix a typo.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Sat, 08 Aug 2009 15:46:39 -0500 |
parents | c138461bf845 |
children | f1e176a76c00 |
comparison
equal
deleted
inserted
replaced
55:c138461bf845 | 56:c2566ab82535 |
---|---|
106 void push(T item) { | 106 void push(T item) { |
107 add(item); | 107 add(item); |
108 } | 108 } |
109 T pop() { | 109 T pop() { |
110 if(_count < 1) | 110 if(_count < 1) |
111 throw new Exception("List.Pop() - List is empty"); | 111 throw new Exception("List.pop() - List is empty"); |
112 T item = _data[_count-1]; | 112 T item = _data[_count-1]; |
113 // must null out to allow to be collected | 113 // must null out to allow to be collected |
114 static if(is(T == class) || is(T == interface)) | 114 static if(is(T == class) || is(T == interface)) |
115 _data[_count-1] = cast(T)null; | 115 _data[_count-1] = cast(T)null; |
116 --_count; | 116 --_count; |
119 return item; | 119 return item; |
120 } | 120 } |
121 void add(T item) { | 121 void add(T item) { |
122 insert(item, _count); | 122 insert(item, _count); |
123 } | 123 } |
124 // TODO: AddRange? | |
125 void remove(T item) { | 124 void remove(T item) { |
126 uint i = find(item); | 125 uint i = find(item); |
127 if(i == -1) | 126 if(i == -1) |
128 return; | 127 return; |
129 | 128 |
143 _data[index] = item; | 142 _data[index] = item; |
144 ++_count; | 143 ++_count; |
145 static if(hasDelegates) | 144 static if(hasDelegates) |
146 whenAdded(item, index); | 145 whenAdded(item, index); |
147 } | 146 } |
148 // TODO: InsertRange? | |
149 void clear() { | 147 void clear() { |
150 for(; _count > 0; --_count) { | 148 for(; _count > 0; --_count) { |
151 static if(hasDelegates) | 149 static if(hasDelegates) |
152 whenRemoved(_data[_count-1], _count-1); | 150 whenRemoved(_data[_count-1], _count-1); |
153 // must null out to allow to be collected | 151 // must null out to allow to be collected |