linear_hash_handler.h File Reference
#include "linear_hash.h"

Description

Header for handler for a linear hash .

Author
Spencer MacBeth
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1.Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2.Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3.Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file linear_hash_handler.h.

Include dependency graph for linear_hash_handler.h:
This graph shows which files directly or indirectly include this file:

Functions

void linear_hash_dict_init (ion_dictionary_handler_t *handler)
 Registers a linear hash handler to a dictionary instance. More...
 
ion_status_t linear_hash_dict_insert (ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
 Inserts a key and value pair into the dictionary. More...
 
ion_err_t linear_hash_create_dictionary (ion_dictionary_id_t id, ion_key_type_t key_type, ion_key_size_t key_size, ion_value_size_t value_size, ion_dictionary_size_t dictionary_size, ion_dictionary_compare_t compare, ion_dictionary_handler_t *handler, ion_dictionary_t *dictionary)
 Creates an instance of a dictionary. More...
 
ion_err_t linear_hash_close_dictionary (ion_dictionary_t *dictionary)
 
ion_err_t linear_hash_open_dictionary (ion_dictionary_handler_t *handler, ion_dictionary_t *dictionary, ion_dictionary_config_info_t *config, ion_dictionary_compare_t compare)
 
ion_status_t linear_hash_dict_get (ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
 
ion_status_t linear_hash_dict_delete (ion_dictionary_t *dictionary, ion_key_t key)
 Deletes the key and associated value from the given dictionary instance. More...
 
ion_err_t linear_hash_delete_dictionary (ion_dictionary_t *dictionary)
 Deletes an instance of a dictionary and its associated data. More...
 
ion_err_t linear_hash_destroy_dictionary (ion_dictionary_id_t id)
 Cleans up all files created by the dictionary, and frees any allocated memory, for an already closed dictionary. More...
 
ion_status_t linear_hash_dict_update (ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
 Updates the value stored at a given key. More...
 
ion_status_t linear_hash_dict_find (ion_dictionary_t *dictionary)
 

Function Documentation

ion_err_t linear_hash_close_dictionary ( ion_dictionary_t dictionary)

Definition at line 169 of file linear_hash_handler.c.

171  {
173 
174  if (dictionary->instance != NULL) {
175  free(dictionary->instance);
176  dictionary->instance = NULL;
177  }
178 
179  if (err_ok != err) {
180  return err;
181  }
182 
183  return err_ok;
184 }
ion_dictionary_parent_t * instance
ion_err_t linear_hash_close(linear_hash_table_t *linear_hash)
Close a linear hash instance with proper resource clean-up.
Definition: linear_hash.c:1466
char ion_err_t
The error type used to store error codes.
Definition: kv_system.h:226

Here is the call graph for this function:

Here is the caller graph for this function:

ion_err_t linear_hash_create_dictionary ( ion_dictionary_id_t  id,
ion_key_type_t  key_type,
ion_key_size_t  key_size,
ion_value_size_t  value_size,
ion_dictionary_size_t  dictionary_size,
ion_dictionary_compare_t  compare,
ion_dictionary_handler_t handler,
ion_dictionary_t dictionary 
)

Creates an instance of a dictionary.

Creates an instance of a dictionary given a key_size and value_size, in bytes. Given an By nature of the structure, the maximum number of elements is bounded only by memory.

Parameters
id
key_type
key_sizeSize of the key in bytes.
value_sizeSize of the value in bytes.
dictionary_size
compare
handlerHandler to be bound to the dictionary instance being created. Assumption is that the handler has been initialized prior.
dictionaryPointer in which the created dictionary instance is to be stored. Assumption is that it has been properly allocated by the user.
Returns
Status of creation.

Definition at line 83 of file linear_hash_handler.c.

92  {
93  int initial_size, split_threshold, records_per_bucket;
94 
95  dictionary->instance = malloc(sizeof(linear_hash_table_t));
96 
97  if (NULL == dictionary->instance) {
98  return err_out_of_memory;
99  }
100 
101  dictionary->instance->compare = compare;
102 
103  initial_size = 4;
104  split_threshold = 85;
105  records_per_bucket = 4;
106 
107  /* TODO Should we handle the possible error code returned by this? If yes, what sorts of errors does it return? */
108  ion_err_t result = linear_hash_init(id, dictionary_size, key_type, key_size, value_size, initial_size, split_threshold, records_per_bucket, (linear_hash_table_t *) dictionary->instance);
109 
110  if ((err_ok == result) && (NULL != handler)) {
111  dictionary->handler = handler;
113  }
114 
115  return result;
116 }
ion_dictionary_handler_t * handler
ion_dictionary_parent_t * instance
char ion_err_t
The error type used to store error codes.
Definition: kv_system.h:226
ion_err_t linear_hash_init(ion_dictionary_id_t id, ion_dictionary_size_t dictionary_size, ion_key_type_t key_type, ion_key_size_t key_size, ion_value_size_t value_size, int initial_size, int split_threshold, int records_per_bucket, linear_hash_table_t *linear_hash)
Definition: linear_hash.c:47
ion_dictionary_type_t type
ion_dictionary_compare_t compare

Here is the call graph for this function:

Here is the caller graph for this function:

ion_err_t linear_hash_delete_dictionary ( ion_dictionary_t dictionary)

Deletes an instance of a dictionary and its associated data.

Parameters
dictionaryThe instance of the dictionary to be deleted.
Returns
Status of dictionary deletion.

Definition at line 148 of file linear_hash_handler.c.

150  {
151  ion_err_t result = linear_hash_destroy((linear_hash_table_t *) dictionary->instance);
152 
153  free(dictionary->instance);
154  dictionary->instance = NULL;
155  return result;
156 }
ion_err_t linear_hash_destroy(linear_hash_table_t *linear_hash)
Close a linear hash instance and delete its associated .lhs and .lhd files.
Definition: linear_hash.c:1507
ion_dictionary_parent_t * instance
char ion_err_t
The error type used to store error codes.
Definition: kv_system.h:226

Here is the call graph for this function:

Here is the caller graph for this function:

ion_err_t linear_hash_destroy_dictionary ( ion_dictionary_id_t  id)

Cleans up all files created by the dictionary, and frees any allocated memory, for an already closed dictionary.

Parameters
idThe identifier identifying the dictionary to delete.
Returns
The resulting status of the operation.

Definition at line 127 of file linear_hash_handler.c.

129  {
130  char filename[ION_MAX_FILENAME_LENGTH];
131 
132  dictionary_get_filename(id, "lhs", filename);
133 
134  if (0 != fremove(filename)) {
135  return err_file_delete_error;
136  }
137 
138  dictionary_get_filename(id, "lhd", filename);
139 
140  if (0 != fremove(filename)) {
141  return err_file_delete_error;
142  }
143 
144  return err_ok;
145 }
#define fremove(x)
Definition: kv_system.h:56
int dictionary_get_filename(ion_dictionary_id_t id, char *ext, char *filename)
Given the ID, implementation specific extension, and a buffer to write to, writes back the formatted ...
Definition: dictionary.c:41
#define ION_MAX_FILENAME_LENGTH
Since the arduino conforms to 8.3 syntax, that's 8 + 3 = 11 + 1 (null terminator) characters...
Definition: kv_system.h:73

Here is the call graph for this function:

Here is the caller graph for this function:

ion_status_t linear_hash_dict_delete ( ion_dictionary_t dictionary,
ion_key_t  key 
)

Deletes the key and associated value from the given dictionary instance.

Parameters
dictionaryThe instance of the dictionary to delete from.
keyThe key to be deleted.
Returns
Status of deletion.

Definition at line 119 of file linear_hash_handler.c.

122  {
123  return linear_hash_delete(key, (linear_hash_table_t *) dictionary->instance);
124 }
ion_dictionary_parent_t * instance
#define key(k)
Definition: bpp_tree.c:75
ion_status_t linear_hash_delete(ion_byte_t *key, linear_hash_table_t *linear_hash)
Delete all records with keys matching the key specified in the linear hash.
Definition: linear_hash.c:867

Here is the call graph for this function:

Here is the caller graph for this function:

ion_status_t linear_hash_dict_find ( ion_dictionary_t dictionary)

Definition at line 187 of file linear_hash_handler.c.

189  {
191 
192  UNUSED(dictionary);
193  status.error = err_not_implemented;
194  return status;
195 }
ion_err_t error
Definition: kv_system.h:291
#define UNUSED(x)
Definition: kv_system.h:102
#define ION_STATUS_INITIALIZE
Definition: kv_system.h:107
A status object that describes the result of a dictionary operation.
Definition: kv_system.h:290
ion_status_t linear_hash_dict_get ( ion_dictionary_t dictionary,
ion_key_t  key,
ion_value_t  value 
)

Definition at line 65 of file linear_hash_handler.c.

69  {
70  return linear_hash_get(key, value, (linear_hash_table_t *) dictionary->instance);
71 }
ion_status_t linear_hash_get(ion_byte_t *key, ion_byte_t *value, linear_hash_table_t *linear_hash)
Retrieve a record from the linear hash. The key and value will be written to the key and value pointe...
Definition: linear_hash.c:673
ion_dictionary_parent_t * instance
#define key(k)
Definition: bpp_tree.c:75

Here is the call graph for this function:

Here is the caller graph for this function:

void linear_hash_dict_init ( ion_dictionary_handler_t handler)

Registers a linear hash handler to a dictionary instance.

Binds each unique linear hash function to the generic dictionary interface. Only needs to be called once when the linear hash is initialized.

Parameters
handlerAn instance of a dictionary handler that is to be bound. It is assumed handler is initialized by the user.

Definition at line 40 of file linear_hash_handler.c.

42  {
44  handler->get = linear_hash_dict_get;
50  /* handler->find = linear_hash_dict_find; */
53 }
ion_status_t(* insert)(ion_dictionary_t *, ion_key_t, ion_value_t)
ion_err_t linear_hash_open_dictionary(ion_dictionary_handler_t *handler, ion_dictionary_t *dictionary, ion_dictionary_config_info_t *config, ion_dictionary_compare_t compare)
ion_status_t linear_hash_dict_update(ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
Updates the value stored at a given key.
ion_status_t(* remove)(ion_dictionary_t *, ion_key_t)
ion_err_t(* destroy_dictionary)(ion_dictionary_id_t id)
ion_status_t linear_hash_dict_insert(ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
Inserts a key and value pair into the dictionary.
ion_status_t linear_hash_dict_get(ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
ion_status_t(* update)(ion_dictionary_t *, ion_key_t, ion_value_t)
ion_err_t linear_hash_close_dictionary(ion_dictionary_t *dictionary)
ion_err_t linear_hash_create_dictionary(ion_dictionary_id_t id, ion_key_type_t key_type, ion_key_size_t key_size, ion_value_size_t value_size, ion_dictionary_size_t dictionary_size, ion_dictionary_compare_t compare, ion_dictionary_handler_t *handler, ion_dictionary_t *dictionary)
Creates an instance of a dictionary.
ion_err_t linear_hash_delete_dictionary(ion_dictionary_t *dictionary)
Deletes an instance of a dictionary and its associated data.
ion_err_t(* close_dictionary)(ion_dictionary_t *)
ion_err_t(* open_dictionary)(ion_dictionary_handler_t *, ion_dictionary_t *, ion_dictionary_config_info_t *, ion_dictionary_compare_t)
ion_err_t(* create_dictionary)(ion_dictionary_id_t, ion_key_type_t, ion_key_size_t, ion_value_size_t, ion_dictionary_size_t, ion_dictionary_compare_t, ion_dictionary_handler_t *, ion_dictionary_t *)
ion_err_t(* delete_dictionary)(ion_dictionary_t *)
ion_err_t linear_hash_destroy_dictionary(ion_dictionary_id_t id)
Cleans up all files created by the dictionary, and frees any allocated memory, for an already closed ...
ion_status_t linear_hash_dict_delete(ion_dictionary_t *dictionary, ion_key_t key)
Deletes the key and associated value from the given dictionary instance.
ion_status_t(* get)(ion_dictionary_t *, ion_key_t, ion_value_t)

Here is the call graph for this function:

Here is the caller graph for this function:

ion_status_t linear_hash_dict_insert ( ion_dictionary_t dictionary,
ion_key_t  key,
ion_value_t  value 
)

Inserts a key and value pair into the dictionary.

Parameters
dictionaryThe dictionary instance to insert the value into.
keyThe key to use.
valueThe value to use.
Returns
Status of insertion.

Definition at line 56 of file linear_hash_handler.c.

60  {
62 }
ion_dictionary_parent_t * instance
int insert_hash_to_bucket(ion_byte_t *key, linear_hash_table_t *linear_hash)
Map a key to the address space of the linear hash. Used to map records to buckets with an index less ...
Definition: linear_hash.c:1358
#define key(k)
Definition: bpp_tree.c:75
ion_status_t linear_hash_insert(ion_key_t key, ion_value_t value, int hash_bucket_idx, linear_hash_table_t *linear_hash)
Insert a record into the linear hash.
Definition: linear_hash.c:573

Here is the call graph for this function:

Here is the caller graph for this function:

ion_status_t linear_hash_dict_update ( ion_dictionary_t dictionary,
ion_key_t  key,
ion_value_t  value 
)

Updates the value stored at a given key.

Updates the value for a given key. If the key doesn't exist, the key value pair will be added as if it was an insert.

Parameters
dictionaryThe instance of the dictionary to be updated.
keyThe key that is to be updated.
valueThe new value to be used.
Returns
Status of update.

Definition at line 74 of file linear_hash_handler.c.

78  {
79  return linear_hash_update(key, value, (linear_hash_table_t *) dictionary->instance);
80 }
ion_dictionary_parent_t * instance
ion_status_t linear_hash_update(ion_key_t key, ion_value_t value, linear_hash_table_t *linear_hash)
Update the value of the first record matching the key specified in the linear hash.
Definition: linear_hash.c:774
#define key(k)
Definition: bpp_tree.c:75

Here is the call graph for this function:

Here is the caller graph for this function:

ion_err_t linear_hash_open_dictionary ( ion_dictionary_handler_t handler,
ion_dictionary_t dictionary,
ion_dictionary_config_info_t config,
ion_dictionary_compare_t  compare 
)

Definition at line 159 of file linear_hash_handler.c.

164  {
165  return linear_hash_create_dictionary(config->id, config->type, config->key_size, config->value_size, config->dictionary_size, compare, handler, dictionary);
166 }
ion_err_t linear_hash_create_dictionary(ion_dictionary_id_t id, ion_key_type_t key_type, ion_key_size_t key_size, ion_value_size_t value_size, ion_dictionary_size_t dictionary_size, ion_dictionary_compare_t compare, ion_dictionary_handler_t *handler, ion_dictionary_t *dictionary)
Creates an instance of a dictionary.
ion_dictionary_size_t dictionary_size

Here is the call graph for this function:

Here is the caller graph for this function: