-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkey_list.h
More file actions
67 lines (52 loc) · 1.68 KB
/
key_list.h
File metadata and controls
67 lines (52 loc) · 1.68 KB
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
/*
* COPYRIGHT NOTICE
* Copyright (C) 2015, Jhuster, All Rights Reserved
* Author: Jhuster(lujun.hust@gmail.com)
*
* https://github.com/Jhuster/TLV
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License,
* or (at your option) any later version.
*/
#ifndef _KEY_LIST_H_
#define _KEY_LIST_H_
#ifdef __cplusplus
extern "C" {
#else
#endif /* __cplusplus */
#include <stdlib.h>
typedef struct _value {
void *value;
} value_t;
typedef int key_t;
typedef void (*value_releaser)(value_t value);
#define key_compare(a, b) ((a==b)?1:0)
typedef struct key_list_node {
key_t key;
value_t value;
struct key_list_node *prev;
struct key_list_node *next;
} key_list_node_t;
typedef struct key_list {
int count;
key_list_node_t *header;
value_releaser releaser;
} key_list_t;
key_list_t *key_list_create(value_releaser releaser);
int key_list_destroy(key_list_t *list);
int key_list_count(key_list_t *list);
int key_list_keyset(key_list_t *list, key_t* array, int array_size);
int key_list_find_key(key_list_t *list, key_t key);
int key_list_add(key_list_t *list, key_t key, value_t value);
int key_list_get(key_list_t *list, key_t key, value_t *value);
int key_list_edit(key_list_t *list, key_t key, value_t value);
int key_list_delete(key_list_t *list, key_t key);
#define key_list_foreach(L,V) key_list_node_t *_node = NULL;\
key_list_node_t* V;\
for (V = _node = L->header; _node != NULL; V = _node = _node->next)
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif