Skip to content

zhashx table growth implementation doesn't match description? #2332

Description

@Loinsrch

The hash table size is increased slightly (up to 5 times before roughly doubling the size) when an overly long chain (between 1 and 63 items depending on table size) is detected.

linked list. The hash table size is increased slightly (up to 5 times

If I understand the code correctly, in order to get these "slight" table size increases, the prime_index should only be increased by one in this case:

uint new_prime_index = self->prime_index + GROWTH_FACTOR;

Increasing the prime index by GROWTH_FACTOR effectively always doubles the size.

Whether the described "slight increase" behavior would be desirable or not is another question. I guess the intent is to attempt to "rebalance" the table for a more uniform hash distribution, but rehashing is an expensive operation at scale. Ultimately, though, the current implementation doesn't seem to match the design intent per the description and the prime table design itself (if the prime index always grows by 5, most of the entries in the table will never be used).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    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