2008-06-27 20:34:14 +02:00
|
|
|
#ifndef foopulsecoreidxsethfoo
|
|
|
|
|
#define foopulsecoreidxsethfoo
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-07-16 19:56:36 +00:00
|
|
|
/***
|
2006-06-19 21:53:48 +00:00
|
|
|
This file is part of PulseAudio.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2008-06-27 20:34:14 +02:00
|
|
|
Copyright 2004-2008 Lennart Poettering
|
2007-02-13 15:35:19 +00:00
|
|
|
Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
2004-11-14 14:58:54 +00:00
|
|
|
it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
|
License, or (at your option) any later version.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
2004-07-16 19:56:36 +00:00
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2004-11-14 14:58:54 +00:00
|
|
|
Lesser General Public License for more details.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-14 14:58:54 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2006-06-19 21:53:48 +00:00
|
|
|
License along with PulseAudio; if not, write to the Free Software
|
2004-07-16 19:56:36 +00:00
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
2004-06-08 23:54:24 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
2008-06-27 20:34:14 +02:00
|
|
|
#include <pulsecore/macro.h>
|
|
|
|
|
|
2004-11-21 21:31:28 +00:00
|
|
|
/* A combination of a set and a dynamic array. Entries are indexable
|
2008-06-27 20:34:14 +02:00
|
|
|
* both through an automatically generated numeric index and the
|
|
|
|
|
* entry's data pointer. As usual, memory management is the user's
|
|
|
|
|
* job. */
|
2004-11-21 02:43:05 +00:00
|
|
|
|
2004-11-21 21:31:28 +00:00
|
|
|
/* A special index value denoting the invalid index. */
|
2004-07-03 23:35:12 +00:00
|
|
|
#define PA_IDXSET_INVALID ((uint32_t) -1)
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2008-06-27 20:12:24 +02:00
|
|
|
/* Similar to pa_free_cb_t, but takes a userdata argument */
|
|
|
|
|
typedef void (*pa_free2_cb_t)(void *p, void *userdata);
|
|
|
|
|
|
2004-11-21 21:31:28 +00:00
|
|
|
/* Generic implementations for hash and comparison functions. Just
|
|
|
|
|
* compares the pointer or calculates the hash value directly from the
|
|
|
|
|
* pointer value. */
|
2004-07-03 23:35:12 +00:00
|
|
|
unsigned pa_idxset_trivial_hash_func(const void *p);
|
|
|
|
|
int pa_idxset_trivial_compare_func(const void *a, const void *b);
|
2004-06-27 22:42:17 +00:00
|
|
|
|
2004-11-21 21:31:28 +00:00
|
|
|
/* Generic implementations for hash and comparison functions for strings. */
|
2004-07-03 23:35:12 +00:00
|
|
|
unsigned pa_idxset_string_hash_func(const void *p);
|
|
|
|
|
int pa_idxset_string_compare_func(const void *a, const void *b);
|
2004-06-27 22:42:17 +00:00
|
|
|
|
2006-08-18 19:42:14 +00:00
|
|
|
typedef unsigned (*pa_hash_func_t)(const void *p);
|
|
|
|
|
typedef int (*pa_compare_func_t)(const void *a, const void *b);
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
typedef struct pa_idxset pa_idxset;
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-11-21 21:31:28 +00:00
|
|
|
/* Instantiate a new idxset with the specified hash and comparison functions */
|
2006-08-18 19:42:14 +00:00
|
|
|
pa_idxset* pa_idxset_new(pa_hash_func_t hash_func, pa_compare_func_t compare_func);
|
2004-11-21 21:31:28 +00:00
|
|
|
|
|
|
|
|
/* Free the idxset. When the idxset is not empty the specified function is called for every entry contained */
|
2008-06-27 20:34:14 +02:00
|
|
|
void pa_idxset_free(pa_idxset *s, pa_free2_cb_t free_cb, void *userdata);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
/* Store a new item in the idxset. The index of the item is returned in *idx */
|
|
|
|
|
int pa_idxset_put(pa_idxset*s, void *p, uint32_t *idx);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
/* Get the entry by its idx */
|
|
|
|
|
void* pa_idxset_get_by_index(pa_idxset*s, uint32_t idx);
|
2004-11-21 21:31:28 +00:00
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
/* Get the entry by its data. The idx is returned in *index */
|
|
|
|
|
void* pa_idxset_get_by_data(pa_idxset*s, const void *p, uint32_t *idx);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-11-21 21:31:28 +00:00
|
|
|
/* Similar to pa_idxset_get_by_index(), but removes the entry from the idxset. */
|
2006-01-11 01:17:39 +00:00
|
|
|
void* pa_idxset_remove_by_index(pa_idxset*s, uint32_t idx);
|
2004-11-21 21:31:28 +00:00
|
|
|
|
|
|
|
|
/* Similar to pa_idxset_get_by_data(), but removes the entry from the idxset */
|
2006-01-11 01:17:39 +00:00
|
|
|
void* pa_idxset_remove_by_data(pa_idxset*s, const void *p, uint32_t *idx);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-06-14 20:30:50 +00:00
|
|
|
/* This may be used to iterate through all entries. When called with
|
|
|
|
|
an invalid index value it returns the first entry, otherwise the
|
2006-01-11 01:17:39 +00:00
|
|
|
next following. The function is best called with *idx =
|
2004-11-21 21:31:28 +00:00
|
|
|
PA_IDXSET_VALID first. It is safe to manipulate the idxset between
|
|
|
|
|
the calls. It is not guaranteed that all entries have already been
|
|
|
|
|
returned before the an entry is returned the second time.*/
|
2006-01-11 01:17:39 +00:00
|
|
|
void* pa_idxset_rrobin(pa_idxset *s, uint32_t *idx);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2008-06-27 20:34:14 +02:00
|
|
|
/* Iterate through the idxset. At first iteration state should be NULL */
|
|
|
|
|
void *pa_idxset_iterate(pa_idxset *s, void **state, uint32_t *idx);
|
|
|
|
|
|
|
|
|
|
/* Return the oldest entry in the idxset and remove it. If idx is not NULL fill in its index in *idx */
|
|
|
|
|
void* pa_idxset_steal_first(pa_idxset *s, uint32_t *idx);
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
/* Return the oldest entry in the idxset. Fill in its index in *idx. */
|
|
|
|
|
void* pa_idxset_first(pa_idxset *s, uint32_t *idx);
|
2004-11-21 21:31:28 +00:00
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
/* Return the entry following the entry indexed by *idx. After the
|
2004-11-21 21:31:28 +00:00
|
|
|
* call *index contains the index of the returned
|
|
|
|
|
* object. pa_idxset_first() and pa_idxset_next() may be used to
|
|
|
|
|
* iterate through the set.*/
|
2006-01-11 01:17:39 +00:00
|
|
|
void *pa_idxset_next(pa_idxset *s, uint32_t *idx);
|
2004-06-14 20:30:50 +00:00
|
|
|
|
2008-06-27 20:34:14 +02:00
|
|
|
/* Return the current number of entries in the idxset */
|
2006-01-11 01:17:39 +00:00
|
|
|
unsigned pa_idxset_size(pa_idxset*s);
|
|
|
|
|
|
2008-06-27 20:34:14 +02:00
|
|
|
/* Return TRUE of the idxset is empty */
|
|
|
|
|
pa_bool_t pa_idxset_isempty(pa_idxset *s);
|
2004-06-15 17:05:03 +00:00
|
|
|
|
2009-06-17 03:01:40 +02:00
|
|
|
/* Duplicate the idxset. This will not copy the actual indexes */
|
|
|
|
|
pa_idxset *pa_idxset_copy(pa_idxset *s);
|
|
|
|
|
|
2009-06-06 15:30:24 +02:00
|
|
|
/* A macro to ease iteration through all entries */
|
2009-04-29 01:46:12 +02:00
|
|
|
#define PA_IDXSET_FOREACH(e, s, idx) \
|
|
|
|
|
for ((e) = pa_idxset_first((s), &(idx)); (e); (e) = pa_idxset_next((s), &(idx)))
|
|
|
|
|
|
2004-06-08 23:54:24 +00:00
|
|
|
#endif
|