Loading...
Searching...
No Matches
Data Structures | Typedefs | Enumerations | Functions
listmap.h File Reference

Combined list and map utility (headers) More...

#include <glib.h>
Include dependency graph for listmap.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  imquic_listmap
 Utility that implements a list and a map at the same time. More...
 

Typedefs

typedef enum imquic_listmap_key imquic_listmap_key
 Type of keys for the map part, to figure out the hashing algorithm.
 
typedef struct imquic_listmap imquic_listmap
 Utility that implements a list and a map at the same time.
 

Enumerations

enum  imquic_listmap_key { IMQUIC_LISTMAP_NUMBER = 0 , IMQUIC_LISTMAP_STRING , IMQUIC_LISTMAP_NUMBER64 }
 Type of keys for the map part, to figure out the hashing algorithm. More...
 

Functions

imquic_listmapimquic_listmap_create (imquic_listmap_key type, GDestroyNotify destroy)
 Create a new imquic_listmap instance.
 
void imquic_listmap_destroy (imquic_listmap *lm)
 Destroy an existing imquic_listmap instance.
 
int imquic_listmap_prepend (imquic_listmap *lm, void *key, void *item)
 Add a new item at the beginning of a imquic_listmap instance.
 
int imquic_listmap_append (imquic_listmap *lm, void *key, void *item)
 Add a new item at the end of a imquic_listmap instance.
 
int imquic_listmap_remove (imquic_listmap *lm, void *key)
 Remove an item from a imquic_listmap instance.
 
int imquic_listmap_clear (imquic_listmap *lm)
 Remove all items from a imquic_listmap instance.
 
void * imquic_listmap_find (imquic_listmap *lm, void *key)
 Look for an item via its key.
 
gboolean imquic_listmap_contains (imquic_listmap *lm, void *item)
 Check if a listmap contains a certain item.
 
void imquic_listmap_traverse (imquic_listmap *lm)
 Start traversing a listmap in an ordered way from the start.
 
void * imquic_listmap_next (imquic_listmap *lm, gboolean *found)
 Get the next item from the listmap, assuming we're traversing.
 
void * imquic_listmap_prev (imquic_listmap *lm, gboolean *found)
 Get the previous item from the listmap, assuming we're traversing.
 

Detailed Description

Combined list and map utility (headers)

Author
Lorenzo Miniero loren.nosp@m.zo@m.nosp@m.eetec.nosp@m.ho.c.nosp@m.om

Implementation of a generic structure that contains properties both of a map and a linked list (with quick pointers to the head to work a bit like a queue, when appending). Mostly to be used for tracking in an efficient way resources that must be ordered, but also quickly accessed via a key (e.g., sent packets by packet number).

Typedef Documentation

◆ imquic_listmap

typedef struct imquic_listmap imquic_listmap

Utility that implements a list and a map at the same time.

◆ imquic_listmap_key

Type of keys for the map part, to figure out the hashing algorithm.

Enumeration Type Documentation

◆ imquic_listmap_key

Type of keys for the map part, to figure out the hashing algorithm.

Enumerator
IMQUIC_LISTMAP_NUMBER 

Generic number (up to 32-bits)

IMQUIC_LISTMAP_STRING 

String.

IMQUIC_LISTMAP_NUMBER64 

64-bit number

Function Documentation

◆ imquic_listmap_append()

int imquic_listmap_append ( imquic_listmap * lm,
void * key,
void * item )

Add a new item at the end of a imquic_listmap instance.

Note
Adding items to a listmap resets the traversing index
Parameters
lmThe imquic_listmap instance to append the item to
keyThe item key, for the map
itemThe item to add to the listmap
Returns
0 if successful, or a negative integer otherwise

◆ imquic_listmap_clear()

int imquic_listmap_clear ( imquic_listmap * lm)

Remove all items from a imquic_listmap instance.

Parameters
lmThe imquic_listmap instance to clear
Returns
0 if successful, or a negative integer otherwise

◆ imquic_listmap_contains()

gboolean imquic_listmap_contains ( imquic_listmap * lm,
void * item )

Check if a listmap contains a certain item.

Parameters
lmThe imquic_listmap instance to search
itemThe item to find
Returns
TRUE if found, or FALSE otherwise

◆ imquic_listmap_create()

imquic_listmap * imquic_listmap_create ( imquic_listmap_key type,
GDestroyNotify destroy )

Create a new imquic_listmap instance.

Parameters
typeThe imquic_listmap_key key type
destroyThe function to invoke when a stored item is removed
Returns
A pointer to a new imquic_listmap instance, or NULL otherwise

◆ imquic_listmap_destroy()

void imquic_listmap_destroy ( imquic_listmap * lm)

Destroy an existing imquic_listmap instance.

Parameters
lmThe imquic_listmap instance to destroy

◆ imquic_listmap_find()

void * imquic_listmap_find ( imquic_listmap * lm,
void * key )

Look for an item via its key.

Parameters
lmThe imquic_listmap instance to lookup
keyThe item key to lookup
Returns
A pointer to the item, if found, or NULL otherwise

◆ imquic_listmap_next()

void * imquic_listmap_next ( imquic_listmap * lm,
gboolean * found )

Get the next item from the listmap, assuming we're traversing.

Parameters
[in]lmThe imquic_listmap to get the next item from
[out]foundSet to TRUE if the item was found (to avoid ambiguities if the item itself is 0 or NULL)
Returns
A pointer to the item

◆ imquic_listmap_prepend()

int imquic_listmap_prepend ( imquic_listmap * lm,
void * key,
void * item )

Add a new item at the beginning of a imquic_listmap instance.

Note
Adding items to a listmap resets the traversing index
Parameters
lmThe imquic_listmap instance to prepend the item to
keyThe item key, for the map
itemThe item to add to the listmap
Returns
0 if successful, or a negative integer otherwise

◆ imquic_listmap_prev()

void * imquic_listmap_prev ( imquic_listmap * lm,
gboolean * found )

Get the previous item from the listmap, assuming we're traversing.

Parameters
[in]lmThe imquic_listmap to get the previous item from
[out]foundSet to TRUE if the item was found (to avoid ambiguities if the item itself is 0 or NULL)
Returns
A pointer to the item

◆ imquic_listmap_remove()

int imquic_listmap_remove ( imquic_listmap * lm,
void * key )

Remove an item from a imquic_listmap instance.

Note
Removing items from a listmap resets the traversing index
Parameters
lmThe imquic_listmap instance to remove the item from
keyThe key of the item to remove
Returns
0 if successful, or a negative integer otherwise

◆ imquic_listmap_traverse()

void imquic_listmap_traverse ( imquic_listmap * lm)

Start traversing a listmap in an ordered way from the start.

Note
This only resets the list: use imquic_listmap_traverse_next and imquic_listmap_traverse_prev to actually access the items
Parameters
lmThe imquic_listmap to start traversing