S2OPC OPCUA Toolkit
Loading...
Searching...
No Matches
sopc_dict.h
Go to the documentation of this file.
1/*
2 * Licensed to Systerel under one or more contributor license
3 * agreements. See the NOTICE file distributed with this work
4 * for additional information regarding copyright ownership.
5 * Systerel licenses this file to you under the Apache
6 * License, Version 2.0 (the "License"); you may not use this
7 * file except in compliance with the License. You may obtain
8 * a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
25#ifndef SOPC_DICT_H_
26#define SOPC_DICT_H_
27
28#include <stdbool.h>
29#include <stddef.h>
30#include <stdint.h>
31
32typedef struct _SOPC_Dict SOPC_Dict;
33
37typedef void SOPC_Dict_Free_Fct(uintptr_t data);
38
42typedef uint64_t SOPC_Dict_KeyHash_Fct(const uintptr_t data);
43
49typedef bool SOPC_Dict_KeyEqual_Fct(const uintptr_t a, const uintptr_t b);
50
56typedef void SOPC_Dict_ForEach_Fct(const uintptr_t key, uintptr_t value, uintptr_t user_data);
57
75SOPC_Dict* SOPC_Dict_Create(uintptr_t empty_key,
76 SOPC_Dict_KeyHash_Fct* key_hash,
77 SOPC_Dict_KeyEqual_Fct* key_equal,
78 SOPC_Dict_Free_Fct* key_free,
79 SOPC_Dict_Free_Fct* value_free);
80
90
98bool SOPC_Dict_Reserve(SOPC_Dict* d, size_t n_items);
99
116void SOPC_Dict_SetTombstoneKey(SOPC_Dict* d, uintptr_t tombstone_key);
117
130bool SOPC_Dict_Insert(SOPC_Dict* d, uintptr_t key, uintptr_t value);
131
142uintptr_t SOPC_Dict_Get(const SOPC_Dict* d, const uintptr_t key, bool* found);
143
158uintptr_t SOPC_Dict_GetKey(const SOPC_Dict* d, const uintptr_t key, bool* found);
159
168void SOPC_Dict_Remove(SOPC_Dict* d, const uintptr_t key);
169
177
184
192
199
205size_t SOPC_Dict_Size(const SOPC_Dict* d);
206
216
229void SOPC_Dict_ForEach(SOPC_Dict* d, SOPC_Dict_ForEach_Fct* func, uintptr_t user_data);
230
231#endif /* SOPC_DICT_H_ */
void SOPC_Dict_SetValueFreeFunc(SOPC_Dict *d, SOPC_Dict_Free_Fct *func)
Sets the free function for this dictionary's values.
bool SOPC_Dict_KeyEqual_Fct(const uintptr_t a, const uintptr_t b)
Type of functions used when checking two keys for equality. The function should return TRUE if and on...
Definition sopc_dict.h:49
SOPC_Dict_Free_Fct * SOPC_Dict_GetKeyFreeFunc(const SOPC_Dict *d)
Retrieves the free function for this dictionary's keys.
void SOPC_Dict_Free_Fct(uintptr_t data)
Type of functions used to free keys and values.
Definition sopc_dict.h:37
void SOPC_Dict_ForEach_Fct(const uintptr_t key, uintptr_t value, uintptr_t user_data)
Type of callback functions for SOPC_Dict_ForEach. Both the key and value belong to the dictionary....
Definition sopc_dict.h:56
size_t SOPC_Dict_Capacity(const SOPC_Dict *d)
Returns the number if items this dictionary can hold.
void SOPC_Dict_Delete(SOPC_Dict *d)
Deletes a dictionary.
void SOPC_Dict_ForEach(SOPC_Dict *d, SOPC_Dict_ForEach_Fct *func, uintptr_t user_data)
Iterates over the dictionary, calling the given function for each (key, value) pair.
struct _SOPC_Dict SOPC_Dict
Definition sopc_dict.h:32
bool SOPC_Dict_Insert(SOPC_Dict *d, uintptr_t key, uintptr_t value)
Inserts a new key and value in the dictionary.
uint64_t SOPC_Dict_KeyHash_Fct(const uintptr_t data)
Type of hash functions.
Definition sopc_dict.h:42
SOPC_Dict_Free_Fct * SOPC_Dict_GetValueFreeFunc(const SOPC_Dict *d)
Retrieves the free function for this dictionary's values.
SOPC_Dict * SOPC_Dict_Create(uintptr_t empty_key, SOPC_Dict_KeyHash_Fct *key_hash, SOPC_Dict_KeyEqual_Fct *key_equal, SOPC_Dict_Free_Fct *key_free, SOPC_Dict_Free_Fct *value_free)
Creates a new, empty dictionary.
uintptr_t SOPC_Dict_GetKey(const SOPC_Dict *d, const uintptr_t key, bool *found)
Looks up a given key in the dictionary.
bool SOPC_Dict_Reserve(SOPC_Dict *d, size_t n_items)
Reserve space for a given number of items in a dictionary.
size_t SOPC_Dict_Size(const SOPC_Dict *d)
Returns the number of items in this dictionary.
uintptr_t SOPC_Dict_Get(const SOPC_Dict *d, const uintptr_t key, bool *found)
Looks up the value associated with a key in the dictionary.
void SOPC_Dict_SetKeyFreeFunc(SOPC_Dict *d, SOPC_Dict_Free_Fct *func)
Sets the free function for this dictionary's keys.
void SOPC_Dict_Remove(SOPC_Dict *d, const uintptr_t key)
Removes a values from the dictionary.
void SOPC_Dict_SetTombstoneKey(SOPC_Dict *d, uintptr_t tombstone_key)
Set the key used to mark removed values.