Hashes

Hashes — Key:Value hashes or dictionaries.

Synopsis




typedef     librdf_hash;
typedef     librdf_hash_cursor;
librdf_hash* librdf_new_hash_from_string    (librdf_world *world,
                                             const char *name,
                                             const char *string);
librdf_hash* librdf_new_hash_from_array_of_strings
                                            (librdf_world *world,
                                             const char *name,
                                             const char **array);
librdf_hash* librdf_new_hash_from_hash      (librdf_hash *old_hash);
void        librdf_free_hash                (librdf_hash *hash);
char*       librdf_hash_get                 (librdf_hash *hash,
                                             const char *key);
int         librdf_hash_get_as_boolean      (librdf_hash *hash,
                                             const char *key);
long        librdf_hash_get_as_long         (librdf_hash *hash,
                                             const char *key);
char*       librdf_hash_get_del             (librdf_hash *hash,
                                             const char *key);
int         librdf_hash_put_strings         (librdf_hash *hash,
                                             const char *key,
                                             const char *value);
void        librdf_hash_print               (librdf_hash *hash,
                                             FILE *fh);
void        librdf_hash_print_keys          (librdf_hash *hash,
                                             FILE *fh);
void        librdf_hash_print_values        (librdf_hash *hash,
                                             const char *key_string,
                                             FILE *fh);

Description

Interface to implementations of key:value hashes either in memory, on disk and with persistence. Keys may have multiple and duplicate values.

Details

librdf_hash

typedef struct librdf_hash_s librdf_hash;

Redland hash class.


librdf_hash_cursor

typedef struct librdf_hash_cursor_s librdf_hash_cursor;

Redland hash cursor class.


librdf_new_hash_from_string ()

librdf_hash* librdf_new_hash_from_string    (librdf_world *world,
                                             const char *name,
                                             const char *string);

Constructor - create a new librdf_hash object from a string.

See librdf_hash_from_string for the string format.

world : redland world object
name : hash name
string : hash encoded as a string
Returns : a new librdf_hash object or NULL on failure

librdf_new_hash_from_array_of_strings ()

librdf_hash* librdf_new_hash_from_array_of_strings
                                            (librdf_world *world,
                                             const char *name,
                                             const char **array);

Constructor - create a new librdf_hash object from an array of strings.

world : redland world object
name : hash name
array : address of the start of the array of char* pointers
Returns : a new librdf_hash object or NULL on failure

librdf_new_hash_from_hash ()

librdf_hash* librdf_new_hash_from_hash      (librdf_hash *old_hash);

Copy Constructor - create a new librdf_hash object from an existing one.

old_hash : the hash to use to construct the hash
Returns : a new librdf_hash object or NULL on failure

librdf_free_hash ()

void        librdf_free_hash                (librdf_hash *hash);

Destructor - destroy a librdf_hash object.

hash : hash object

librdf_hash_get ()

char*       librdf_hash_get                 (librdf_hash *hash,
                                             const char *key);

Retrieve one value from hash for a given key as string.

The value returned is from newly allocated memory which the caller must free.

hash : hash object
key : pointer to key
Returns : the value or NULL on failure

librdf_hash_get_as_boolean ()

int         librdf_hash_get_as_boolean      (librdf_hash *hash,
                                             const char *key);

Lookup a hash key and decode value as a boolean.

hash : librdf_hash object
key : key string to look up
Returns : >0 (for true), 0 (for false) or <0 (for key not found or not known boolean value)

librdf_hash_get_as_long ()

long        librdf_hash_get_as_long         (librdf_hash *hash,
                                             const char *key);

Lookup a hash key and decode value as a long.

hash : librdf_hash object
key : key string to look up
Returns : >0 (for success), <0 (for key not found or not known boolean value)

librdf_hash_get_del ()

char*       librdf_hash_get_del             (librdf_hash *hash,
                                             const char *key);

Retrieve one value from hash for a given key as string and remove all values with that key.

The value returned is from newly allocated memory which the caller must free.

hash : hash object
key : pointer to key
Returns : the value or NULL on failure

librdf_hash_put_strings ()

int         librdf_hash_put_strings         (librdf_hash *hash,
                                             const char *key,
                                             const char *value);

Insert key/value pairs into the hash as strings.

The key and values are copied into the hash, no sharing i s done.

hash : hash object
key : key
value : value
Returns : non 0 on failure

librdf_hash_print ()

void        librdf_hash_print               (librdf_hash *hash,
                                             FILE *fh);

Pretty print the hash to a file descriptor.

hash : the hash
fh : file handle

librdf_hash_print_keys ()

void        librdf_hash_print_keys          (librdf_hash *hash,
                                             FILE *fh);

Pretty print the keys to a file descriptor.

hash : the hash
fh : file handle

librdf_hash_print_values ()

void        librdf_hash_print_values        (librdf_hash *hash,
                                             const char *key_string,
                                             FILE *fh);

Pretty print the values of one key to a file descriptor.

hash : the hash
key_string : the key as a string
fh : file handle