Skip to content

HashMap has no way to avoid key copy or double hash for insertion #35463

@nagisa

Description

@nagisa

Currently all HashMap APIs which make insertion into a map possible (insert, entry) require the key by-value. If avoiding a clone is desired, the user must instead use something like if !map.contains(key) { map.insert(key.clone(), val); }, which results in key getting hashed twice.

Ideally, something like HashMap::insert_clone(key: &K, val: V) where K: Clone or HashMap::entry_clone(key: &K) where K: Clone would exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions