Skip to content

Add a function #46

Description

@profic0de

Add hashmap_ensure() function

A common pattern is:

item = hashmap_get(map, &lookup);
if (!item) {
    hashmap_set(map, &new_item);
    item = hashmap_get(map, &lookup);
}

Could you implement something like:

void *hashmap_ensure(struct hashmap *map, const void *item);

which returns the existing item if present, otherwise inserts it and returns the newly inserted item?

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