-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ (delete): Added a hashmap delete function
- Loading branch information
Showing
17 changed files
with
250 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ on: | |
push: | ||
|
||
jobs: | ||
tests: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,4 +53,5 @@ dkms.conf | |
|
||
build | ||
.direnv | ||
result | ||
result | ||
/debug.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,36 @@ | ||
#include "entry.h" | ||
#include "hash.h" | ||
|
||
#include <string.h> | ||
|
||
static th_entry_t *th_entry_new(th_key_t *key, th_any_t value) | ||
{ | ||
th_entry_t *entry = malloc(sizeof(th_entry_t)); | ||
|
||
if (entry == NULL) return NULL; | ||
|
||
entry->key = *key; | ||
entry->value = value; | ||
entry->previous = NULL; | ||
entry->next = NULL; | ||
|
||
return entry; | ||
} | ||
|
||
static void th_entry_raw_add(th_entry_t **root, | ||
th_entry_t *entry) | ||
static void th_entry_raw_add(th_entry_t **root, th_entry_t *entry) | ||
{ | ||
if (*root != NULL) { | ||
(*root)->previous = entry; | ||
} | ||
|
||
entry->next = *root; | ||
*root = entry; | ||
} | ||
|
||
void th_entry_add(th_entry_t **root, th_key_t *key, | ||
th_any_t value) | ||
bool th_entry_add(th_entry_t **root, th_key_t *key, th_any_t value) | ||
{ | ||
th_entry_t *entry = th_entry_new(key, value); | ||
|
||
if (entry == NULL) return false; | ||
|
||
th_entry_raw_add(root, entry); | ||
} | ||
|
||
th_key_t th_key_new(th_any_t data, size_t size, | ||
th_hash_func_t hash_func) | ||
{ | ||
return (th_key_t) { | ||
.hash = hash_func(data, size), | ||
.size = size, | ||
.data = data, | ||
}; | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <string.h> | ||
|
||
#include "key.h" | ||
#include "hash.h" | ||
|
||
th_key_t th_key_new(th_any_t data, size_t size) | ||
{ | ||
return (th_key_t) { | ||
.hash = th_hash(data, size), | ||
.size = size, | ||
.data = data, | ||
}; | ||
} | ||
|
||
bool th_key_is_equal(th_key_t *first, th_key_t *second) | ||
{ | ||
if (first->size != second->size) return false; | ||
|
||
return memcmp(first->data, second->data, first->size) == 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef __TINYHASH_KEY_H__ | ||
#define __TINYHASH_KEY_H__ | ||
|
||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
|
||
#include "types.h" | ||
|
||
typedef struct { | ||
uint32_t hash; | ||
int size; | ||
th_any_t data; | ||
} th_key_t; | ||
|
||
th_key_t th_key_new(th_any_t data, size_t size); | ||
|
||
bool th_key_is_equal(th_key_t *first, th_key_t *second); | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.