25 #ifndef PIPEWIRE_MAP_H
26 #define PIPEWIRE_MAP_H
88 #define PW_MAP_INIT(extend) (struct pw_map) { PW_ARRAY_INIT(extend), SPA_ID_INVALID }
96 #define pw_map_get_size(m) pw_array_get_len(&(m)->items, union pw_map_item)
97 #define pw_map_get_item(m,id) pw_array_get_unchecked(&(m)->items,id,union pw_map_item)
98 #define pw_map_item_is_free(item) ((item)->next & 0x1)
99 #define pw_map_id_is_free(m,id) (pw_map_item_is_free(pw_map_get_item(m,id)))
101 #define pw_map_check_id(m,id) ((id) < pw_map_get_size(m))
103 #define pw_map_has_item(m,id) (pw_map_check_id(m,id) && !pw_map_id_is_free(m, id))
104 #define pw_map_lookup_unchecked(m,id) pw_map_get_item(m,id)->data
107 #define PW_MAP_ID_TO_PTR(id) (SPA_UINT32_TO_PTR((id)<<1))
109 #define PW_MAP_PTR_TO_ID(p) (SPA_PTR_TO_UINT32(p)>>1)
148 union pw_map_item *start, *item;
152 start = (
union pw_map_item *) map->
items.
data;
156 item = (
union pw_map_item *)
pw_array_add(&map->
items,
sizeof(
union pw_map_item));
159 start = (
union pw_map_item *) map->
items.
data;
176 union pw_map_item *item;
180 else if (
id == size) {
181 item = (
union pw_map_item *)
pw_array_add(&map->
items,
sizeof(
union pw_map_item));
231 int (*func) (
void *item_data,
void *data),
void *data)
233 union pw_map_item *item;
238 if ((res = func(item->data, data)) != 0)
static int pw_array_ensure_size(struct pw_array *arr, size_t size)
Make sure size bytes can be added to the array.
Definition: array.h:116
static void pw_array_init(struct pw_array *arr, size_t extend)
Initialize the array with given extend.
Definition: array.h:95
static void * pw_array_add(struct pw_array *arr, size_t size)
Add ref size bytes to arr.
Definition: array.h:139
static void pw_array_clear(struct pw_array *arr)
Clear the array.
Definition: array.h:103
#define pw_array_for_each(pos, array)
Definition: array.h:77
static void pw_array_reset(struct pw_array *arr)
Reset the array.
Definition: array.h:110
static void pw_map_remove(struct pw_map *map, uint32_t id)
Remove an item at index.
Definition: map.h:205
#define pw_map_check_id(m, id)
Definition: map.h:106
static void * pw_map_lookup(struct pw_map *map, uint32_t id)
Find an item in the map.
Definition: map.h:219
static int pw_map_insert_at(struct pw_map *map, uint32_t id, void *data)
Replace the data in the map at an index.
Definition: map.h:180
#define pw_map_get_size(m)
Get the number of currently allocated elements in the map.
Definition: map.h:101
static uint32_t pw_map_insert_new(struct pw_map *map, void *data)
Insert data in the map.
Definition: map.h:153
static void pw_map_reset(struct pw_map *map)
Reset a map but keep previously allocated storage.
Definition: map.h:141
static void pw_map_clear(struct pw_map *map)
Clear a map and free the data storage.
Definition: map.h:133
#define pw_map_item_is_free(item)
Definition: map.h:103
#define pw_map_id_is_free(m, id)
Definition: map.h:104
static void pw_map_init(struct pw_map *map, size_t size, size_t extend)
Initialize a map.
Definition: map.h:123
static int pw_map_for_each(struct pw_map *map, int(*func)(void *item_data, void *data), void *data)
Iterate all map items.
Definition: map.h:237
#define pw_map_get_item(m, id)
Definition: map.h:102
#define SPA_ID_INVALID
Definition: defs.h:217
#define SPA_LIKELY(x)
Definition: defs.h:313
size_t size
length of array in bytes
Definition: array.h:54
size_t extend
number of bytes to extend with
Definition: array.h:56
void * data
pointer to array data
Definition: array.h:53
A map.
Definition: map.h:86
struct pw_array items
Definition: map.h:87
uint32_t free_list
Definition: map.h:88