PipeWire  0.3.38

A map that holds objects indexed by id. More...

Files

file  map.h
 pipewire/map.h
 

Data Structures

union  pw_map_item
 An entry in the map. More...
 
struct  pw_map
 A map. More...
 

Macros

#define PW_MAP_INIT(extend)   (struct pw_map) { PW_ARRAY_INIT(extend), SPA_ID_INVALID }
 
#define pw_map_get_size(m)   pw_array_get_len(&(m)->items, union pw_map_item)
 
#define pw_map_get_item(m, id)   pw_array_get_unchecked(&(m)->items,id,union pw_map_item)
 
#define pw_map_item_is_free(item)   ((item)->next & 0x1)
 
#define pw_map_id_is_free(m, id)   (pw_map_item_is_free(pw_map_get_item(m,id)))
 
#define pw_map_check_id(m, id)   ((id) < pw_map_get_size(m))
 
#define pw_map_has_item(m, id)   (pw_map_check_id(m,id) && !pw_map_id_is_free(m, id))
 
#define pw_map_lookup_unchecked(m, id)   pw_map_get_item(m,id)->data
 
#define PW_MAP_ID_TO_PTR(id)   (SPA_UINT32_TO_PTR((id)<<1))
 Convert an id to a pointer that can be inserted into the map. More...
 
#define PW_MAP_PTR_TO_ID(p)   (SPA_PTR_TO_UINT32(p)>>1)
 Convert a pointer to an id that can be retrieved from the map. More...
 

Functions

static void pw_map_init (struct pw_map *map, size_t size, size_t extend)
 Initialize a map. More...
 
static void pw_map_clear (struct pw_map *map)
 Clear a map. More...
 
static void pw_map_reset (struct pw_map *map)
 
static uint32_t pw_map_insert_new (struct pw_map *map, void *data)
 Insert data in the map. More...
 
static int pw_map_insert_at (struct pw_map *map, uint32_t id, void *data)
 Insert data in the map at an index. More...
 
static void pw_map_remove (struct pw_map *map, uint32_t id)
 Remove an item at index. More...
 
static void * pw_map_lookup (struct pw_map *map, uint32_t id)
 Find an item in the map. More...
 
static int pw_map_for_each (struct pw_map *map, int(*func)(void *item_data, void *data), void *data)
 Iterate all map items. More...
 

Detailed Description

A map that holds objects indexed by id.

Macro Definition Documentation

◆ PW_MAP_INIT

#define PW_MAP_INIT (   extend)    (struct pw_map) { PW_ARRAY_INIT(extend), SPA_ID_INVALID }

◆ pw_map_get_size

#define pw_map_get_size (   m)    pw_array_get_len(&(m)->items, union pw_map_item)

◆ pw_map_get_item

#define pw_map_get_item (   m,
  id 
)    pw_array_get_unchecked(&(m)->items,id,union pw_map_item)

◆ pw_map_item_is_free

#define pw_map_item_is_free (   item)    ((item)->next & 0x1)

◆ pw_map_id_is_free

#define pw_map_id_is_free (   m,
  id 
)    (pw_map_item_is_free(pw_map_get_item(m,id)))

◆ pw_map_check_id

#define pw_map_check_id (   m,
  id 
)    ((id) < pw_map_get_size(m))

◆ pw_map_has_item

#define pw_map_has_item (   m,
  id 
)    (pw_map_check_id(m,id) && !pw_map_id_is_free(m, id))

◆ pw_map_lookup_unchecked

#define pw_map_lookup_unchecked (   m,
  id 
)    pw_map_get_item(m,id)->data

◆ PW_MAP_ID_TO_PTR

#define PW_MAP_ID_TO_PTR (   id)    (SPA_UINT32_TO_PTR((id)<<1))

Convert an id to a pointer that can be inserted into the map.

◆ PW_MAP_PTR_TO_ID

#define PW_MAP_PTR_TO_ID (   p)    (SPA_PTR_TO_UINT32(p)>>1)

Convert a pointer to an id that can be retrieved from the map.

Function Documentation

◆ pw_map_init()

static void pw_map_init ( struct pw_map map,
size_t  size,
size_t  extend 
)
inlinestatic

Initialize a map.

Parameters
mapthe map to initialize
sizethe initial size of the map
extendthe amount to bytes to grow the map with when needed

◆ pw_map_clear()

static void pw_map_clear ( struct pw_map map)
inlinestatic

Clear a map.

Parameters
mapthe map to clear

◆ pw_map_reset()

static void pw_map_reset ( struct pw_map map)
inlinestatic

◆ pw_map_insert_new()

static uint32_t pw_map_insert_new ( struct pw_map map,
void *  data 
)
inlinestatic

Insert data in the map.

Parameters
mapthe map to insert into
datathe item to add
Returns
the id where the item was inserted or SPA_ID_INVALID when the item can not be inserted.

◆ pw_map_insert_at()

static int pw_map_insert_at ( struct pw_map map,
uint32_t  id,
void *  data 
)
inlinestatic

Insert data in the map at an index.

Parameters
mapthe map to inser into
idthe index to insert at
datathe data to insert
Returns
0 on success, -ENOSPC value when the index is invalid or a < 0 errno value.

◆ pw_map_remove()

static void pw_map_remove ( struct pw_map map,
uint32_t  id 
)
inlinestatic

Remove an item at index.

Parameters
mapthe map to remove from
idthe index to remove

◆ pw_map_lookup()

static void* pw_map_lookup ( struct pw_map map,
uint32_t  id 
)
inlinestatic

Find an item in the map.

Parameters
mapthe map to use
idthe index to look at
Returns
the item at id or NULL when no such item exists

◆ pw_map_for_each()

static int pw_map_for_each ( struct pw_map map,
int(*)(void *item_data, void *data)  func,
void *  data 
)
inlinestatic

Iterate all map items.

Parameters
mapthe map to iterate
functhe function to call for each item, the item data and data is passed to the function. When func returns a non-zero result, iteration ends and the result is returned.
datadata to pass to func
Returns
the result of the last call to func or 0 when all callbacks returned 0.