aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/c-ares/src/lib/include/ares_htable_vpvp.h
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2024-10-19 17:59:18 +0000
committerAlexander Smirnov <alex@ydb.tech>2024-10-19 17:59:18 +0000
commitceddbfe68f6ec7949a4062716c8f9840a59c6888 (patch)
treeabfecadbb9c1e5aea40701dd20d902cb7bccd962 /contrib/libs/c-ares/src/lib/include/ares_htable_vpvp.h
parent07f2e60d02d95eab14a86a4b9469db1af7795001 (diff)
parentd920c750e476fa2dc80c45f990d9456b1afeadd1 (diff)
downloadydb-ceddbfe68f6ec7949a4062716c8f9840a59c6888.tar.gz
Merge branch 'rightlib' into mergelibs-241019-1758
Diffstat (limited to 'contrib/libs/c-ares/src/lib/include/ares_htable_vpvp.h')
-rw-r--r--contrib/libs/c-ares/src/lib/include/ares_htable_vpvp.h128
1 files changed, 128 insertions, 0 deletions
diff --git a/contrib/libs/c-ares/src/lib/include/ares_htable_vpvp.h b/contrib/libs/c-ares/src/lib/include/ares_htable_vpvp.h
new file mode 100644
index 0000000000..1ebe614576
--- /dev/null
+++ b/contrib/libs/c-ares/src/lib/include/ares_htable_vpvp.h
@@ -0,0 +1,128 @@
+/* MIT License
+ *
+ * Copyright (c) 2024 Brad House
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * SPDX-License-Identifier: MIT
+ */
+#ifndef __ARES__HTABLE_VPVP_H
+#define __ARES__HTABLE_VPVP_H
+
+/*! \addtogroup ares_htable_vpvp HashTable with void pointer Key and void
+ * pointer Value
+ *
+ * This data structure wraps the base ares_htable data structure in order to
+ * split the key and value data types as size_t and void pointer, respectively.
+ *
+ * Average time complexity:
+ * - Insert: O(1)
+ * - Search: O(1)
+ * - Delete: O(1)
+ *
+ * @{
+ */
+
+struct ares_htable_vpvp;
+
+/*! Opaque data type for size_t key, void pointer hash table implementation */
+typedef struct ares_htable_vpvp ares_htable_vpvp_t;
+
+/*! Callback to free key stored in hashtable
+ *
+ * \param[in] key user-supplied key
+ */
+typedef void (*ares_htable_vpvp_key_free_t)(void *key);
+
+/*! Callback to free value stored in hashtable
+ *
+ * \param[in] val user-supplied value
+ */
+typedef void (*ares_htable_vpvp_val_free_t)(void *val);
+
+/*! Destroy hashtable
+ *
+ * \param[in] htable Initialized hashtable
+ */
+CARES_EXTERN void ares_htable_vpvp_destroy(ares_htable_vpvp_t *htable);
+
+/*! Create size_t key, void pointer value hash table
+ *
+ * \param[in] key_free Optional. Call back to free user-supplied key. If
+ * NULL it is expected the caller will clean up any user
+ * supplied keys.
+ * \param[in] val_free Optional. Call back to free user-supplied value. If
+ * NULL it is expected the caller will clean up any user
+ * supplied values.
+ */
+CARES_EXTERN ares_htable_vpvp_t *
+ ares_htable_vpvp_create(ares_htable_vpvp_key_free_t key_free,
+ ares_htable_vpvp_val_free_t val_free);
+
+/*! Insert key/value into hash table
+ *
+ * \param[in] htable Initialized hash table
+ * \param[in] key key to associate with value
+ * \param[in] val value to store (takes ownership). May be NULL.
+ * \return ARES_TRUE on success, ARES_FALSE on failure or out of memory
+ */
+CARES_EXTERN ares_bool_t ares_htable_vpvp_insert(ares_htable_vpvp_t *htable,
+ void *key, void *val);
+
+/*! Retrieve value from hashtable based on key
+ *
+ * \param[in] htable Initialized hash table
+ * \param[in] key key to use to search
+ * \param[out] val Optional. Pointer to store value.
+ * \return ARES_TRUE on success, ARES_FALSE on failure
+ */
+CARES_EXTERN ares_bool_t ares_htable_vpvp_get(const ares_htable_vpvp_t *htable,
+ const void *key, void **val);
+
+/*! Retrieve value from hashtable directly as return value. Caveat to this
+ * function over ares_htable_vpvp_get() is that if a NULL value is stored
+ * you cannot determine if the key is not found or the value is NULL.
+ *
+ * \param[in] htable Initialized hash table
+ * \param[in] key key to use to search
+ * \return value associated with key in hashtable or NULL
+ */
+CARES_EXTERN void *ares_htable_vpvp_get_direct(const ares_htable_vpvp_t *htable,
+ const void *key);
+
+/*! Remove a value from the hashtable by key
+ *
+ * \param[in] htable Initialized hash table
+ * \param[in] key key to use to search
+ * \return ARES_TRUE if found, ARES_FALSE if not
+ */
+CARES_EXTERN ares_bool_t ares_htable_vpvp_remove(ares_htable_vpvp_t *htable,
+ const void *key);
+
+/*! Retrieve the number of keys stored in the hash table
+ *
+ * \param[in] htable Initialized hash table
+ * \return count
+ */
+CARES_EXTERN size_t ares_htable_vpvp_num_keys(const ares_htable_vpvp_t *htable);
+
+/*! @} */
+
+#endif /* __ARES__HTABLE_VPVP_H */