-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathslist.h
90 lines (62 loc) · 2.06 KB
/
slist.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef SLIST_H
#define SLIST_H
#include <stdbool.h>
#include <stddef.h>
#include "fn.h"
struct SList {
void *val;
struct SList *nex;
};
/*
* Lifecycle
*/
// clone the list, setting val pointers
struct SList *slist_shallow_clone(struct SList *head);
// free list
void slist_free(struct SList **head);
// free list and vals, NULL fn_free_val uses free()
void slist_free_vals(struct SList **head, fn_free_val);
/*
* Mutate
*/
// append val to a list
struct SList *slist_append(struct SList **head, void *val);
// remove an item, returning the val
void *slist_remove(struct SList **head, struct SList **item);
// remove items, NULL fn_equals is val pointer comparison
size_t slist_remove_all(struct SList **head, fn_equals, const void *b);
// remove items and free vals, NULL equals is val pointer comparison, NULL fn_free_val calls free()
size_t slist_remove_all_free(struct SList **head, fn_equals, const void *b, fn_free_val);
/*
* Access
*/
// val at position
void *slist_at(struct SList *head, size_t index);
// find
struct SList *slist_find(struct SList *head, fn_test);
// find a val
void *slist_find_val(struct SList *head, fn_test);
// find, NULL fn_equals is val pointer comparison
struct SList *slist_find_equal(struct SList *head, fn_equals, const void *b);
// find a val, NULL fn_equals is val pointer comparison
void *slist_find_equal_val(struct SList *head, fn_equals, const void *b);
/*
* Comparison
*/
// same length and every item equal in order, NULL fn_equals compares pointers
bool slist_equal(struct SList *a, struct SList *b, fn_equals);
/*
* Utility
*/
// sort into a new list
struct SList *slist_sort(struct SList *head, fn_less_than);
// move items between lists where from value equals b, NULL fn_equals does nothing
void slist_move(struct SList **to, struct SList **from, fn_equals, const void *b);
// move items between lists where from value equals b, NULL fn_equals does nothing
void slist_move(struct SList **to, struct SList **from, fn_equals, const void *b);
/*
* Info
*/
// length
size_t slist_length(struct SList *head);
#endif // SLIST_H