Main Page | Data Structures | Directories | File List | Data Fields | Globals

ks_assoc.c File Reference

libkarmaclient's associative array type. More...

#include "ks_config.h"
#include "ks_assoc.h"
#include "ks_string.h"
#include <string.h>
#include <stdio.h>

Go to the source code of this file.

Functions

ks_type_tks_assoc_type (void)
void ks_assoc_init (ks_assoc_t *s)
ks_assoc_tks_assoc_new (void)
void ks_assoc_fini (ks_assoc_t *s)
void ks_assoc_free (ks_assoc_t *s)
void ks_assoc_put (ks_assoc_t *s, const char *key, size_t len, ks_base_t *ptr)
ks_base_tks_assoc_get (ks_assoc_t *s, const char *key, size_t len)
int ks_assoc_size (ks_assoc_t *s)
ks_array_tks_assoc_keys (ks_assoc_t *s)


Detailed Description

libkarmaclient's associative array type.

This module provides an associative array, allowing us to deal with dictionaries of information.

Definition in file ks_assoc.c.


Function Documentation

void ks_assoc_fini ks_assoc_t s  ) 
 

Clear the state of a ks_assoc_t, leaving in the ks_assoc_t in a suitable state for ks_assoc_init() to reinitialise.

Parameters:
s a pointer to the ks_assoc_t to be reset
Returns:
nothing

Definition at line 238 of file ks_assoc.c.

References _ks_assoc_t::array, and ks_array_fini().

Referenced by ks_assoc_free().

void ks_assoc_free ks_assoc_t s  ) 
 

Destroy a ks_assoc_t, freeing all memory used by it.

Parameters:
s a poingter to the ks_assoc_t to be destroyed
Returns:
nothing

Definition at line 251 of file ks_assoc.c.

References ks_assoc_fini(), and ks_free().

Referenced by ks_response_free().

ks_base_t* ks_assoc_get ks_assoc_t s,
const char *  key,
size_t  len
 

Retrieve the data associated with a given key from a ks_assoc_t.

Parameters:
s a pointer to the ks_asssoc_t to be searched
key the hte key to search the ks_assoc_t for
len the length of the key string
Returns:
a pointer to the data associated with key in s

Definition at line 319 of file ks_assoc.c.

References _ks_bucket_t::data.

Referenced by ks_combination_data(), ks_combination_score(), ks_fact_data(), ks_fact_feed(), ks_fact_identity(), ks_fact_value(), ks_response_combination(), ks_response_combinations(), ks_response_error(), ks_response_id(), ks_response_message(), and ks_response_time().

void ks_assoc_init ks_assoc_t s  ) 
 

Initialise a ks_assoc_t. This will have been done for you by ks_assoc_new() for each new ks_assoc_t. If you need to reinitialise a ks_assoc_t, then you should first clear its state using ks_assoc_fini(), or your application could leak memory.

Parameters:
s a pointer to the ks_assoc_t to be initialised
Returns:
nothing

Definition at line 210 of file ks_assoc.c.

References _ks_assoc_t::array, _ks_assoc_t::base, ks_array_init(), and _ks_base_t::type.

Referenced by ks_assoc_new().

ks_array_t* ks_assoc_keys ks_assoc_t s  ) 
 

Return the list of keys stored in a ks_assoc_t

Parameters:
s a pointer to the ks_assoc_t whose keys are to be returned
Returns:
a ks_array_t containing all of the keys present in the given ks_assoc_t

Definition at line 350 of file ks_assoc.c.

References _ks_assoc_t::array, _ks_bucket_t::key, _ks_bucket_t::klen, ks_array_add(), ks_array_get(), ks_array_length(), ks_array_new(), KS_CAST, and ks_string_new().

ks_assoc_t* ks_assoc_new void   ) 
 

Create a new, initialised ks_assoc_t.

Returns:
a pointer to the new ks_assoc_t on success, or NULL on failure

Definition at line 222 of file ks_assoc.c.

References ks_assoc_init(), and ks_malloc().

void ks_assoc_put ks_assoc_t s,
const char *  key,
size_t  len,
ks_base_t ptr
 

Put new data in a ks_assoc_t, and associate it with a given key. If the key already exists, the existing data associated with that key is destroyed and the new data inserted in its place, otherwise a new bucket is created for the key and data.

Parameters:
s a pointer to the ks_assoc_t into which the data is to be put
key a string with which the data is to be associated
len the length of the key string
ptr a spointer to the data to be put in the ks_assoc_t
Returns:
nothing

Definition at line 295 of file ks_assoc.c.

References _ks_assoc_t::array, _ks_bucket_t::data, and ks_array_add().

Referenced by ks_fact_feed().

int ks_assoc_size ks_assoc_t s  ) 
 

Find the number of entries in a ks_assoc_t

Parameters:
s a pointer to the ks_assoc_t whose size is to be determined
Returns:
the number of buckets stored in the given ks_assoc_t

Definition at line 335 of file ks_assoc.c.

References _ks_assoc_t::array, and ks_array_length().

Referenced by ks_response_combinations_size().

ks_type_t* ks_assoc_type void   ) 
 

Retrieve the metaclass for ks_assoc_t objects.

Returns:
a pointer to the metaclass for ks_assoc_t

Definition at line 172 of file ks_assoc.c.

Referenced by ks_response_bparse().


Generated on Tue Aug 7 21:11:31 2007 for libkarmaclient by  doxygen 1.4.4