cxmap.h
/*
* This file is part of the ESO C Extension Library
* Copyright (C) 2001-2026 European Southern Observatory
*
* 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.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <https://www.gnu.org/licenses/>.
*/
#ifndef CX_MAP_H
#define CX_MAP_H
#include "cxtree.h"
#include "cxtypes.h"
CX_BEGIN_DECLS
typedef cx_tree cx_map;
typedef cx_tree_iterator cx_map_iterator;
typedef cx_tree_const_iterator cx_map_const_iterator;
typedef cx_tree_compare_func cx_map_compare_func;
/*
* Create, copy and destroy operations
*/
cx_map *cx_map_new(cx_compare_func, cx_free_func, cx_free_func);
void cx_map_delete(cx_map *);
/*
* Nonmodifying operations
*/
cxsize cx_map_size(const cx_map *);
cxbool cx_map_empty(const cx_map *);
cxsize cx_map_max_size(const cx_map *);
cx_map_compare_func cx_map_key_comp(const cx_map *);
/*
* Special search operations
*/
cxsize cx_map_count(const cx_map *, cxcptr);
cx_map_iterator cx_map_find(const cx_map *, cxcptr);
cx_map_iterator cx_map_lower_bound(const cx_map *, cxcptr);
cx_map_iterator cx_map_upper_bound(const cx_map *, cxcptr);
void cx_map_equal_range(const cx_map *, cxcptr, cx_map_iterator *,
cx_map_iterator *);
/*
* Assignment operations
*/
void cx_map_swap(cx_map *, cx_map *);
cxptr cx_map_assign(cx_map *, cx_map_iterator, cxcptr);
cxptr cx_map_put(cx_map *, cxcptr, cxcptr);
/*
* Element access
*/
cxptr cx_map_get_key(const cx_map *, cx_map_const_iterator);
cxptr cx_map_get_value(const cx_map *, cx_map_const_iterator);
cxptr cx_map_get(cx_map *, cxcptr);
/*
* Iterator functions
*/
cx_map_iterator cx_map_begin(const cx_map *);
cx_map_iterator cx_map_end(const cx_map *);
cx_map_iterator cx_map_next(const cx_map *, cx_map_const_iterator);
cx_map_iterator cx_map_previous(const cx_map *, cx_map_const_iterator);
/*
* Inserting and removing elements
*/
cx_map_iterator cx_map_insert(cx_map *, cxcptr, cxcptr);
void cx_map_erase_position(cx_map *, cx_map_iterator);
void cx_map_erase_range(cx_map *, cx_map_iterator, cx_map_iterator);
cxsize cx_map_erase(cx_map *, cxcptr);
void cx_map_clear(cx_map *);
CX_END_DECLS
#endif /* CX_MAP_H */
cx_map_next
cx_map_iterator cx_map_next(const cx_map *, cx_map_const_iterator)
Get an iterator for the next pair in the map.
Definition cxmap.c:105
cx_map_count
cxsize cx_map_count(const cx_map *, cxcptr)
Get the number of elements matching a key.
Definition cxmap.c:580
cx_map_begin
cx_map_iterator cx_map_begin(const cx_map *)
Get an iterator to the first pair in a map.
Definition cxmap.c:60
cx_map_erase_range
void cx_map_erase_range(cx_map *, cx_map_iterator, cx_map_iterator)
Erase a range of elements from a map.
Definition cxmap.c:649
cx_map_size
cxsize cx_map_size(const cx_map *)
Get the actual number of pairs in the map.
Definition cxmap.c:250
cx_map_erase_position
void cx_map_erase_position(cx_map *, cx_map_iterator)
Erase an element from a map.
Definition cxmap.c:625
cx_map_key_comp
cx_map_compare_func cx_map_key_comp(const cx_map *)
Retrieve a map's key comparison function.
Definition cxmap.c:291
cx_map_equal_range
void cx_map_equal_range(const cx_map *, cxcptr, cx_map_iterator *, cx_map_iterator *)
Find a subsequence matching a given key.
Definition cxmap.c:559
cx_map_get
cxptr cx_map_get(cx_map *, cxcptr)
Get the data for a given key.
Definition cxmap.c:439
cx_map_previous
cx_map_iterator cx_map_previous(const cx_map *, cx_map_const_iterator)
Get an iterator for the previous pair in the map.
Definition cxmap.c:128
cx_map_lower_bound
cx_map_iterator cx_map_lower_bound(const cx_map *, cxcptr)
Find the beginning of a subsequence matching a given key.
Definition cxmap.c:498
cx_map
cx_tree cx_map
The map datatype.
Definition cxmap.h:38
cx_map_assign
cxptr cx_map_assign(cx_map *, cx_map_iterator, cxcptr)
Assign data to an iterator position.
Definition cxmap.c:335
cx_map_max_size
cxsize cx_map_max_size(const cx_map *)
Get the maximum number of pairs possible.
Definition cxmap.c:269
cx_map_delete
void cx_map_delete(cx_map *)
Destroy a map and all its elements.
Definition cxmap.c:231
cx_map_const_iterator
cx_tree_const_iterator cx_map_const_iterator
The map constant iterator datatype.
Definition cxmap.h:61
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_upper_bound
cx_map_iterator cx_map_upper_bound(const cx_map *, cxcptr)
Find the end of a subsequence matching a given key.
Definition cxmap.c:532
cx_map_get_key
cxptr cx_map_get_key(const cx_map *, cx_map_const_iterator)
Get the key from a given iterator position.
Definition cxmap.c:396
cx_map_find
cx_map_iterator cx_map_find(const cx_map *, cxcptr)
Locate an element in the map.
Definition cxmap.c:470
cx_map_insert
cx_map_iterator cx_map_insert(cx_map *, cxcptr, cxcptr)
Attempt to insert data into a map.
Definition cxmap.c:603
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:205
cx_map_swap
void cx_map_swap(cx_map *, cx_map *)
Swap the contents of two maps.
Definition cxmap.c:313
cx_map_iterator
cx_tree_iterator cx_map_iterator
The map iterator datatype.
Definition cxmap.h:49
cx_map_empty
cxbool cx_map_empty(const cx_map *)
Check whether a map is empty.
Definition cxmap.c:172
cx_map_get_value
cxptr cx_map_get_value(const cx_map *, cx_map_const_iterator)
Get the data from a given iterator position.
Definition cxmap.c:416
cx_map_end
cx_map_iterator cx_map_end(const cx_map *)
Get an iterator for the position after the last pair in the map.
Definition cxmap.c:82
cx_map_erase
cxsize cx_map_erase(cx_map *, cxcptr)
Erase an element from a map according to the provided key.
Definition cxmap.c:676
cx_map_put
cxptr cx_map_put(cx_map *, cxcptr, cxcptr)
Set the value of a pair matching the given key.
Definition cxmap.c:359
cx_map_clear
void cx_map_clear(cx_map *)
Remove all pairs from a map.
Definition cxmap.c:148
cx_tree_compare_func
cxbool(* cx_tree_compare_func)(cxcptr, cxcptr)
The tree's key comparison operator function.
Definition cxtree.h:72