blob: f1021532486700a33ea887f79e530129dc6ae103 (
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _BH_LIST_H
#define _BH_LIST_H
#ifdef __cplusplus
extern "C" {
#endif
#include "bh_platform.h"
/* List user should embedded bh_list_link into list elem data structure
* definition. And bh_list_link data field should be the first field.
* For example, if we would like to use bh_list for our own data type A,
* A must be defined as a structure like below:
* struct A {
* bh_list_link l;
* ...
* };
*
* bh_list_link is defined as a structure (not typedef void*).
* It will make extend list into bi-direction easy.
*/
typedef struct bh_list_link {
struct bh_list_link *next;
} bh_list_link;
typedef struct bh_list {
bh_list_link head;
uint32 len;
} bh_list;
/* list operation return value */
typedef enum bh_list_status {
BH_LIST_SUCCESS = 0,
BH_LIST_ERROR = -1
} bh_list_status;
/**
* Initialize a list.
*
* @param list pointer to list.
* @return <code>BH_LIST_ERROR</code> if OK;
* <code>BH_LIST_ERROR</code> if list pointer is NULL.
*/
bh_list_status
bh_list_init(bh_list *list);
/**
* Insert an elem pointer into list. The list node memory is maintained by list
* while elem memory is the responsibility of list user.
*
* @param list pointer to list.
* @param elem pointer to elem that will be inserted into list.
* @return <code>BH_LIST_ERROR</code> if OK;
* <code>BH_LIST_ERROR</code> if input is invalid or no memory
* available.
*/
bh_list_status
bh_list_insert(bh_list *list, void *elem);
/**
* Remove an elem pointer from list. The list node memory is maintained by list
* while elem memory is the responsibility of list user.
*
* @param list pointer to list.
* @param elem pointer to elem that will be inserted into list.
* @return <code>BH_LIST_ERROR</code> if OK;
* <code>BH_LIST_ERROR</code> if element does not exist in given
* list.
*/
bh_list_status
bh_list_remove(bh_list *list, void *elem);
/**
* Get the list length.
*
* @param list pointer to list.
* @return the length of the list.
*/
uint32
bh_list_length(bh_list *list);
/**
* Get the first elem in the list.
*
* @param list pointer to list.
* @return pointer to the first node.
*/
void *
bh_list_first_elem(bh_list *list);
/**
* Get the next elem of given list input elem.
*
* @param node pointer to list node.
* @return pointer to next list node.
*/
void *
bh_list_elem_next(void *node);
#ifdef __cplusplus
}
#endif
#endif /* #ifndef _BH_LIST_H */
|