Skip to content

Champ (Map/Set) Iterators should expose their knownSize  #11606

Open
@joshlemer

Description

@joshlemer

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 next() have occurred, and decrement a counter. Or if that is too inconvenient (since there are many overrides of next() for each variant of the Iterator), then perhaps atleast return rootNode.size in the case where the Iterator is still in starting position.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions