@@ -50,7 +50,7 @@ class SparseIntArray:
50
50
root.foreachBinding(op, 0 )
51
51
52
52
/** Transform each defined value with transformation `op`.
53
- * The transformation gets the element index and value as parameters.
53
+ * The transformation takes the element index and value as parameters.
54
54
*/
55
55
def transform (op : (Int , Value ) => Value ): Unit =
56
56
root.transform(op, 0 )
@@ -189,6 +189,9 @@ object SparseIntArray:
189
189
private def skipUndefined (i : Int ): Int =
190
190
if i < NodeSize && elems(i) == null then skipUndefined(i + 1 ) else i
191
191
192
+ // Note: This takes (depth of tree) recursive steps to produce the
193
+ // next index. It could be more efficient if we kept all active iterators
194
+ // in a path.
192
195
def keysIterator (offset : Int ) = new Iterator [Value ]:
193
196
private var curIdx = skipUndefined(0 )
194
197
private var elemIt = Iterator .empty[Int ]
@@ -228,35 +231,3 @@ object SparseIntArray:
228
231
if level == 0 then LeafNode () else InnerNode (level)
229
232
230
233
end SparseIntArray
231
-
232
- @ main def Test =
233
- val a = SparseIntArray ()
234
- println(s " a = $a" )
235
- a(1 ) = 22
236
- println(s " a = $a" )
237
- a(222 ) = 33
238
- println(s " a = $a" )
239
- a(55555 ) = 44
240
- println(s " a = $a" )
241
- println(s " iterator of a yields ${a.keysIterator.toList}" )
242
- assert(a.size == 3 , a)
243
- assert(a.contains(1 ), a)
244
- assert(a.contains(222 ), a)
245
- assert(a.contains(55555 ), a)
246
- assert(! a.contains(2 ))
247
- assert(! a.contains(20000000 ))
248
- a(222 ) = 44
249
- assert(a.size == 3 )
250
- assert(a(1 ) == 22 )
251
- assert(a(222 ) == 44 )
252
- assert(a(55555 ) == 44 )
253
- assert(a.remove(1 ))
254
- println(s " a = $a" )
255
- assert(a(222 ) == 44 , a)
256
- assert(a.remove(55555 ))
257
- assert(a(222 ) == 44 , a)
258
- assert(a.size == 1 )
259
- assert(! a.contains(1 ))
260
- assert(! a.remove(55555 ))
261
- assert(a.remove(222 ))
262
- assert(a.size == 0 )
0 commit comments