Debian Codegraph @

src/fcml_coll.h

raw
1 /*
2 * FCML - Free Code Manipulation Library.
3 * Copyright (C) 2010-2020 Slawomir Wojtasiak
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #ifndef FCML_COLL_H_
21 #define FCML_COLL_H_
22
23 #include <fcml_types.h>
24
25 #include "fcml_ceh.h"
26
27 /***********************/
28 /* Bidirectional List. */
29 /***********************/
30
31 typedef struct fcml_st_coll_list_element {
32 struct fcml_st_coll_list_element *prev;
33 struct fcml_st_coll_list_element *next;
34 fcml_ptr item;
35 } fcml_st_coll_list_element;
36
37 typedef struct fcml_st_coll_list {
38 struct fcml_st_coll_list_element *head;
39 struct fcml_st_coll_list_element *tail;
40 fcml_int32_t size;
41 } fcml_st_coll_list;
42
43 typedef void (*fcml_fp_coll_list_action)(fcml_ptr item_value, fcml_ptr args);
44
45 fcml_st_coll_list* fcml_fn_coll_list_alloc_with_args(fcml_ptr handler_args);
46
47 fcml_st_coll_list* fcml_fn_coll_list_alloc();
48
49 fcml_st_coll_list_element* fcml_fn_coll_list_add_front(fcml_st_coll_list *list,
50 const fcml_ptr item);
51
52 fcml_st_coll_list_element* fcml_fn_coll_list_add_back(fcml_st_coll_list *list,
53 const fcml_ptr item);
54
55 fcml_st_coll_list_element* fcml_fn_coll_list_insert(fcml_st_coll_list *list,
56 fcml_st_coll_list_element *prev_element, const fcml_ptr item);
57
58 void fcml_fn_coll_list_free(fcml_st_coll_list *list,
59 fcml_fp_coll_list_action item_handler,
60 const fcml_ptr item_handler_args);
61
62 /*************/
63 /* Hash Map. */
64 /*************/
65
66 #define FCML_COLL_ERROR_NO_ERROR 0x0000
67 #define FCML_COLL_ERROR_OUT_OF_MEMORY 0x0001
68 #define FCML_COLL_ERROR_MAP_FULL 0x0002
69 #define FCML_COLL_ERROR_BAD_ARGS 0x0003
70
71 #define FCML_COLL_MAP_DEFAULT_FACTOR 0.75
72
73 /* Hash & Equals for strings.*/
74
75 typedef void (*fcml_fnp_coll_map_entry_handler)(fcml_ptr key, fcml_ptr value,
76 fcml_ptr args);
77
78 typedef fcml_bool (*fcml_fnp_coll_map_entry_handler_if)(fcml_ptr key,
79 fcml_ptr value, fcml_ptr args);
80
81 typedef fcml_uint32_t (*fcml_fnp_coll_map_key_hash)(fcml_ptr key);
82
83 typedef fcml_bool (*fcml_fnp_coll_map_key_equals)(fcml_ptr key1, fcml_ptr key2);
84
85 typedef struct fcml_st_coll_map_descriptor {
86 fcml_fnp_coll_map_key_hash hash_function;
87 fcml_fnp_coll_map_key_equals equals_function;
88 fcml_fnp_coll_map_entry_handler entry_free_function;
89 fcml_ptr entry_free_args;
90 } fcml_st_coll_map_descriptor;
91
92 typedef fcml_ptr fcml_coll_map;
93
94 fcml_coll_map fcml_fn_coll_map_alloc(
95 const fcml_st_coll_map_descriptor *descriptor, fcml_uint32_t capacity,
96 fcml_int *error);
97
98 void fcml_fn_coll_map_put(fcml_coll_map map, const fcml_ptr key,
99 const fcml_ptr value, fcml_int *error);
100
101 fcml_ptr fcml_fn_coll_map_get(fcml_coll_map map, const fcml_ptr key);
102
103 fcml_uint32_t fcml_fn_coll_map_size(const fcml_coll_map map);
104
105 void fcml_fn_coll_map_clear(fcml_coll_map map);
106
107 void fcml_fn_coll_map_remove(fcml_coll_map map, const fcml_ptr key);
108
109 void fcml_fn_coll_map_remove_if(fcml_coll_map map,
110 fcml_fnp_coll_map_entry_handler_if item_handler,
111 const fcml_ptr item_handler_args);
112
113 void fcml_fn_coll_map_free(fcml_coll_map map);
114
115 extern fcml_st_coll_map_descriptor fcml_coll_map_descriptor_string;
116 extern fcml_st_coll_map_descriptor fcml_coll_map_descriptor_uint32;
117
118 #endif /* FCML_COLL_H_ */