hashmap: Apply 'const' to arguments like we did with the kernel version
This commit is contained in:
parent
d608044bac
commit
aebb75ac75
@ -14,10 +14,10 @@
|
|||||||
|
|
||||||
_Begin_C_Header
|
_Begin_C_Header
|
||||||
|
|
||||||
typedef unsigned int (*hashmap_hash_t) (void * key);
|
typedef unsigned int (*hashmap_hash_t) (const void * key);
|
||||||
typedef int (*hashmap_comp_t) (void * a, void * b);
|
typedef int (*hashmap_comp_t) (const void * a, const void * b);
|
||||||
typedef void (*hashmap_free_t) (void *);
|
typedef void (*hashmap_free_t) (void *);
|
||||||
typedef void * (*hashmap_dupe_t) (void *);
|
typedef void * (*hashmap_dupe_t) (const void *);
|
||||||
|
|
||||||
typedef struct hashmap_entry {
|
typedef struct hashmap_entry {
|
||||||
char * key;
|
char * key;
|
||||||
@ -37,17 +37,17 @@ typedef struct hashmap {
|
|||||||
|
|
||||||
extern hashmap_t * hashmap_create(int size);
|
extern hashmap_t * hashmap_create(int size);
|
||||||
extern hashmap_t * hashmap_create_int(int size);
|
extern hashmap_t * hashmap_create_int(int size);
|
||||||
extern void * hashmap_set(hashmap_t * map, void * key, void * value);
|
extern void * hashmap_set(hashmap_t * map, const void * key, void * value);
|
||||||
extern void * hashmap_get(hashmap_t * map, void * key);
|
extern void * hashmap_get(hashmap_t * map, const void * key);
|
||||||
extern void * hashmap_remove(hashmap_t * map, void * key);
|
extern void * hashmap_remove(hashmap_t * map, const void * key);
|
||||||
extern int hashmap_has(hashmap_t * map, void * key);
|
extern int hashmap_has(hashmap_t * map, const void * key);
|
||||||
extern list_t * hashmap_keys(hashmap_t * map);
|
extern list_t * hashmap_keys(hashmap_t * map);
|
||||||
extern list_t * hashmap_values(hashmap_t * map);
|
extern list_t * hashmap_values(hashmap_t * map);
|
||||||
extern void hashmap_free(hashmap_t * map);
|
extern void hashmap_free(hashmap_t * map);
|
||||||
|
|
||||||
extern unsigned int hashmap_string_hash(void * key);
|
extern unsigned int hashmap_string_hash(const void * key);
|
||||||
extern int hashmap_string_comp(void * a, void * b);
|
extern int hashmap_string_comp(const void * a, const void * b);
|
||||||
extern void * hashmap_string_dupe(void * key);
|
extern void * hashmap_string_dupe(const void * key);
|
||||||
extern int hashmap_is_empty(hashmap_t * map);
|
extern int hashmap_is_empty(hashmap_t * map);
|
||||||
|
|
||||||
_End_C_Header
|
_End_C_Header
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include <toaru/list.h>
|
#include <toaru/list.h>
|
||||||
#include <toaru/hashmap.h>
|
#include <toaru/hashmap.h>
|
||||||
|
|
||||||
unsigned int hashmap_string_hash(void * _key) {
|
unsigned int hashmap_string_hash(const void * _key) {
|
||||||
unsigned int hash = 0;
|
unsigned int hash = 0;
|
||||||
char * key = (char *)_key;
|
char * key = (char *)_key;
|
||||||
int c;
|
int c;
|
||||||
@ -21,24 +21,24 @@ unsigned int hashmap_string_hash(void * _key) {
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hashmap_string_comp(void * a, void * b) {
|
int hashmap_string_comp(const void * a, const void * b) {
|
||||||
return !strcmp(a,b);
|
return !strcmp(a,b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void * hashmap_string_dupe(void * key) {
|
void * hashmap_string_dupe(const void * key) {
|
||||||
return strdup(key);
|
return strdup(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int hashmap_int_hash(void * key) {
|
unsigned int hashmap_int_hash(const void * key) {
|
||||||
return (uintptr_t)key;
|
return (uintptr_t)key;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hashmap_int_comp(void * a, void * b) {
|
int hashmap_int_comp(const void * a, const void * b) {
|
||||||
return (uintptr_t)a == (uintptr_t)b;
|
return (uintptr_t)a == (uintptr_t)b;
|
||||||
}
|
}
|
||||||
|
|
||||||
void * hashmap_int_dupe(void * key) {
|
void * hashmap_int_dupe(const void * key) {
|
||||||
return key;
|
return (void*)key;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hashmap_int_free(void * ptr) {
|
static void hashmap_int_free(void * ptr) {
|
||||||
@ -79,7 +79,7 @@ hashmap_t * hashmap_create_int(int size) {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
void * hashmap_set(hashmap_t * map, void * key, void * value) {
|
void * hashmap_set(hashmap_t * map, const void * key, void * value) {
|
||||||
unsigned int hash = map->hash_func(key) % map->size;
|
unsigned int hash = map->hash_func(key) % map->size;
|
||||||
|
|
||||||
hashmap_entry_t * x = map->entries[hash];
|
hashmap_entry_t * x = map->entries[hash];
|
||||||
@ -112,7 +112,7 @@ void * hashmap_set(hashmap_t * map, void * key, void * value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void * hashmap_get(hashmap_t * map, void * key) {
|
void * hashmap_get(hashmap_t * map, const void * key) {
|
||||||
unsigned int hash = map->hash_func(key) % map->size;
|
unsigned int hash = map->hash_func(key) % map->size;
|
||||||
|
|
||||||
hashmap_entry_t * x = map->entries[hash];
|
hashmap_entry_t * x = map->entries[hash];
|
||||||
@ -129,7 +129,7 @@ void * hashmap_get(hashmap_t * map, void * key) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void * hashmap_remove(hashmap_t * map, void * key) {
|
void * hashmap_remove(hashmap_t * map, const void * key) {
|
||||||
unsigned int hash = map->hash_func(key) % map->size;
|
unsigned int hash = map->hash_func(key) % map->size;
|
||||||
|
|
||||||
hashmap_entry_t * x = map->entries[hash];
|
hashmap_entry_t * x = map->entries[hash];
|
||||||
@ -161,7 +161,7 @@ void * hashmap_remove(hashmap_t * map, void * key) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int hashmap_has(hashmap_t * map, void * key) {
|
int hashmap_has(hashmap_t * map, const void * key) {
|
||||||
unsigned int hash = map->hash_func(key) % map->size;
|
unsigned int hash = map->hash_func(key) % map->size;
|
||||||
|
|
||||||
hashmap_entry_t * x = map->entries[hash];
|
hashmap_entry_t * x = map->entries[hash];
|
||||||
|
Loading…
Reference in New Issue
Block a user