]> code.delx.au - pulseaudio/blob - src/pulsecore/idxset.h
idxset: Use pa_free_cb_t instead of pa_free2_cb_t
[pulseaudio] / src / pulsecore / idxset.h
1 #ifndef foopulsecoreidxsethfoo
2 #define foopulsecoreidxsethfoo
3
4 /***
5 This file is part of PulseAudio.
6
7 Copyright 2004-2008 Lennart Poettering
8 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
9
10 PulseAudio is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as
12 published by the Free Software Foundation; either version 2.1 of the
13 License, or (at your option) any later version.
14
15 PulseAudio is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public
21 License along with PulseAudio; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 USA.
24 ***/
25
26 #include <inttypes.h>
27
28 #include <pulse/def.h>
29
30 #include <pulsecore/macro.h>
31
32 /* A combination of a set and a dynamic array. Entries are indexable
33 * both through an automatically generated numeric index and the
34 * entry's data pointer. As usual, memory management is the user's
35 * job. */
36
37 /* A special index value denoting the invalid index. */
38 #define PA_IDXSET_INVALID ((uint32_t) -1)
39
40 /* Generic implementations for hash and comparison functions. Just
41 * compares the pointer or calculates the hash value directly from the
42 * pointer value. */
43 unsigned pa_idxset_trivial_hash_func(const void *p);
44 int pa_idxset_trivial_compare_func(const void *a, const void *b);
45
46 /* Generic implementations for hash and comparison functions for strings. */
47 unsigned pa_idxset_string_hash_func(const void *p);
48 int pa_idxset_string_compare_func(const void *a, const void *b);
49
50 typedef unsigned (*pa_hash_func_t)(const void *p);
51 typedef int (*pa_compare_func_t)(const void *a, const void *b);
52
53 typedef struct pa_idxset pa_idxset;
54
55 /* Instantiate a new idxset with the specified hash and comparison functions */
56 pa_idxset* pa_idxset_new(pa_hash_func_t hash_func, pa_compare_func_t compare_func);
57
58 /* Free the idxset. When the idxset is not empty the specified function is called for every entry contained */
59 void pa_idxset_free(pa_idxset *s, pa_free_cb_t free_cb);
60
61 /* Store a new item in the idxset. The index of the item is returned in *idx */
62 int pa_idxset_put(pa_idxset*s, void *p, uint32_t *idx);
63
64 /* Get the entry by its idx */
65 void* pa_idxset_get_by_index(pa_idxset*s, uint32_t idx);
66
67 /* Get the entry by its data. The index is returned in *idx */
68 void* pa_idxset_get_by_data(pa_idxset*s, const void *p, uint32_t *idx);
69
70 /* Similar to pa_idxset_get_by_index(), but removes the entry from the idxset. */
71 void* pa_idxset_remove_by_index(pa_idxset*s, uint32_t idx);
72
73 /* Similar to pa_idxset_get_by_data(), but removes the entry from the idxset */
74 void* pa_idxset_remove_by_data(pa_idxset*s, const void *p, uint32_t *idx);
75
76 /* This may be used to iterate through all entries. When called with
77 an invalid index value it returns the first entry, otherwise the
78 next following. The function is best called with *idx =
79 PA_IDXSET_VALID first. It is safe to manipulate the idxset between
80 the calls. It is not guaranteed that all entries have already been
81 returned before the an entry is returned the second time.*/
82 void* pa_idxset_rrobin(pa_idxset *s, uint32_t *idx);
83
84 /* Iterate through the idxset. At first iteration state should be NULL */
85 void *pa_idxset_iterate(pa_idxset *s, void **state, uint32_t *idx);
86
87 /* Return the oldest entry in the idxset and remove it. If idx is not NULL fill in its index in *idx */
88 void* pa_idxset_steal_first(pa_idxset *s, uint32_t *idx);
89
90 /* Return the oldest entry in the idxset. Fill in its index in *idx. */
91 void* pa_idxset_first(pa_idxset *s, uint32_t *idx);
92
93 /* Return the entry following the entry indexed by *idx. After the
94 * call *index contains the index of the returned
95 * object. pa_idxset_first() and pa_idxset_next() may be used to
96 * iterate through the set.*/
97 void *pa_idxset_next(pa_idxset *s, uint32_t *idx);
98
99 /* Return the current number of entries in the idxset */
100 unsigned pa_idxset_size(pa_idxset*s);
101
102 /* Return TRUE of the idxset is empty */
103 pa_bool_t pa_idxset_isempty(pa_idxset *s);
104
105 /* Duplicate the idxset. This will not copy the actual indexes */
106 pa_idxset *pa_idxset_copy(pa_idxset *s);
107
108 /* A macro to ease iteration through all entries */
109 #define PA_IDXSET_FOREACH(e, s, idx) \
110 for ((e) = pa_idxset_first((s), &(idx)); (e); (e) = pa_idxset_next((s), &(idx)))
111
112 #endif