initial commit
This commit is contained in:
131
ds.h
Normal file
131
ds.h
Normal file
@ -0,0 +1,131 @@
|
||||
#ifndef _DS_LOADED
|
||||
#define _DS_LOADED
|
||||
|
||||
typedef struct _sll {
|
||||
struct _sll *next;
|
||||
void *data;
|
||||
} ds_sll_t;
|
||||
|
||||
typedef struct _dll {
|
||||
struct _dll *next;
|
||||
struct _dll *prev;
|
||||
void *data;
|
||||
} ds_dll_t;
|
||||
|
||||
typedef struct {
|
||||
ds_sll_t **data;
|
||||
unsigned data_len;
|
||||
} ds_hmp_t;
|
||||
|
||||
typedef struct {
|
||||
char *key;
|
||||
void *val;
|
||||
} _ds_hmp_kv_t;
|
||||
|
||||
#define ds_ll_foreach(t, ll) for (t *cur = ll; cur; cur = cur->next)
|
||||
|
||||
/**
|
||||
* @brief create a new allocated node for a singly linked list
|
||||
*
|
||||
* @param data the data you want to store
|
||||
* @return the node
|
||||
*/
|
||||
ds_sll_t *ds_sll_new_node(void *data);
|
||||
|
||||
/**
|
||||
* @brief create a new allocated node for a doubly linked list
|
||||
*
|
||||
* @param data the data you want to store
|
||||
* @return the node
|
||||
*/
|
||||
ds_dll_t *ds_dll_new_node(void *data);
|
||||
|
||||
/**
|
||||
* @brief data to insert into a singly linked list. This will use
|
||||
* ds_sll_new_node to create the node for you.
|
||||
*
|
||||
* @param ll singly linked list
|
||||
* @param data data you want to add
|
||||
*/
|
||||
void ds_sll_insert(ds_sll_t *ll, void *data);
|
||||
|
||||
/**
|
||||
* @brief data to insert into a doubly linked list. This will use
|
||||
* ds_sll_new_node to create the node for you.
|
||||
*
|
||||
* @param ll doubly linked list
|
||||
* @param data data you want to add
|
||||
*/
|
||||
void ds_dll_insert(ds_dll_t *ll, void *data);
|
||||
|
||||
/**
|
||||
* @brief remove an index from a singly linked list
|
||||
*
|
||||
* @param ll singly linked list
|
||||
* @param idx the node
|
||||
* @return the data in the node
|
||||
*/
|
||||
void *ds_sll_remove(ds_sll_t **ll, unsigned idx);
|
||||
|
||||
/**
|
||||
* @brief remove an index from a doubly linked list
|
||||
*
|
||||
* @param ll doubly linked list
|
||||
* @param idx the node
|
||||
* @return the data in the node
|
||||
*/
|
||||
void *ds_dll_remove(ds_dll_t **ll, unsigned idx);
|
||||
|
||||
/**
|
||||
* @brief initialize a new hashmap
|
||||
*
|
||||
* @param data_len the amount of slots in the array
|
||||
* @return the hashmap
|
||||
*/
|
||||
ds_hmp_t *ds_hmp_init(int data_len);
|
||||
|
||||
/**
|
||||
* @brief free all data allocated by ds_hmp_init and ds_hmp_insert
|
||||
*
|
||||
* @param hmp pointer to the hashmap
|
||||
*/
|
||||
void ds_hmp_free(ds_hmp_t **hmp);
|
||||
|
||||
/**
|
||||
* @brief generate a numerical hash from a given string. You shouldn't need to
|
||||
* use this, but it's available just incase.
|
||||
*
|
||||
* @param str
|
||||
* @return the hash
|
||||
*/
|
||||
int _ds_hmp_gen_hash(char *str);
|
||||
|
||||
/**
|
||||
* @brief insert data at key (which will be hashed using _ds_hmp_gen_hash). You
|
||||
* are responsible for freeing the key later.
|
||||
*
|
||||
* @param hmp the hashmap to insert into
|
||||
* @param key the key
|
||||
* @param data the data
|
||||
*/
|
||||
void ds_hmp_insert(ds_hmp_t *hmp, char *key, void *data);
|
||||
|
||||
/**
|
||||
* @brief get something from a hashmap using it's key
|
||||
*
|
||||
* @param hmp the hashmap
|
||||
* @param key the key where it's stored
|
||||
* @return the data stored at the key
|
||||
*/
|
||||
void *ds_hmp_get(ds_hmp_t *hmp, char *key);
|
||||
|
||||
/**
|
||||
* @brief remove something from a hashmap using it's key
|
||||
*
|
||||
* @param hmp the hashmap
|
||||
* @param key the key where it's stored
|
||||
* @return the data stored at the key
|
||||
*/
|
||||
void *ds_hmp_remove(ds_hmp_t *hmp, char *key);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user