#ifndef MAP_H #define MAP_H #include #include #include "list.h" union map_data { void *ptr; fpos_t pos; intptr_t i; uintptr_t u; }; struct map { void (*free_entry)(void *key, union map_data *data); uint_least32_t (*hash)(const void *key); uint_least32_t table_mask; int (*compare)(const void *key1, const void *key2); LIST_HEAD(struct, struct map_entry) *table; long count; }; uint_least32_t map_hash_stringignorecase(const void *key); uint_least32_t map_hash_string(const void *key); uint_least32_t map_hash_unsigned(const void *key); uint_least32_t map_hash_uintptr(const void *key); int map_compare_stringignorecase(const void *key1, const void *key2); int map_compare_string(const void *key1, const void *key2); int map_compare_unsigned(const void *key1, const void *key2); int map_compare_uintptr(const void *key1, const void *key2); void map_init(struct map *m, unsigned initial_size_bits, void (*free_entry)(void *key,union map_data *data), uint_least32_t (*hash)(const void *key), int (*compare)(const void *key1,const void *key2)); int map_replace(struct map *m, void *key, const union map_data *data, int replace, int exclusive); int map_add_ptr(struct map *m, void *key, void *ptr); int map_replace_fpos(struct map *m, uintptr_t key, const fpos_t *pos); union map_data *map_lookup(struct map *m, const void *key); fpos_t *map_lookup_fpos(struct map *m, const void *key); void *map_lookup_ptr(struct map *m, const void *key); void map_foreach(struct map *m, void *p, void (*callback)(void *p,void *key,union map_data *data)); int map_remove(struct map *m, void *key); void map_free(struct map *m); #endif