Dillo v3.1.1-46-g8a360e32
Loading...
Searching...
No Matches
klist.c File Reference

A simple ADT for Key-Data pairs. More...

#include "klist.h"
Include dependency graph for klist.c:

Go to the source code of this file.

Functions

static int Klist_node_by_key_cmp (const void *Node, const void *key)
 Compare function for searching data by its key.
 
static int Klist_node_by_node_cmp (const void *Node1, const void *Node2)
 Compare function for searching data by node.
 
void * a_Klist_get_data (Klist_t *Klist, int Key)
 Return the data pointer for a given Key (or NULL if not found)
 
int a_Klist_insert (Klist_t **Klist, void *Data)
 Insert a data pointer and return a key for it.
 
void a_Klist_remove (Klist_t *Klist, int Key)
 Remove data by Key.
 
int a_Klist_length (Klist_t *Klist)
 Return the number of elements in the Klist.
 
void a_Klist_free (Klist_t **KlistPtr)
 Free a Klist.
 

Detailed Description

A simple ADT for Key-Data pairs.

NOTE: this ADT is not perfect. The possibility of holding a Key, after its data has been removed, long enough for the key-counter to reset and reuse the same key is very low, but EXISTS. So, the responsibility remains with the caller.

Definition in file klist.c.

Function Documentation

◆ a_Klist_free()

void a_Klist_free ( Klist_t **  KlistPtr)

Free a Klist.

Definition at line 110 of file klist.c.

References dFree(), dList_free(), dList_length(), dList_nth_data(), dList_remove_fast(), and Klist_t::List.

Referenced by a_Http_freeall().

◆ a_Klist_get_data()

◆ a_Klist_insert()

int a_Klist_insert ( Klist_t **  Klist,
void *  Data 
)

Insert a data pointer and return a key for it.

Definition at line 56 of file klist.c.

References a_Klist_get_data(), KlistNode_t::Data, dList_insert_sorted(), dList_new(), dNew, KlistNode_t::Key, and Klist_node_by_node_cmp().

Referenced by Dpi_conn_new(), Http_sock_new(), IO_ins(), Tls_conn_new(), and Tls_make_conn_key().

◆ a_Klist_length()

int a_Klist_length ( Klist_t Klist)

Return the number of elements in the Klist.

Definition at line 102 of file klist.c.

References dList_length(), and Klist_t::List.

Referenced by IO_del(), and IO_ins().

◆ a_Klist_remove()

void a_Klist_remove ( Klist_t Klist,
int  Key 
)

◆ Klist_node_by_key_cmp()

static int Klist_node_by_key_cmp ( const void *  Node,
const void *  key 
)
static

Compare function for searching data by its key.

Definition at line 27 of file klist.c.

References VOIDP2INT.

Referenced by a_Klist_get_data(), and a_Klist_remove().

◆ Klist_node_by_node_cmp()

static int Klist_node_by_node_cmp ( const void *  Node1,
const void *  Node2 
)
static

Compare function for searching data by node.

Definition at line 35 of file klist.c.

Referenced by a_Klist_insert().