Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Idea for a possible Nob_HashMap

Open
#138 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
c

Research direction

No file or test is named. Start by inspecting nob's dynamic-array implementation and the repository's current data-structure conventions; clarify the hash-map API and collision strategy before coding. Done would require an agreed design and implementation scope, with behavior for setting, getting, growth, and collisions defined.

Written by the indexing model from the issue text.

Description

Writing this issue because I have been thinking that it would be nice if nob had a hash map implementation in a similar fashion as to how dynamic arrays are implemented.
Something that came to my mind was to do a definition of the Hash map like this:

typedef struct {
    Nob_Hash_Index *indexes;
    Type *items;
    size_t count;
    size_t capacity;
} My_Hash;

Where we add the indexes field on the structure to indicate that this is a hash map.
Than add macros in the form of nob_hash_set and nob_hash_get to add a new value and get a value from the hash map.

But, here comes the problem I have wanted to discuss, the strategy to manage collisions. For what I have been thinking, I would like to implement the indexes array by chaining the colliding addresses with a linked list, and so defining the Nob_Hash_Index like this:

typedef struct index_type {
    size_t value; // Place holder name
    struct index_type *next_index;
} Nob_Hash_Index;

I think this is a good way to manage it because we don't really need to think about changing the size of the indexes array in case the hash map is growing and potentially we could even think of the indexes array statically, and having this definition:

typedef struct {
    Type *items;
    size_t count;
    size_t capacity;
    Nob_Hash_Index indexes[MY_HASH_SIZE];
} My_Hash;
Dominant language
C++
Stars
3.3k
Forks
215
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tsoding/nob.h

All issues in tsoding/nob.h

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.