OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
shash.h File Reference
#include <stdint.h>
Include dependency graph for shash.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SHASH_API_VERSION   1002000
 
#define SHASH_API_VERSION_STR   "1.2.0"
 

Functions

shashshash_create (uint32_t options)
 
int shash_destroy (shash *h)
 
int shash_set (shash *h, const char *key, const char *value)
 
const char * shash_get (shash *h, const char *key)
 
int shash_remove (shash *h, const char *key)
 
int shash_rewind (shash *h)
 
int shash_next (shash *h, const char **key, const char **value)
 
int shash_size (shash *h)
 
const char * shash_version ()
 

Detailed Description

A simple dictionary library for storing strings.

Definition in file shash.h.

Macro Definition Documentation

◆ SHASH_API_VERSION

#define SHASH_API_VERSION   1002000

Current API version. If already defined, use API defined first.

Definition at line 16 of file shash.h.

◆ SHASH_API_VERSION_STR

#define SHASH_API_VERSION_STR   "1.2.0"

Current API version as a string. If already defined, use API defined first.

Definition at line 18 of file shash.h.

Function Documentation

◆ shash_create()

shash* shash_create ( uint32_t  options)

Initialize a shash object.

Parameters
[in]optionsBitwise OR'd option flags. Currently unused.
Returns
Pointer to malloc'd shash.

Definition at line 105 of file shash.c.

◆ shash_destroy()

int shash_destroy ( shash h)

Destroy a shash object, free'ing the memory used.

Parameters
[in]hPointer to shash to be destroyed.
Returns
0 on success.

Definition at line 136 of file shash.c.

◆ shash_get()

const char* shash_get ( shash h,
const char *  key 
)

Find a pointer associated with the given string.

Parameters
[in]hPointer to shash to be searched.
[in]keyKey for which to search.
Returns
Pointer to value, or NULL if key is not found.

Definition at line 205 of file shash.c.

◆ shash_next()

int shash_next ( shash h,
const char **  key,
const char **  value 
)

Retrieves the next key-value pair in the shash. 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-shash, the shash is rewind()'d and the state of the key and value inputs are set to NULL.

Parameters
[in]hPointer to shash to be traversed.
[out]keyPointer to fill with the next key, NULL to ignore.
[out]valuePointer to fill with the next value, NULL to ignore.
Returns
-1 on error, positive 1 on end-of-shash, and 0 on success.

Definition at line 283 of file shash.c.

◆ shash_remove()

int shash_remove ( shash h,
const char *  key 
)

Remove a pointer associated with the given string.

Parameters
[in]hPointer to shash to be modified.
[in]keyKey for which to remove.
Returns
0 on success.

Definition at line 146 of file shash.c.

◆ shash_rewind()

int shash_rewind ( shash h)

Rewind iterator for traversing all the keys and values.

Parameters
[in]hPointer to shash to be reset.
Returns
number of items currently in the shash.

Definition at line 277 of file shash.c.

◆ shash_set()

int shash_set ( shash h,
const char *  key,
const char *  value 
)

Add or overwrite a pointer, associating it with the given key.

Parameters
[in]hPointer to shash to be modified.
[in]keyNull-terminated string with which to associate the new pointer.
[in]valueNew pointer to store..
Returns
0 on add, 1 on overwrite, and -1 on error.

Definition at line 224 of file shash.c.

◆ shash_size()

int shash_size ( shash h)

Retrieves the number of key-value pairs in the hash object.

Parameters
[in]hPointer to shash to be analyzed.

Definition at line 320 of file shash.c.

◆ shash_version()

const char* shash_version ( )

Returns the source code version and the implemented API version.

No assumptions are made about the format of the return value.

Definition at line 324 of file shash.c.