3beff0607eadee53c281f66b4d7755e97af335f6
[ardour.git] / libs / fluidsynth / src / fluid_hash.h
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 /*
21  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GLib Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GLib at ftp://ftp.gtk.org/pub/gtk/.
25  */
26
27 /*
28  * Adapted for FluidSynth use by Josh Green <jgreen@users.sourceforge.net>
29  * September 8, 2009 from glib 2.18.4
30  * 
31  * - Self contained (no dependencies on glib)
32  * - changed names to fluid_hashtable_...
33  */
34
35 #ifndef _FLUID_HASH_H
36 #define _FLUID_HASH_H
37
38 #include "fluidsynth_priv.h"
39 #include "fluid_list.h"
40 #include "fluid_sys.h"
41
42 /* Extracted from gtypes.h */
43 typedef void (*fluid_destroy_notify_t)(void *data);
44 typedef unsigned int (*fluid_hash_func_t)(const void *key);
45 typedef int (*fluid_equal_func_t)(const void *a, const void *b);
46 /* End gtypes.h extraction */
47
48 typedef int (*fluid_hr_func_t)(void *key, void *value, void *user_data);
49 typedef struct _fluid_hashtable_iter_t fluid_hashtable_iter_t;
50
51 typedef struct _fluid_hashnode_t      fluid_hashnode_t;
52
53 struct _fluid_hashnode_t
54 {
55   void *key;
56   void *value;
57   fluid_hashnode_t *next;
58   unsigned int key_hash;
59 };
60
61 struct _fluid_hashtable_t
62 {
63   int size;
64   int nnodes;
65   fluid_hashnode_t **nodes;
66   fluid_hash_func_t hash_func;
67   fluid_equal_func_t key_equal_func;
68   volatile int ref_count;
69   fluid_destroy_notify_t key_destroy_func;
70   fluid_destroy_notify_t value_destroy_func;
71   fluid_rec_mutex_t mutex;          // Optionally used in other modules (fluid_settings.c for example)
72 };
73
74 struct _fluid_hashtable_iter_t
75 {
76   /*< private >*/
77   void *        dummy1;
78   void *        dummy2;
79   void *        dummy3;
80   int           dummy4;
81   int           dummy5;         // Bool
82   void *        dummy6;
83 };
84
85 fluid_hashtable_t* new_fluid_hashtable (fluid_hash_func_t hash_func,
86                                         fluid_equal_func_t key_equal_func);
87 fluid_hashtable_t* new_fluid_hashtable_full (fluid_hash_func_t hash_func,
88                                               fluid_equal_func_t key_equal_func,
89                                               fluid_destroy_notify_t key_destroy_func,
90                                               fluid_destroy_notify_t value_destroy_func);
91 void delete_fluid_hashtable(fluid_hashtable_t *hashtable);
92
93 void fluid_hashtable_iter_init (fluid_hashtable_iter_t *iter, fluid_hashtable_t *hashtable);
94 int fluid_hashtable_iter_next (fluid_hashtable_iter_t *iter, void **key, void **value);
95 fluid_hashtable_t *fluid_hashtable_iter_get_hash_table (fluid_hashtable_iter_t *iter);
96 void fluid_hashtable_iter_remove (fluid_hashtable_iter_t *iter);
97 void fluid_hashtable_iter_steal (fluid_hashtable_iter_t *iter);
98
99 fluid_hashtable_t* fluid_hashtable_ref (fluid_hashtable_t *hashtable);
100 void fluid_hashtable_unref (fluid_hashtable_t *hashtable);
101
102 void *fluid_hashtable_lookup (fluid_hashtable_t *hashtable, const void *key);
103 int fluid_hashtable_lookup_extended (fluid_hashtable_t *hashtable, const void *lookup_key,
104                                       void **orig_key, void **value);
105
106 void fluid_hashtable_insert (fluid_hashtable_t *hashtable, void *key, void *value);
107 void fluid_hashtable_replace (fluid_hashtable_t *hashtable, void *key, void *value);
108
109 int fluid_hashtable_remove (fluid_hashtable_t *hashtable, const void *key);
110 int fluid_hashtable_steal (fluid_hashtable_t *hashtable, const void *key);
111 void fluid_hashtable_remove_all (fluid_hashtable_t *hashtable);
112 void fluid_hashtable_steal_all (fluid_hashtable_t *hashtable);
113 unsigned int fluid_hashtable_foreach_steal (fluid_hashtable_t *hashtable,
114                                              fluid_hr_func_t func, void *user_data);
115 void fluid_hashtable_foreach (fluid_hashtable_t *hashtable, fluid_hr_func_t func,
116                                void *user_data);
117 void *fluid_hashtable_find (fluid_hashtable_t *hashtable, fluid_hr_func_t predicate,
118                              void *user_data);
119 unsigned int fluid_hashtable_size (fluid_hashtable_t *hashtable);
120 fluid_list_t *fluid_hashtable_get_keys (fluid_hashtable_t *hashtable);
121 fluid_list_t *fluid_hashtable_get_values (fluid_hashtable_t *hashtable);
122
123 int fluid_str_equal (const void *v1, const void *v2);
124 unsigned int fluid_str_hash (const void *v);
125 int fluid_direct_equal (const void *v1, const void *v2);
126 unsigned int fluid_direct_hash (const void *v);
127 int fluid_int_equal (const void *v1, const void *v2);
128 unsigned int fluid_int_hash (const void *v);
129
130 #endif /* _FLUID_HASH_H */
131