Idea for a possible Nob_HashMap
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
- Domain
- build-system, tooling
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
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tsoding/nob.h
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
nob__walk_dir_opt_impl() tries to close zeroed handle for non directory entriesPossibly taken @whophi claimed this 66 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
nob_get_file_type error check is dead code: nob_copy_directory_recursively aborts and nob_walk_dir returns true on unreadable pathsPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 1/5 Under an hour Newbie friendliness 76/100
Similar issues
-
new contributor
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
OpenMS/OpenMS#10512 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
mesonbuild/wrapdb#2961 ·
Maintainers usually reply within 1 day
-
80 Instance - Raid - Northrend
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
azerothcore/azerothcore-wotlk#28075 ·
Maintainers usually reply within 1 day
-
SCA cis_ubuntu24-04 35664 / cis_ubuntu26-04 41664 "Ensure sudo log file exists": sudoers.d rule is missing the r: prefix, so it can never matchPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MrNeRF/LichtFeld-Studio#3205 ·
Maintainers usually reply within 1 day