I'm currently working with Rust's HashSet
and I'm trying to understand the computational complexity of the HashSet::len
operation.
The Rust documentation provides information about the computational complexity of get
and insert
operations for HashMap
being O(1) on average, but it doesn't explicitly mention the complexity for HashSet
or the len
operation.
In general, the len operation for many data structures is O(1), but I couldn't find a specific statement confirming this for HashSet::len
in Rust.
Here's the link to the relevant Rust documentation: Rust Collections
Could anyone clarify the computational complexity of HashSet::len
? Is it O(1) as I would expect, or is there a different complexity associated with this operation in Rust's HashSet
?
len()
implementation with a runtime complexity of more than O(1). I can't find a statement to that end in the documentation, but it's the only thing that makes sense. – Softshoe.len()
is O(1) for all standard lib collections: github.com/rust-lang/api-guidelines/discussions/149 – SoftshoeHashSet
operations, the docs you linked state that: "For Sets, all operations have the cost of the equivalent Map operation." But you're right that the complexity oflen
is undocumented. – Berniecebernier