Skip to content

Review and improve HashMap's handling of an empty table #53853

Closed

Description

@RalfJung

In #53804, I fixed the most immediate problem arising from how HashMap handles the empty table, but @gnzlbg still (rightly) sees more problems. We still use 1 instead of NonNull::dangling() as value for EMPTY, and ptr() even tests equality with EMPTY to return NULL instead. We can't really use non-NULL pointers as sentinel values like that, and NULL is often a worse choice than an aligned dangling pointer because the latter are at least valid for zero-sized operations.

See here for @gnzlbg's suggestions.

Activity

  1. added
    A-collectionsArea: `std::collections` (prefer A-binaryheap, A-btree, A-hashtable, A-linkedlist, A-vecdeque)
    T-libs-api[DEPRECATED; DO NOT USE]
    on Jan 27, 2019
  2. Mark-Simulacrum commented on Dec 23, 2019

    @Mark-Simulacrum
    Member

    I'm going to close this issue since our hash maps are now a thin wrapper around hashbrown which hopefully doesn't suffer from these issues; if it does, this should be refiled upstream. A cursory examination didn't find any obvious problems for sentinel use of dangling or so.

  3. gnzlbg commented on Dec 24, 2019

    @gnzlbg
    Contributor

    Yes none of this applies to the new hashbrown impl. cc @Amanieu in case they want to re-read the comments and any of that rings a bell, but I haven't see anything like that in hashbrown.

  4. Amanieu commented on Dec 24, 2019

    @Amanieu
    Member

    I agree, I don't think any of this applies to hashbrown.

  5. added
    A-hashtableArea: `std::collections::{HashMap, HashSet}`
    and removed
    A-collectionsArea: `std::collections` (prefer A-binaryheap, A-btree, A-hashtable, A-linkedlist, A-vecdeque)
    on Nov 2, 2026
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

    A-hashtableArea: `std::collections::{HashMap, HashSet}`T-libs-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions