annotate ext/sord/src/zix/hash.h @ 245:b32c68f08ec0

Use local sord/serd build
author Chris Cannam <cannam@all-day-breakfast.com>
date Thu, 15 Jun 2017 09:38:52 +0100
parents c5cdc9e6a4bf
children
rev   line source
cannam@226 1 /*
cannam@226 2 Copyright 2011-2015 David Robillard <http://drobilla.net>
cannam@226 3
cannam@226 4 Permission to use, copy, modify, and/or distribute this software for any
cannam@226 5 purpose with or without fee is hereby granted, provided that the above
cannam@226 6 copyright notice and this permission notice appear in all copies.
cannam@226 7
cannam@226 8 THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
cannam@226 9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
cannam@226 10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
cannam@226 11 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
cannam@226 12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
cannam@226 13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
cannam@226 14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
cannam@226 15 */
cannam@226 16
cannam@226 17 #ifndef ZIX_HASH_H
cannam@226 18 #define ZIX_HASH_H
cannam@226 19
cannam@226 20 #include <stddef.h>
cannam@226 21 #include <stdint.h>
cannam@226 22
cannam@245 23 #include "common.h"
cannam@226 24
cannam@226 25 #ifdef __cplusplus
cannam@226 26 extern "C" {
cannam@226 27 #endif
cannam@226 28
cannam@226 29 /**
cannam@226 30 @addtogroup zix
cannam@226 31 @{
cannam@226 32 @name Hash
cannam@226 33 @{
cannam@226 34 */
cannam@226 35
cannam@226 36 typedef struct ZixHashImpl ZixHash;
cannam@226 37
cannam@226 38 /**
cannam@226 39 Function for computing the hash of an element.
cannam@226 40 */
cannam@226 41 typedef uint32_t (*ZixHashFunc)(const void* value);
cannam@226 42
cannam@226 43 /**
cannam@226 44 Function to visit a hash element.
cannam@226 45 */
cannam@226 46 typedef void (*ZixHashVisitFunc)(void* value,
cannam@226 47 void* user_data);
cannam@226 48
cannam@226 49 /**
cannam@226 50 Create a new hash table.
cannam@226 51
cannam@226 52 To minimize space overhead, unlike many hash tables this stores a single
cannam@226 53 value, not a key and a value. Any size of value can be stored, but all the
cannam@226 54 values in the hash table must be the same size, and the values must be safe
cannam@226 55 to copy with memcpy. To get key:value behaviour, simply insert a struct
cannam@226 56 with a key and value into the hash.
cannam@226 57
cannam@226 58 @param hash_func The hashing function.
cannam@226 59 @param equal_func A function to test value equality.
cannam@226 60 @param value_size The size of the values to be stored.
cannam@226 61 */
cannam@226 62 ZIX_API ZixHash*
cannam@226 63 zix_hash_new(ZixHashFunc hash_func,
cannam@226 64 ZixEqualFunc equal_func,
cannam@226 65 size_t value_size);
cannam@226 66
cannam@226 67 /**
cannam@226 68 Free `hash`.
cannam@226 69 */
cannam@226 70 ZIX_API void
cannam@226 71 zix_hash_free(ZixHash* hash);
cannam@226 72
cannam@226 73 /**
cannam@226 74 Return the number of elements in `hash`.
cannam@226 75 */
cannam@226 76 ZIX_API size_t
cannam@226 77 zix_hash_size(const ZixHash* hash);
cannam@226 78
cannam@226 79 /**
cannam@226 80 Insert an item into `hash`.
cannam@226 81
cannam@226 82 If no matching value is found, ZIX_STATUS_SUCCESS will be returned, and @p
cannam@226 83 inserted will be pointed to the copy of `value` made in the new hash node.
cannam@226 84
cannam@226 85 If a matching value already exists, ZIX_STATUS_EXISTS will be returned, and
cannam@226 86 `inserted` will be pointed to the existing value.
cannam@226 87
cannam@226 88 @param hash The hash table.
cannam@226 89 @param value The value to be inserted.
cannam@226 90 @param inserted The copy of `value` in the hash table.
cannam@226 91 @return ZIX_STATUS_SUCCESS, ZIX_STATUS_EXISTS, or ZIX_STATUS_NO_MEM.
cannam@226 92 */
cannam@226 93 ZIX_API ZixStatus
cannam@226 94 zix_hash_insert(ZixHash* hash,
cannam@226 95 const void* value,
cannam@226 96 const void** inserted);
cannam@226 97
cannam@226 98 /**
cannam@226 99 Remove an item from `hash`.
cannam@226 100
cannam@226 101 @param hash The hash table.
cannam@226 102 @param value The value to remove.
cannam@226 103 @return ZIX_STATUS_SUCCES or ZIX_STATUS_NOT_FOUND.
cannam@226 104 */
cannam@226 105 ZIX_API ZixStatus
cannam@226 106 zix_hash_remove(ZixHash* hash,
cannam@226 107 const void* value);
cannam@226 108
cannam@226 109 /**
cannam@226 110 Search for an item in `hash`.
cannam@226 111
cannam@226 112 @param hash The hash table.
cannam@226 113 @param value The value to search for.
cannam@226 114 */
cannam@226 115 ZIX_API const void*
cannam@226 116 zix_hash_find(const ZixHash* hash,
cannam@226 117 const void* value);
cannam@226 118
cannam@226 119 /**
cannam@226 120 Call `f` on each value in `hash`.
cannam@226 121
cannam@226 122 @param hash The hash table.
cannam@226 123 @param f The function to call on each value.
cannam@226 124 @param user_data The user_data parameter passed to `f`.
cannam@226 125 */
cannam@226 126 ZIX_API void
cannam@226 127 zix_hash_foreach(ZixHash* hash,
cannam@226 128 ZixHashVisitFunc f,
cannam@226 129 void* user_data);
cannam@226 130
cannam@226 131 /**
cannam@226 132 @}
cannam@226 133 @}
cannam@226 134 */
cannam@226 135
cannam@226 136 #ifdef __cplusplus
cannam@226 137 } /* extern "C" */
cannam@226 138 #endif
cannam@226 139
cannam@226 140 #endif /* ZIX_HASH_H */