Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Champ (Map/Set) Iterators should expose their knownSize #11606
All iterators over the CHAMP Maps/Sets currently expose a knownSize of -1. Since Maps/Sets cache their size, it should at the very least be possible to track how many calls to
scala> import collection.immutable._ import collection.immutable._ scala> HashMap(1 -> 1, 2 -> 2).iterator.knownSize res1: Int = -1 scala> HashSet(1,2).iterator.knownSize res2: Int = -1
@NthPortal I'm just thinking that in the vast majority of cases, knownSize is called on a fresh iterator in order to preallocate or short circuit, and then never called again, so if it's too costly to maintain a count throughout the iteration, we'll still get almost all the benefits by knowing the size at the start.