-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.h
55 lines (31 loc) · 759 Bytes
/
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
#ifndef LIST_H
#define LIST_H
#include <stddef.h>
#include <stdlib.h>
#include <stdbool.h>
// A list node
typedef struct node {
struct node* next;
void* data;
} node;
// node constructor
node* new_node(node* next, void* data);
// A singly linked list
typedef struct {
node* head;
size_t count;
} list;
// Empty list constructor
list* nil();
#define is_empty(l) ((l)->count == 0)
void cons(void* data, list* l);
// Remove the front element
void* snoc(list* l);
// The type of equivalence relations
typedef bool (*eq_rel)(void const*, void const*);
// Find the first equivalent element to a given one
void* find_list(list const* l, void* data, eq_rel eq_fn);
// Destructor
// TODO
void destroy_list(list** lpp);
#endif // LIST_H