cxdeque.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_DEQUE_H
#define CX_DEQUE_H
#include "cxtypes.h"
CX_BEGIN_DECLS
typedef struct _cx_deque_ cx_deque;
typedef cxsize cx_deque_const_iterator;
typedef cxsize cx_deque_iterator;
/*
* Create, copy and destroy operations
*/
cx_deque *cx_deque_new(void);
void cx_deque_delete(cx_deque *deque);
void cx_deque_destroy(cx_deque *deque, cx_free_func deallocate);
/*
* Non-modifying operations
*/
cxsize cx_deque_size(const cx_deque *deque);
cxbool cx_deque_empty(const cx_deque *deque);
cxsize cx_deque_max_size(const cx_deque *deque);
/*
* Assignment operations
*/
void cx_deque_swap(cx_deque *deque, cx_deque *other);
cxptr cx_deque_assign(cx_deque *deque, cx_deque_iterator position, cxptr data);
/*
* Element access
*/
cxptr cx_deque_front(const cx_deque *deque);
cxptr cx_deque_back(const cx_deque *deque);
cxptr cx_deque_get(const cx_deque *deque, cx_deque_const_iterator position);
/*
* Iterator functions
*/
cx_deque_iterator cx_deque_begin(const cx_deque *deque);
cx_deque_iterator cx_deque_end(const cx_deque *deque);
cx_deque_iterator cx_deque_next(const cx_deque *deque,
cx_deque_const_iterator position);
cx_deque_iterator cx_deque_previous(const cx_deque *deque,
cx_deque_const_iterator position);
/*
* Inserting and removing elements
*/
void cx_deque_push_front(cx_deque *deque, cxcptr data);
cxptr cx_deque_pop_front(cx_deque *deque);
void cx_deque_push_back(cx_deque *deque, cxcptr data);
cxptr cx_deque_pop_back(cx_deque *deque);
cx_deque_iterator cx_deque_insert(cx_deque *deque, cx_deque_iterator position,
cxcptr data);
cx_deque_iterator cx_deque_erase(cx_deque *deque, cx_deque_iterator position,
cx_free_func deallocate);
void cx_deque_clear(cx_deque *deque);
/*
* Extra deque interfaces
*/
/*
* Removing elements
*/
cxptr cx_deque_extract(cx_deque *deque, cx_deque_iterator position);
void cx_deque_remove(cx_deque *deque, cxcptr data);
/*
* Splice functions
*/
void cx_deque_unique(cx_deque *deque, cx_compare_func compare);
void cx_deque_splice(cx_deque *deque, cx_deque_iterator position,
cx_deque *other, cx_deque_iterator start,
cx_deque_iterator end);
void cx_deque_merge(cx_deque *deque, cx_deque *other, cx_compare_func compare);
void cx_deque_sort(cx_deque *deque, cx_compare_func compare);
void cx_deque_reverse(cx_deque *deque);
CX_END_DECLS
#endif /* CX_DEQUE_H */
cx_deque_remove
void cx_deque_remove(cx_deque *deque, cxcptr data)
Remove all elements with a given value from a deque.
Definition cxdeque.c:1346
cx_deque_swap
void cx_deque_swap(cx_deque *deque, cx_deque *other)
Swap the data of two deques.
Definition cxdeque.c:859
cx_deque_erase
cx_deque_iterator cx_deque_erase(cx_deque *deque, cx_deque_iterator position, cx_free_func deallocate)
Erase a deque element.
Definition cxdeque.c:1261
cx_deque_end
cx_deque_iterator cx_deque_end(const cx_deque *deque)
Get an iterator for the position after the last deque element.
Definition cxdeque.c:1021
cx_deque_pop_front
cxptr cx_deque_pop_front(cx_deque *deque)
Remove the first deque element.
Definition cxdeque.c:1126
cx_deque_unique
void cx_deque_unique(cx_deque *deque, cx_compare_func compare)
Remove duplicates of consecutive elements.
Definition cxdeque.c:1387
cx_deque_insert
cx_deque_iterator cx_deque_insert(cx_deque *deque, cx_deque_iterator position, cxcptr data)
Insert data into a deque at a given iterator position.
Definition cxdeque.c:1221
cx_deque_get
cxptr cx_deque_get(const cx_deque *deque, cx_deque_const_iterator position)
Retrieve an element from a deque.
Definition cxdeque.c:975
cx_deque_back
cxptr cx_deque_back(const cx_deque *deque)
Get the last element of a deque.
Definition cxdeque.c:950
cx_deque_splice
void cx_deque_splice(cx_deque *deque, cx_deque_iterator position, cx_deque *other, cx_deque_iterator start, cx_deque_iterator end)
Move a range of elements in front of a given position.
Definition cxdeque.c:1434
cx_deque_pop_back
cxptr cx_deque_pop_back(cx_deque *deque)
Remove the last deque element.
Definition cxdeque.c:1193
cx_deque_size
cxsize cx_deque_size(const cx_deque *deque)
Get the actual number of deque elements.
Definition cxdeque.c:797
cx_deque_clear
void cx_deque_clear(cx_deque *deque)
Remove all elements from a deque.
Definition cxdeque.c:1298
cx_deque_push_back
void cx_deque_push_back(cx_deque *deque, cxcptr data)
Append data at the end of a deque.
Definition cxdeque.c:1154
cx_deque_merge
void cx_deque_merge(cx_deque *deque, cx_deque *other, cx_compare_func compare)
Merge two sorted deques.
Definition cxdeque.c:1484
cx_deque_previous
cx_deque_iterator cx_deque_previous(const cx_deque *deque, cx_deque_const_iterator position)
Get an iterator for the previous deque element.
Definition cxdeque.c:1067
cx_deque_reverse
void cx_deque_reverse(cx_deque *deque)
Reverse the order of all deque elements.
Definition cxdeque.c:1536
cx_deque_max_size
cxsize cx_deque_max_size(const cx_deque *deque)
Get the maximum number of deque elements possible.
Definition cxdeque.c:837
cx_deque_assign
cxptr cx_deque_assign(cx_deque *deque, cx_deque_iterator position, cxptr data)
Assign data to a deque element.
Definition cxdeque.c:900
cx_deque_destroy
void cx_deque_destroy(cx_deque *deque, cx_free_func deallocate)
Destroy a deque and all its elements.
Definition cxdeque.c:765
cx_deque_new
cx_deque * cx_deque_new(void)
Create a new deque without any elements.
Definition cxdeque.c:717
cx_deque_extract
cxptr cx_deque_extract(cx_deque *deque, cx_deque_iterator position)
Extract a deque element.
Definition cxdeque.c:1321
cx_deque_sort
void cx_deque_sort(cx_deque *deque, cx_compare_func compare)
Sort all elements of a deque using the given comparison function.
Definition cxdeque.c:1514
cx_deque_next
cx_deque_iterator cx_deque_next(const cx_deque *deque, cx_deque_const_iterator position)
Get an iterator for the next deque element.
Definition cxdeque.c:1044
cx_deque_empty
cxbool cx_deque_empty(const cx_deque *deque)
Check whether a deque is empty.
Definition cxdeque.c:817
cx_deque_delete
void cx_deque_delete(cx_deque *deque)
Destroy a deque.
Definition cxdeque.c:739
cx_deque_begin
cx_deque_iterator cx_deque_begin(const cx_deque *deque)
Get an iterator for the first deque element.
Definition cxdeque.c:1000
cx_deque_front
cxptr cx_deque_front(const cx_deque *deque)
Get the first element of a deque.
Definition cxdeque.c:928
cx_deque_push_front
void cx_deque_push_front(cx_deque *deque, cxcptr data)
Insert data at the beginning of a deque.
Definition cxdeque.c:1093