Go to the documentation of this file.
25 #ifndef PIPEWIRE_MAP_H
26 #define PIPEWIRE_MAP_H
60 #define PW_MAP_INIT(extend) (struct pw_map) { PW_ARRAY_INIT(extend), SPA_ID_INVALID }
62 #define pw_map_get_size(m) pw_array_get_len(&(m)->items, union pw_map_item)
63 #define pw_map_get_item(m,id) pw_array_get_unchecked(&(m)->items,id,union pw_map_item)
64 #define pw_map_item_is_free(item) ((item)->next & 0x1)
65 #define pw_map_id_is_free(m,id) (pw_map_item_is_free(pw_map_get_item(m,id)))
66 #define pw_map_check_id(m,id) ((id) < pw_map_get_size(m))
67 #define pw_map_has_item(m,id) (pw_map_check_id(m,id) && !pw_map_id_is_free(m, id))
68 #define pw_map_lookup_unchecked(m,id) pw_map_get_item(m,id)->data
71 #define PW_MAP_ID_TO_PTR(id) (SPA_UINT32_TO_PTR((id)<<1))
73 #define PW_MAP_PTR_TO_ID(p) (SPA_PTR_TO_UINT32(p)>>1)
80 static inline void pw_map_init(
struct pw_map *map,
size_t size,
size_t extend)
90 static inline void pw_map_clear(
struct pw_map *map)
92 pw_array_clear(&map->
items);
95 static inline void pw_map_reset(
struct pw_map *map)
97 pw_array_reset(&map->
items);
107 static inline uint32_t pw_map_insert_new(
struct pw_map *map,
void *
data)
134 static inline int pw_map_insert_at(
struct pw_map *map, uint32_t
id,
void *
data)
141 else if (
id == size) {
157 static inline void pw_map_remove(
struct pw_map *map, uint32_t
id)
168 static inline void *pw_map_lookup(
struct pw_map *map, uint32_t
id)
186 static inline int pw_map_for_each(
struct pw_map *map,
187 int (*func) (
void *item_data,
void *
data),
void *
data)
194 if ((res = func(
item->data,
data)) != 0)
uint32_t next
next free index
Definition: map.h:50
user data to add to an object
Definition: filter.c:75
An entry in the map.
Definition: map.h:49
size_t size
length of array in bytes
Definition: array.h:50
size_t extend
number of bytes to extend with
Definition: array.h:52
#define pw_array_for_each(pos, array)
Definition: array.h:72
uint32_t free_list
the free items
Definition: map.h:57
#define SPA_LIKELY(x)
Definition: defs.h:234
Definition: impl-metadata.c:49
struct pw_array items
an array with the map items
Definition: map.h:56
#define pw_map_get_item(m, id)
Definition: map.h:63
void * data
data of this item, must be an even address
Definition: map.h:51
#define pw_map_check_id(m, id)
Definition: map.h:66
#define pw_map_item_is_free(item)
Definition: map.h:64
#define SPA_ID_INVALID
Definition: defs.h:182
void * data
pointer to array data
Definition: array.h:49
A map.
Definition: map.h:55
#define pw_map_get_size(m)
Definition: map.h:62