Freeciv-3.3
Loading...
Searching...
No Matches
genhash.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13#ifndef FC__GENHASH_H
14#define FC__GENHASH_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20/****************************************************************************
21 A general-purpose generic hash table implementation.
22 See comments in "genhash.c".
23****************************************************************************/
24
25/* utility */
26#include "iterator.h"
27#include "support.h" /* bool type */
28
29struct genhash; /* opaque */
30
31/* Hash value type. */
32typedef unsigned int genhash_val_t;
33
34/* Function typedefs: */
35typedef genhash_val_t (*genhash_val_fn_t) (const void *);
36typedef bool (*genhash_comp_fn_t) (const void *, const void *);
37typedef void * (*genhash_copy_fn_t) (const void *);
38typedef void (*genhash_free_fn_t) (void *);
39
40
41/* Supplied functions (matching above typedefs) appropriate for
42 * keys being normal nul-terminated strings: */
44bool genhash_str_comp_func(const char *vkey1, const char *vkey2);
45/* and malloc'ed strings: */
46char *genhash_str_copy_func(const char *vkey);
49
50
51/* General functions: */
64 size_t nentries)
66struct genhash *
73 size_t nentries)
77
80size_t genhash_size(const struct genhash *pgenhash)
82size_t genhash_capacity(const struct genhash *pgenhash)
84
85struct genhash *genhash_copy(const struct genhash *pgenhash)
90
92 const void *data)
95 const void *data);
97 const void *data, void **old_pkey,
98 void **old_pdata)
100
102 void **pdata)
103 fc__attribute((nonnull (1)));
104
105bool genhash_remove(struct genhash *pgenhash, const void *key);
107 void **deleted_pkey, void **deleted_pdata)
108 fc__attribute((nonnull (1)));
109
115
116
117/* Iteration. */
119size_t genhash_iter_sizeof(void);
120
123#define genhash_keys_iterate(ARG_ht, NAME_key) \
124 generic_iterate(struct genhash_iter, const void *, NAME_key, \
125 genhash_iter_sizeof, genhash_key_iter_init, (ARG_ht))
126#define genhash_keys_iterate_end generic_iterate_end
127
129 const struct genhash *hash);
130#define genhash_values_iterate(ARG_ht, NAME_value) \
131 generic_iterate(struct genhash_iter, void *, NAME_value, \
132 genhash_iter_sizeof, genhash_value_iter_init, (ARG_ht))
133#define genhash_values_iterate_end generic_iterate_end
134
136 const struct genhash *hash);
137void *genhash_iter_key(const struct iterator *genhash_iter);
138void *genhash_iter_value(const struct iterator *genhash_iter);
139#define genhash_iterate(ARG_ht, NAME_iter) \
140 generic_iterate(struct genhash_iter, struct iterator *, NAME_iter, \
141 genhash_iter_sizeof, genhash_iter_init, (ARG_ht))
142#define genhash_iterate_end generic_iterate_end
143
144#ifdef __cplusplus
145}
146#endif /* __cplusplus */
147
148#endif /* FC__GENHASH_H */
char * incite_cost
Definition comments.c:76
void genhash_str_free_func(char *vkey) fc__attribute((nonnull(1)))
Definition genhash.c:140
genhash_val_t(* genhash_val_fn_t)(const void *)
Definition genhash.h:35
struct genhash * genhash_new_nentries_full(genhash_val_fn_t key_val_func, genhash_comp_fn_t key_comp_func, genhash_copy_fn_t key_copy_func, genhash_free_fn_t key_free_func, genhash_copy_fn_t data_copy_func, genhash_free_fn_t data_free_func, size_t nentries) fc__warn_unused_result
Definition genhash.c:233
bool genhash_replace_full(struct genhash *pgenhash, const void *key, const void *data, void **old_pkey, void **old_pdata) fc__attribute((nonnull(1)))
Definition genhash.c:637
size_t genhash_capacity(const struct genhash *pgenhash) fc__attribute((nonnull(1)))
Definition genhash.c:531
struct iterator * genhash_key_iter_init(struct genhash_iter *iter, const struct genhash *hash)
Definition genhash.c:882
size_t genhash_size(const struct genhash *pgenhash) fc__attribute((nonnull(1)))
Definition genhash.c:523
struct genhash * genhash_copy(const struct genhash *pgenhash) fc__attribute((nonnull(1))) fc__warn_unused_result
Definition genhash.c:539
bool genhash_str_comp_func(const char *vkey1, const char *vkey2)
Definition genhash.c:124
bool genhashes_are_equal(const struct genhash *pgenhash1, const struct genhash *pgenhash2)
Definition genhash.c:723
bool genhash_lookup(const struct genhash *pgenhash, const void *key, void **pdata) fc__attribute((nonnull(1)))
Definition genhash.c:668
struct genhash * genhash_new_full(genhash_val_fn_t key_val_func, genhash_comp_fn_t key_comp_func, genhash_copy_fn_t key_copy_func, genhash_free_fn_t key_free_func, genhash_copy_fn_t data_copy_func, genhash_free_fn_t data_free_func) fc__warn_unused_result
Definition genhash.c:265
struct genhash * genhash_new(genhash_val_fn_t key_val_func, genhash_comp_fn_t key_comp_func) fc__warn_unused_result
Definition genhash.c:280
bool genhash_set_no_shrink(struct genhash *pgenhash, bool no_shrink) fc__attribute((nonnull(1)))
Definition genhash.c:510
void genhash_destroy(struct genhash *pgenhash) fc__attribute((nonnull(1)))
Definition genhash.c:290
struct genhash * genhash_new_nentries(genhash_val_fn_t key_val_func, genhash_comp_fn_t key_comp_func, size_t nentries) fc__warn_unused_result
Definition genhash.c:250
bool(* genhash_comp_fn_t)(const void *, const void *)
Definition genhash.h:36
void genhash_clear(struct genhash *pgenhash) fc__attribute((nonnull(1)))
Definition genhash.c:576
void(* genhash_free_fn_t)(void *)
Definition genhash.h:38
size_t genhash_iter_sizeof(void)
Definition genhash.c:777
bool genhash_insert(struct genhash *pgenhash, const void *key, const void *data) fc__attribute((nonnull(1)))
Definition genhash.c:596
void *(* genhash_copy_fn_t)(const void *)
Definition genhash.h:37
bool genhashes_are_equal_full(const struct genhash *pgenhash1, const struct genhash *pgenhash2, genhash_comp_fn_t data_comp_func)
Definition genhash.c:732
bool genhash_remove(struct genhash *pgenhash, const void *key)
Definition genhash.c:686
struct iterator * genhash_iter_init(struct genhash_iter *iter, const struct genhash *hash)
Definition genhash.c:873
void * genhash_iter_key(const struct iterator *genhash_iter)
Definition genhash.c:785
struct iterator * genhash_value_iter_init(struct genhash_iter *iter, const struct genhash *hash)
Definition genhash.c:891
char * genhash_str_copy_func(const char *vkey)
Definition genhash.c:132
bool genhash_replace(struct genhash *pgenhash, const void *key, const void *data)
Definition genhash.c:622
genhash_val_t genhash_str_val_func(const char *vkey)
Definition genhash.c:109
unsigned int genhash_val_t
Definition genhash.h:32
bool genhash_remove_full(struct genhash *pgenhash, const void *key, void **deleted_pkey, void **deleted_pdata) fc__attribute((nonnull(1)))
Definition genhash.c:698
void * genhash_iter_value(const struct iterator *genhash_iter)
Definition genhash.c:794
static GHashTable * hash
Definition wldlg.c:322
genhash_comp_fn_t key_comp_func
Definition genhash.c:86
genhash_val_fn_t key_val_func
Definition genhash.c:85
genhash_free_fn_t key_free_func
Definition genhash.c:88
bool no_shrink
Definition genhash.c:93
genhash_copy_fn_t data_copy_func
Definition genhash.c:89
genhash_free_fn_t data_free_func
Definition genhash.c:90
genhash_copy_fn_t key_copy_func
Definition genhash.c:87
#define fc__attribute(x)
Definition support.h:99
#define fc__warn_unused_result
Definition support.h:109
#define bool
Definition support.h:71