libgpac  0.5.0
Classes | Typedefs | Functions
map
utils

This section documents the map object of the GPAC framework. More...

Classes

struct  GF_Pair
 Pair structure. More...
struct  GF_Map
 Map Object. More...
struct  GF_Iterator
 Map iterator Object. More...

Typedefs

typedef struct _tag_map GF_Map
typedef struct _it_map GF_It_Map

Functions

GF_Mapgf_map_new (u32 hash_capacity)
 map constructor
void gf_map_del (GF_Map *ptr)
 map destructor
GF_Err gf_map_iter_new (GF_Map *map, GF_It_Map **it)
 map iterator constructor
void gf_map_iter_del (GF_It_Map *ptr)
 map iterator destructor
void * gf_map_iter_has_next (GF_It_Map *it)
 return the next value in the map
GF_Err gf_map_iter_reset (GF_It_Map *it)
 Reset the iterator in the map.
u32 gf_map_count (const GF_Map *ptr)
 get count
GF_Err gf_map_insert (GF_Map *ptr, const char *key, void *item)
 add item
Bool gf_map_rem (GF_Map *ptr, const char *key)
 removes the couple key/item from the map
void * gf_map_find (GF_Map *ptr, const char *key)
 finds item
Bool gf_map_has_key (GF_Map *ptr, const char *key)
 Check if map contains key.
void gf_map_reset (GF_Map *ptr)
 resets map

Detailed Description

Note:
The map use a random function for hashing. Collisions are resolved by using a GF_List on each slot.

Function Documentation

GF_Map* gf_map_new ( u32  hash_capacity)

Constructs a new map object

Parameters:
hash_capacitythe number of slot in the hash table
Note:
a zero hash_capacity is not allowed, a hash_capacity of 1 is equivalent to a gf_list_find from GF_List with a complexity search in o(n)
Returns:
new map object
void gf_map_del ( GF_Map ptr)

Destructs a map object

Parameters:
ptrmap object to destruct
Note:
The caller is only responsible to destroy the content of the map, not the key
GF_Err gf_map_iter_new ( GF_Map map,
GF_It_Map **  it 
)

Constructs a new map iterator object

Parameters:
mapthe map associated to the iterator
itthe resulting iterator
Returns:
GF_OK if iterator has been properly generated, otherwiise a GF_Err
void gf_map_iter_del ( GF_It_Map *  ptr)

Destructs a map iterator object

Parameters:
ptrmap iterator object to destruct
void* gf_map_iter_has_next ( GF_It_Map *  it)

Return the next value of a GF_Pair in the map

Parameters:
itthe map iterator object
Returns:
the next value of the map if exists, otherwise NULL
GF_Err gf_map_iter_reset ( GF_It_Map *  it)

Reinitalize the iterator to the beginning of the map

Parameters:
itthe map iterator object
Returns:
GF_OK if the iterator has been correctly reinitialize, otherwise a GF_Err
u32 gf_map_count ( const GF_Map ptr)

Returns number of items in the map

Parameters:
ptrtarget map object
Returns:
number of items in the map
GF_Err gf_map_insert ( GF_Map ptr,
const char *  key,
void *  item 
)

Adds an item in the map with an associated key

Parameters:
ptrtarget map object
keythe identified key
itemitem to add
Returns:
GF_OF if insertion occurs properly, GF_NOT_SUPPORTED if the key already exists, a GF_Err in other cases
Note:
the caller is responsible for the deallocation of the key as it is copyied in the map
Bool gf_map_rem ( GF_Map ptr,
const char *  key 
)

Removes an item from the map given to its key if exists

Parameters:
ptrtarget map object
keythe key of the item.
Returns:
GF_TRUE if the key has been delete, otherwise GF_FALSE
Note:
It is the caller responsability to destroy the content of the list if needed
void* gf_map_find ( GF_Map ptr,
const char *  key 
)

Finds a key in the map

Parameters:
ptrtarget map object.
keythe key to find.
Returns:
a pointer to the corresponding value if found, otherwise NULL.
Bool gf_map_has_key ( GF_Map ptr,
const char *  key 
)
Parameters:
ptrtarget map object.
keythe key to check.
Returns:
GF_TRUE if map contains keys, otherwise GF_FALSE
void gf_map_reset ( GF_Map ptr)

Resets the content of the map

Parameters:
ptrtarget map object.
Note:
It is the caller responsability to destroy the content of the list if needed