RAVE
raveobject_hashtable.c File Reference

Implementation of a rave object hashtable that maps between strings and rave core objects. More...

#include "raveobject_hashtable.h"
#include "rave_debug.h"
#include "rave_alloc.h"
#include <string.h>
#include <stdio.h>

Classes

struct  RaveHash_bucket
 
struct  _RaveObjectHashTable_t
 Represents a hash table. More...
 

Macros

#define INITIAL_BUCKET_COUNT   10
 

Typedefs

typedef struct RaveHash_bucket RaveHash_bucket
 

Functions

int RaveObjectHashTable_put (RaveObjectHashTable_t *table, const char *key, RaveCoreObject *obj)
 Inserts a key - object binding in the table.
 
RaveCoreObjectRaveObjectHashTable_get (RaveObjectHashTable_t *table, const char *key)
 Returns the object referred to by key.
 
int RaveObjectHashTable_size (RaveObjectHashTable_t *table)
 Returns the number of items in this table.
 
int RaveObjectHashTable_exists (RaveObjectHashTable_t *table, const char *key)
 Returns if the specified key exists or not.
 
RaveCoreObjectRaveObjectHashTable_remove (RaveObjectHashTable_t *table, const char *key)
 Removes the item with the specified key and returns it.
 
void RaveObjectHashTable_clear (RaveObjectHashTable_t *table)
 Clears all entries in the table.
 
RaveList_tRaveObjectHashTable_keys (RaveObjectHashTable_t *table)
 Returns the keys for the table at the current state.
 
RaveObjectList_tRaveObjectHashTable_values (RaveObjectHashTable_t *table)
 Returns the values for the table.
 
void RaveObjectHashTable_destroyKeyList (RaveList_t *l)
 Helper function to destroy the returned list of keys.
 

Variables

RaveCoreObjectType RaveObjectHashTable_TYPE
 Type definition to use when creating a rave object.
 

Detailed Description

Implementation of a rave object hashtable that maps between strings and rave core objects.

This object supports RAVE_OBJECT_CLONE with an exception, if any members of the list is not possible to clone, they will not be added to the list which means that the returned list might have fewer entries.

Author
Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
Date
2010-01-21

Function Documentation

◆ RaveObjectHashTable_clear()

void RaveObjectHashTable_clear ( RaveObjectHashTable_t * table)

Clears all entries in the table.

Parameters
[in]table- the table

◆ RaveObjectHashTable_destroyKeyList()

void RaveObjectHashTable_destroyKeyList ( RaveList_t * l)

Helper function to destroy the returned list of keys.

Parameters
[in]l- the list to destroy

◆ RaveObjectHashTable_exists()

int RaveObjectHashTable_exists ( RaveObjectHashTable_t * table,
const char * key )

Returns if the specified key exists or not.

Parameters
[in]table- self
[in]key- the key to search for
Returns
1 if the key exists, 0 if it doesn't

◆ RaveObjectHashTable_get()

RaveCoreObject * RaveObjectHashTable_get ( RaveObjectHashTable_t * table,
const char * key )

Returns the object referred to by key.

Parameters
[in]table- the table
[in]key- the key
Returns
the object (or NULL if not found or error)

◆ RaveObjectHashTable_keys()

RaveList_t * RaveObjectHashTable_keys ( RaveObjectHashTable_t * table)

Returns the keys for the table at the current state.

Note, remember to deallocate keys appropriately after retrival or use the function @ref RaveList_freeAndDestroy that will take care of it for you.

Parameters
[in]table- self
Returns
a list containing char* pointers.

◆ RaveObjectHashTable_put()

int RaveObjectHashTable_put ( RaveObjectHashTable_t * table,
const char * key,
RaveCoreObject * obj )

Inserts a key - object binding in the table.

Parameters
[in]table- the table
[in]key- the key
[in]obj- the object
Returns
1 on success, otherwise 0

◆ RaveObjectHashTable_remove()

RaveCoreObject * RaveObjectHashTable_remove ( RaveObjectHashTable_t * table,
const char * key )

Removes the item with the specified key and returns it.

Parameters
[in]table- the table
[in]key- the key
Returns
the object (or NULL if none found)

◆ RaveObjectHashTable_size()

int RaveObjectHashTable_size ( RaveObjectHashTable_t * table)

Returns the number of items in this table.

Parameters
[in]table- the table
Returns
the number of items in this table.

◆ RaveObjectHashTable_values()

RaveObjectList_t * RaveObjectHashTable_values ( RaveObjectHashTable_t * table)

Returns the values for the table.

Note, it is not cloned values but references to them.

Parameters
[in]table- self
Returns
a list of values

Variable Documentation

◆ RaveObjectHashTable_TYPE

RaveCoreObjectType RaveObjectHashTable_TYPE
Initial value:
= {
"HashTable",
RaveObjectHashTable_constructor,
RaveObjectHashTable_destructor,
RaveObjectHashTable_copyconstructor
}
struct _RaveObjectHashTable_t RaveObjectHashTable_t
Defines a hash table.
Definition raveobject_hashtable.h:38

Type definition to use when creating a rave object.