]> code.delx.au - pulseaudio/blob - src/pulsecore/idxset.h
remap: Change remapping function argument type from void to int16_t / float as approp...
[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 typedef void *(*pa_copy_func_t)(const void *p);
53
54 typedef struct pa_idxset pa_idxset;
55
56 /* Instantiate a new idxset with the specified hash and comparison functions */
57 pa_idxset* pa_idxset_new(pa_hash_func_t hash_func, pa_compare_func_t compare_func);
58
59 /* Free the idxset. When the idxset is not empty the specified function is called for every entry contained */
60 void pa_idxset_free(pa_idxset *s, pa_free_cb_t free_cb);
61
62 /* Store a new item in the idxset. The index of the item is returned in *idx */
63 int pa_idxset_put(pa_idxset*s, void *p, uint32_t *idx);
64
65 /* Get the entry by its idx */
66 void* pa_idxset_get_by_index(pa_idxset*s, uint32_t idx);
67
68 /* Get the entry by its data. The index is returned in *idx */
69 void* pa_idxset_get_by_data(pa_idxset*s, const void *p, uint32_t *idx);
70
71 /* Similar to pa_idxset_get_by_index(), but removes the entry from the idxset. */
72 void* pa_idxset_remove_by_index(pa_idxset*s, uint32_t idx);
73
74 /* Similar to pa_idxset_get_by_data(), but removes the entry from the idxset */
75 void* pa_idxset_remove_by_data(pa_idxset*s, const void *p, uint32_t *idx);
76
77 /* If free_cb is not NULL, it's called for each entry. */
78 void pa_idxset_remove_all(pa_idxset *s, pa_free_cb_t free_cb);
79
80 /* This may be used to iterate through all entries. When called with
81 an invalid index value it returns the first entry, otherwise the
82 next following. The function is best called with *idx =
83 PA_IDXSET_VALID first. It is safe to manipulate the idxset between
84 the calls. It is not guaranteed that all entries have already been
85 returned before the an entry is returned the second time.*/
86 void* pa_idxset_rrobin(pa_idxset *s, uint32_t *idx);
87
88 /* Iterate through the idxset. At first iteration state should be NULL */
89 void *pa_idxset_iterate(pa_idxset *s, void **state, uint32_t *idx);
90
91 /* Return the oldest entry in the idxset and remove it. If idx is not NULL fill in its index in *idx */
92 void* pa_idxset_steal_first(pa_idxset *s, uint32_t *idx);
93
94 /* Return the oldest entry in the idxset. Fill in its index in *idx. */
95 void* pa_idxset_first(pa_idxset *s, uint32_t *idx);
96
97 /* Return the entry following the entry indexed by *idx. After the
98 * call *index contains the index of the returned
99 * object. pa_idxset_first() and pa_idxset_next() may be used to
100 * iterate through the set.*/
101 void *pa_idxset_next(pa_idxset *s, uint32_t *idx);
102
103 /* Return the current number of entries in the idxset */
104 unsigned pa_idxset_size(pa_idxset*s);
105
106 /* Return true of the idxset is empty */
107 bool pa_idxset_isempty(pa_idxset *s);
108
109 /* Duplicate the idxset. This will not copy the actual indexes. If copy_func is
110 * set, each entry is copied using the provided function, otherwise a shallow
111 * copy will be made. */
112 pa_idxset *pa_idxset_copy(pa_idxset *s, pa_copy_func_t copy_func);
113
114 /* A macro to ease iteration through all entries */
115 #define PA_IDXSET_FOREACH(e, s, idx) \
116 for ((e) = pa_idxset_first((s), &(idx)); (e); (e) = pa_idxset_next((s), &(idx)))
117
118 #endif