ucx
UAP Common Extensions
Loading...
Searching...
No Matches
kv_list.h
Go to the documentation of this file.
1/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2025 Mike Becker, Olaf Wintermann All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
35
36#ifndef UCX_KV_LIST_H
37#define UCX_KV_LIST_H
38
39#include "common.h"
40#include "list.h"
41#include "map.h"
42
64 size_t elem_size);
65
86 size_t elem_size);
87
96
105
120int cx_kv_list_set_key(CxList *list, size_t index, CxHashKey key);
121
134int cx_kv_list_insert(CxList *list, size_t index, CxHashKey key, void *value);
135
149#define cxKvListSetKey(list, index, key) cx_kv_list_set_key(list, index, CX_HASH_KEY(key))
150
162#define cxKvListInsert(list, index, key, value) cx_kv_list_insert(list, index, CX_HASH_KEY(key), value)
163
177int cxKvListRemoveKey(CxList *list, size_t index);
178
187const CxHashKey *cxKvListGetKey(CxList *list, size_t index);
188
198#define cxKvListAdd(list, key, value) cxKvListInsert(list, (list)->collection.size, key, value)
199
200#endif // UCX_KV_LIST_H
struct cx_allocator_s CxAllocator
High-Level type alias for the allocator type.
Definition allocator.h:80
Common definitions and feature checks.
#define CX_MALLOC
The attributed function always returns freshly allocated memory.
Definition common.h:156
#define CX_DEALLOC(...)
Not supported in clang.
Definition common.h:172
#define CX_NONNULL
All pointer arguments must be non-NULL.
Definition common.h:141
#define CX_NODISCARD
Warn about discarded return value.
Definition common.h:256
#define CX_RETURNS_NONNULL
The returned value is guaranteed to be non-NULL.
Definition common.h:151
#define CX_EXTERN
Declares a function with external linkage.
Definition common.h:297
struct cx_hash_key_s CxHashKey
Type for a hash key.
Definition hash_key.h:61
int cx_kv_list_insert(CxList *list, size_t index, CxHashKey key, void *value)
Inserts an item into the list at the specified index and associates it with the specified key.
CxList * cxKvListCreate(const CxAllocator *allocator, size_t elem_size)
Allocates a linked list with a lookup-map for storing elements with elem_size bytes each.
int cxKvListRemoveKey(CxList *list, size_t index)
Removes the key of a list item.
const CxHashKey * cxKvListGetKey(CxList *list, size_t index)
Returns the key of a list item.
CxMap * cxKvListCreateAsMap(const CxAllocator *allocator, size_t elem_size)
Allocates a linked list with a lookup-map for storing elements with elem_size bytes each.
CxList * cxKvListAsList(CxMap *map)
Converts a map pointer belonging to a key-value-List back to the original list pointer.
int cx_kv_list_set_key(CxList *list, size_t index, CxHashKey key)
Sets or updates the key of a list item.
CxMap * cxKvListAsMap(CxList *list)
Converts a map pointer belonging to a key-value-List back to the original list pointer.
Interface for list implementations.
struct cx_list_s CxList
Common type for all list implementations.
Definition list.h:179
void cxListFree(CxList *list)
Deallocates the memory of the specified list structure.
Interface for map implementations.
void cxMapFree(CxMap *map)
Deallocates the memory of the specified map.
struct cx_map_s CxMap
Type for the UCX map.
Definition map.h:50