ocssw
V2022
|
#include <stdint.h>
Go to the source code of this file.
Macros | |
#define | PHASH_API_VERSION 1002000 |
#define | PHASH_API_VERSION_STR "1.2.0" |
#define | PHASH_NO_COPY_KEYS 1 |
Functions | |
phash * | phash_create (uint32_t options) |
int | phash_destroy (phash *h) |
int | phash_set (phash *h, const char *key, void *value) |
void * | phash_get (phash *h, const char *key) |
int | phash_remove (phash *h, const char *key) |
int | phash_rewind (phash *h) |
int | phash_next (phash *h, const char **key, void **value) |
int | phash_size (phash *h) |
const char * | phash_version () |
Detailed Description
A simple dictionary library for storing pointers.
A phash doesn't actually store any data for the key or the value, merely pointers to them. The in-memory data must persist until the phash is destroyed. If a memory location referred to by a phash is free'd, or non-malloc'd pointers simply go out of scope the phash will almost definitely try to access invalid memory locations during a call to any function except for phash_destroy. String literals, depending on the compiler, generally get put into some kind of read-only memory and persist through the program, so they might be safe.
Definition in file phash.h.
Macro Definition Documentation
◆ PHASH_API_VERSION
#define PHASH_API_VERSION 1002000 |
◆ PHASH_API_VERSION_STR
#define PHASH_API_VERSION_STR "1.2.0" |
◆ PHASH_NO_COPY_KEYS
Function Documentation
◆ phash_create()
phash* phash_create | ( | uint32_t | options | ) |
◆ phash_destroy()
int phash_destroy | ( | phash * | h | ) |
◆ phash_get()
◆ phash_next()
Retrieves the next key-value pair in the phash. The order in which the pointers are returned shall be consistent but may be arbitrary.
Consistent refers only to running identical code and rewinding and traversing the data. Adding or removing pointers may modify the order in which keys are returned.
On end-of-hash, the hash is rewind()'d and the state of the key and value inputs are set to NULL.
- Parameters
-
[in] h Pointer to phash to be traversed. [out] key Pointer to fill with the next key, NULL to ignore. [out] value Pointer to fill with the next value, NULL to ignore.
- Returns
- -1 on error, positive 1 on end-of-hash, and 0 on success.
◆ phash_remove()
◆ phash_rewind()
int phash_rewind | ( | phash * | h | ) |
◆ phash_set()
Add or overwrite a pointer, associating it with the given key.
- Parameters
-
[in] h Pointer to phash to be modified. [in] key Null-terminated string with which to associate the new pointer. [in] value New pointer to store..
- Returns
- 0 on add, 1 on overwrite, and -1 on error.
◆ phash_size()
int phash_size | ( | phash * | h | ) |