-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjts_list.h
65 lines (53 loc) · 1.6 KB
/
jts_list.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#define dequeue(l) pop(l)
typedef struct Node{
void* d;
struct Node* next;
} node;
typedef struct List{
uintmax_t total;
struct Node* head;
struct Node* tail;
} list;
list *new_list(void);
/* Dynamically allocate a list.
* Returns a NULL list pointer if it cannot allocate a new list.
*/
void free_list(list* l);
/* Loop through the list, freeing any nodes.
* Then, free the list struct itself.
* Should be safe to call on a NULL list pointer.
*/
void *pop(list* l);
/* Remove a list item,
* return a pointer to the data that
* the list node contained.
* You must free the data that is returned.
*/
void push(list* l, const size_t size, const void *restrict data);
/* Prepend a list with a new list item.
*/
void enqueue(list* l, size_t size, void* data);
/* Append to a list with a new list item.
*/
list *argvtol(const int argc, char **argv);
/* Return a list of characters containing argv where
* there are spaces as delimiters for the argv strings.
* You must free the list that is returned.
*/
list* map_inplace(list *l, void (*fp)(void *));
/* input: list
* input: callback function that gets applied to each element of the list
* output: pointer to the same list as the input
*/
list* filter_inplace(list *l, int (*is_true)(void *));
/* input: list
* input: callback function that gets applied to each element of the list
* output: pointer to the same list as the input
*/
list* map(list *l, int (*compar)(const void *, const void *));
list* filter(list *l, int (*compar)(const void *, const void *));