blob: 6b0f20929ebb69acf5c6444c8785275dac5a056e (
plain)
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
|
/*
* This file is part of libdom test suite.
* Licensed under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
* Copyright 2007 James Shaw <jshaw@netsurf-browser.org>
*/
#ifndef list_h_
#define list_h_
#include <stdbool.h>
#include "comparators.h"
/* The element type in the list
*
* The high byte is used for category type
* The low byte is used for concrete type
*/
typedef enum TYPE {
INT = 0x0001,
STRING = 0x0100,
DOM_STRING = 0x0101,
NODE = 0x0200
} TYPE;
struct list_elt {
void* data;
struct list_elt* next;
};
typedef struct list {
unsigned int size;
TYPE type;
struct list_elt* head;
struct list_elt* tail;
} list;
struct list* list_new(TYPE type);
void list_destroy(struct list* list);
/**
* Add data to the tail of the list.
*/
void list_add(struct list* list, void* data);
/**
* Remove element containing data from list.
* The list element is freed, but the caller must free the data itself
* if necessary.
*
* Returns true if data was found in the list.
*/
bool list_remove(struct list* list, void* data);
struct list* list_clone(struct list* list);
/**
* Tests if data is equal to any element in the list.
*/
bool list_contains(struct list* list, void* data,
comparator comparator);
/**
* Tests if superlist contains all elements in sublist. Order is not important.
*/
bool list_contains_all(struct list* superList, struct list* subList,
comparator comparator);
#endif
|