Sitelet https://github.com/xacrimon/dashmap/issues/311
Skip to content

capacity behavior does not align with its documentation #311

Description

@zacknewman

Either there is a bug in code, or the documentation needs to be changed for capacity. The documentation states (emphasis added):

Returns how many key-value pairs the map can store without reallocating.

The following code illustrates a reallocation occurs before inserting more than capacity key-value pairs.

use dashmap::DashMap;
fn main() {
    let map = DashMap::with_capacity(192);
    let cap = map.capacity();
    for i in 0..cap {
        map.insert(i, ());
    }
    assert_eq!(cap, map.len());
    assert_ne!(cap, map.capacity());
}
[zack@laptop src]$ uname -a
Linux laptop 6.10.10-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 12 Sep 2024 17:21:02 +0000 x86_64 GNU/Linux
[zack@laptop src]$ cargo -V
cargo 1.81.0 (2dbb1af80 2024-08-20)

Unsurprisingly, the same problem exists for DashSet.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions