C Standard Library Extensions  1.2.3
cxmap.h
1 /*
2  * This file is part of the ESO C Extension Library
3  * Copyright (C) 2001-2017 European Southern Observatory
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #ifndef CX_MAP_H
21 #define CX_MAP_H
22 
23 #include <cxmemory.h>
24 #include <cxtree.h>
25 
26 CX_BEGIN_DECLS
27 
38 typedef cx_tree cx_map;
39 
49 typedef cx_tree_iterator cx_map_iterator;
50 
61 typedef cx_tree_const_iterator cx_map_const_iterator;
62 
78 
79 /*
80  * Create, copy and destroy operations
81  */
82 
83 
84 cx_map *cx_map_new(cx_compare_func, cx_free_func, cx_free_func);
85 void cx_map_delete(cx_map *);
86 
87 /*
88  * Nonmodifying operations
89  */
90 
91 cxsize cx_map_size(const cx_map *);
92 cxbool cx_map_empty(const cx_map *);
93 cxsize cx_map_max_size(const cx_map *);
95 
96 /*
97  * Special search operations
98  */
99 
100 cxsize cx_map_count(const cx_map *, cxcptr);
101 cx_map_iterator cx_map_find(const cx_map *, cxcptr);
102 cx_map_iterator cx_map_lower_bound(const cx_map *, cxcptr);
103 cx_map_iterator cx_map_upper_bound(const cx_map *, cxcptr);
104 void cx_map_equal_range(const cx_map *, cxcptr, cx_map_iterator *,
105  cx_map_iterator *);
106 
107 /*
108  * Assignment operations
109  */
110 
111 void cx_map_swap(cx_map *, cx_map *);
112 cxptr cx_map_assign(cx_map *, cx_map_iterator, cxcptr);
113 cxptr cx_map_put(cx_map *, cxcptr, cxcptr);
114 
115 /*
116  * Element access
117  */
118 
121 cxptr cx_map_get(cx_map *, cxcptr);
122 
123 /*
124  * Iterator functions
125  */
126 
131 
132 
133 /*
134  * Inserting and removing elements
135  */
136 
137 cx_map_iterator cx_map_insert(cx_map *, cxcptr, cxcptr);
140 cxsize cx_map_erase(cx_map *, cxcptr);
141 void cx_map_clear(cx_map *);
142 
143 CX_END_DECLS
144 
145 #endif /* CX_MAP_H */
cx_tree_compare_func
cxbool(* cx_tree_compare_func)(cxcptr, cxcptr)
The tree's key comparison operator function.
Definition: cxtree.h:72
cx_tree_end
cx_tree_iterator cx_tree_end(const cx_tree *tree)
Get an iterator for the position after the last pair in the tree.
Definition: cxtree.c:1056
cx_map_insert
cx_map_iterator cx_map_insert(cx_map *map, cxcptr key, cxcptr data)
Attempt to insert data into a map.
Definition: cxmap.c:648
cx_tree_upper_bound
cx_tree_iterator cx_tree_upper_bound(const cx_tree *tree, cxcptr key)
Find the end of a subsequence.
Definition: cxtree.c:1557
cx_tree_equal_range
void cx_tree_equal_range(const cx_tree *tree, cxcptr key, cx_tree_iterator *begin, cx_tree_iterator *end)
Find a subsequence matching a given key.
Definition: cxtree.c:1588
cx_tree_find
cx_tree_iterator cx_tree_find(const cx_tree *tree, cxcptr key)
Locate an element in the tree.
Definition: cxtree.c:1499
cx_map_next
cx_map_iterator cx_map_next(const cx_map *map, cx_map_const_iterator position)
Get an iterator for the next pair in the map.
Definition: cxmap.c:110
cx_tree_next
cx_tree_iterator cx_tree_next(const cx_tree *tree, cx_tree_const_iterator position)
Get an iterator for the next pair in the tree.
Definition: cxtree.c:1083
cx_tree_get_value
cxptr cx_tree_get_value(const cx_tree *tree, cx_tree_const_iterator position)
Get the data from a given iterator position.
Definition: cxtree.c:1468
cx_map_previous
cx_map_iterator cx_map_previous(const cx_map *map, cx_map_const_iterator position)
Get an iterator for the previous pair in the map.
Definition: cxmap.c:135
cx_tree_lower_bound
cx_tree_iterator cx_tree_lower_bound(const cx_tree *tree, cxcptr key)
Find the beginning of a subsequence.
Definition: cxtree.c:1528
cx_map_clear
void cx_map_clear(cx_map *map)
Remove all pairs from a map.
Definition: cxmap.c:157
cx_tree_erase_position
void cx_tree_erase_position(cx_tree *tree, cx_tree_iterator position)
Erase an element from a tree.
Definition: cxtree.c:1715
cx_map_compare_func
cx_tree_compare_func cx_map_compare_func
The map's key comparison operator function.
Definition: cxmap.h:77
cx_map_put
cxptr cx_map_put(cx_map *map, cxcptr key, cxcptr data)
Set the value of a pair matching the given key.
Definition: cxmap.c:386
cx_map_count
cxsize cx_map_count(const cx_map *map, cxcptr key)
Get the number of elements matching a key.
Definition: cxmap.c:623
cx_tree_clear
void cx_tree_clear(cx_tree *tree)
Remove all pairs from a tree.
Definition: cxtree.c:1148
cx_tree_erase
cxsize cx_tree_erase(cx_tree *tree, cxcptr key)
Erase all elements from a tree matching the provided key.
Definition: cxtree.c:1785
cx_map_empty
cxbool cx_map_empty(const cx_map *map)
Check whether a map is empty.
Definition: cxmap.c:183
cx_tree_new
cx_tree * cx_tree_new(cx_tree_compare_func compare, cx_free_func key_destroy, cx_free_func value_destroy)
Create a new tree without any elements.
Definition: cxtree.c:1212
cx_map_get_key
cxptr cx_map_get_key(const cx_map *map, cx_map_const_iterator position)
Get the key from a given iterator position.
Definition: cxmap.c:426
cx_map_get_value
cxptr cx_map_get_value(const cx_map *map, cx_map_const_iterator position)
Get the data from a given iterator position.
Definition: cxmap.c:448
cx_map_delete
void cx_map_delete(cx_map *map)
Destroy a map and all its elements.
Definition: cxmap.c:246
cx_tree_previous
cx_tree_iterator cx_tree_previous(const cx_tree *tree, cx_tree_const_iterator position)
Get an iterator for the previous pair in the tree.
Definition: cxtree.c:1117
cx_map_begin
cx_map_iterator cx_map_begin(const cx_map *map)
Get an iterator to the first pair in a map.
Definition: cxmap.c:61
cx_map_end
cx_map_iterator cx_map_end(const cx_map *map)
Get an iterator for the position after the last pair in the map.
Definition: cxmap.c:85
cx_tree_begin
cx_tree_iterator cx_tree_begin(const cx_tree *tree)
Get an iterator to the first pair in the tree.
Definition: cxtree.c:1030
cx_map_size
cxsize cx_map_size(const cx_map *map)
Get the actual number of pairs in the map.
Definition: cxmap.c:267
cx_tree_key_comp
cx_tree_compare_func cx_tree_key_comp(const cx_tree *tree)
Get the key comparison function.
Definition: cxtree.c:1326
cx_tree_max_size
cxsize cx_tree_max_size(const cx_tree *tree)
Get the maximum number of pairs possible.
Definition: cxtree.c:1299
cx_map_assign
cxptr cx_map_assign(cx_map *map, cx_map_iterator position, cxcptr data)
Assign data to an iterator position.
Definition: cxmap.c:360
cx_map_erase
cxsize cx_map_erase(cx_map *map, cxcptr key)
Erase an element from a map according to the provided key.
Definition: cxmap.c:728
cx_map_find
cx_map_iterator cx_map_find(const cx_map *map, cxcptr key)
Locate an element in the map.
Definition: cxmap.c:505
cx_tree_insert_unique
cx_tree_iterator cx_tree_insert_unique(cx_tree *tree, cxcptr key, cxcptr data)
Attempt to insert data into a tree.
Definition: cxtree.c:1661
cx_map_key_comp
cx_map_compare_func cx_map_key_comp(const cx_map *map)
Retrieve a map's key comparison function.
Definition: cxmap.c:312
cx_map_const_iterator
cx_tree_const_iterator cx_map_const_iterator
The map constant iterator datatype.
Definition: cxmap.h:61
cx_map_iterator
cx_tree_iterator cx_map_iterator
The map iterator datatype.
Definition: cxmap.h:49
cx_map_equal_range
void cx_map_equal_range(const cx_map *map, cxcptr key, cx_map_iterator *begin, cx_map_iterator *end)
Find a subsequence matching a given key.
Definition: cxmap.c:600
cx_tree_erase_range
void cx_tree_erase_range(cx_tree *tree, cx_tree_iterator begin, cx_tree_iterator end)
Erase a range of elements from a tree.
Definition: cxtree.c:1749
cx_map_upper_bound
cx_map_iterator cx_map_upper_bound(const cx_map *map, cxcptr key)
Find the end of a subsequence matching a given key.
Definition: cxmap.c:571
cx_map_get
cxptr cx_map_get(cx_map *map, cxcptr key)
Get the data for a given key.
Definition: cxmap.c:473
cx_map_erase_range
void cx_map_erase_range(cx_map *map, cx_map_iterator begin, cx_map_iterator end)
Erase a range of elements from a map.
Definition: cxmap.c:698
cx_map_lower_bound
cx_map_iterator cx_map_lower_bound(const cx_map *map, cxcptr key)
Find the beginning of a subsequence matching a given key.
Definition: cxmap.c:535
cx_map
cx_tree cx_map
The map datatype.
Definition: cxmap.h:38
cx_tree_assign
cxptr cx_tree_assign(cx_tree *tree, cx_tree_iterator position, cxcptr data)
Assign data to an iterator position.
Definition: cxtree.c:1404
cx_tree_delete
void cx_tree_delete(cx_tree *tree)
Destroy a tree and all its elements.
Definition: cxtree.c:1250
cx_tree_get_key
cxptr cx_tree_get_key(const cx_tree *tree, cx_tree_const_iterator position)
Get the key from a given iterator position.
Definition: cxtree.c:1441
cx_map_erase_position
void cx_map_erase_position(cx_map *map, cx_map_iterator position)
Erase an element from a map.
Definition: cxmap.c:672
cx_tree_swap
void cx_tree_swap(cx_tree *tree1, cx_tree *tree2)
Swap the contents of two trees.
Definition: cxtree.c:1352
cx_tree_empty
cxbool cx_tree_empty(const cx_tree *tree)
Check whether a tree is empty.
Definition: cxtree.c:1176
cx_map_swap
void cx_map_swap(cx_map *map1, cx_map *map2)
Swap the contents of two maps.
Definition: cxmap.c:336
cx_tree_size
cxsize cx_tree_size(const cx_tree *tree)
Get the actual number of pairs in the tree.
Definition: cxtree.c:1276
cx_map_new
cx_map * cx_map_new(cx_map_compare_func compare, cx_free_func key_destroy, cx_free_func value_destroy)
Create a new map without any elements.
Definition: cxmap.c:218
cx_map_max_size
cxsize cx_map_max_size(const cx_map *map)
Get the maximum number of pairs possible.
Definition: cxmap.c:288