@@ -50,7 +50,7 @@ class SparseIntArray:
5050 root.foreachBinding(op, 0 )
5151
5252 /** 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.
5454 */
5555 def transform (op : (Int , Value ) => Value ): Unit =
5656 root.transform(op, 0 )
@@ -189,6 +189,9 @@ object SparseIntArray:
189189 private def skipUndefined (i : Int ): Int =
190190 if i < NodeSize && elems(i) == null then skipUndefined(i + 1 ) else i
191191
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.
192195 def keysIterator (offset : Int ) = new Iterator [Value ]:
193196 private var curIdx = skipUndefined(0 )
194197 private var elemIt = Iterator .empty[Int ]
@@ -228,35 +231,3 @@ object SparseIntArray:
228231 if level == 0 then LeafNode () else InnerNode (level)
229232
230233end 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