Mass reformat
This commit is contained in:
parent
4d27def35e
commit
df11e34235
27 changed files with 121 additions and 136 deletions
|
|
@ -3,19 +3,19 @@
|
|||
#include <string.h>
|
||||
|
||||
typedef struct hashmap_entry {
|
||||
char *key;
|
||||
void *value;
|
||||
char *key;
|
||||
void *value;
|
||||
struct hashmap_entry *next;
|
||||
} hashmap_entry_t;
|
||||
|
||||
struct hashmap {
|
||||
hashmap_entry_t **buckets;
|
||||
size_t bucket_count;
|
||||
size_t bucket_count;
|
||||
};
|
||||
|
||||
static unsigned long hash(const char *str) {
|
||||
unsigned long hash = 5381;
|
||||
int c;
|
||||
int c;
|
||||
while ((c = *str++)) hash = ((hash << 5) + hash) + c;
|
||||
return hash;
|
||||
}
|
||||
|
|
@ -43,7 +43,7 @@ void hashmap_destroy(hashmap_t *map) {
|
|||
}
|
||||
|
||||
void hashmap_put(hashmap_t *map, const char *key, void *value) {
|
||||
size_t index = (hash(key) % map->bucket_count);
|
||||
size_t index = (hash(key) % map->bucket_count);
|
||||
hashmap_entry_t *entry = map->buckets[index];
|
||||
|
||||
while (entry) {
|
||||
|
|
@ -63,7 +63,7 @@ void hashmap_put(hashmap_t *map, const char *key, void *value) {
|
|||
}
|
||||
|
||||
void *hashmap_get(hashmap_t *map, const char *key) {
|
||||
size_t index = (hash(key) % map->bucket_count);
|
||||
size_t index = (hash(key) % map->bucket_count);
|
||||
hashmap_entry_t *entry = map->buckets[index];
|
||||
|
||||
while (entry) {
|
||||
|
|
@ -81,7 +81,7 @@ void hashmap_remove(hashmap_t *map, const char *key) {
|
|||
size_t index = (hash(key) % map->bucket_count);
|
||||
|
||||
hashmap_entry_t **prev = &map->buckets[index];
|
||||
hashmap_entry_t *entry = *prev;
|
||||
hashmap_entry_t *entry = *prev;
|
||||
|
||||
while (entry) {
|
||||
if (strcmp(entry->key, key) == 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue