skip_list_handler.h File Reference
#include "skip_list_types.h"
#include "skip_list.h"

Description

Handler liaison between dictionary API and skiplist implementation.

Author
Eric Huang
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 skip_list_handler.h.

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

Functions

void sldict_init (ion_dictionary_handler_t *handler)
 Registers a skiplist handler to a dictionary instance. More...
 
ion_status_t sldict_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 sldict_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_status_t sldict_delete (ion_dictionary_t *dictionary, ion_key_t key)
 Deletes the key and associated value from the given dictionary instance. More...
 
ion_err_t sldict_delete_dictionary (ion_dictionary_t *dictionary)
 Deletes an instance of a dictionary and its associated data. More...
 
ion_err_t sldict_destroy_dictionary (ion_dictionary_id_t id)
 Deletes an instance of a closed dictionary. More...
 
ion_status_t sldict_update (ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
 Updates the value stored at a given key. More...
 

Function Documentation

ion_err_t sldict_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 as well as the dictionary_size, which is the maximum number of levels in the skiplist. By nature of the structure, the maximum number of elements is bounded only by memory use.

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 376 of file skip_list_handler.c.

385  {
386  UNUSED(id);
387 
388  int pnum, pden;
389 
390  dictionary->instance = malloc(sizeof(ion_skiplist_t));
391 
392  if (NULL == dictionary->instance) {
393  return err_out_of_memory;
394  }
395 
396  dictionary->instance->compare = compare;
398 
399  pnum = 1;
400  pden = 4;
401 
402  ion_err_t result = sl_initialize((ion_skiplist_t *) dictionary->instance, key_type, key_size, value_size, dictionary_size, pnum, pden);
403 
404  if ((err_ok == result) && (NULL != handler)) {
405  dictionary->handler = handler;
406  }
407 
408  return result;
409 }
Struct of the Skiplist, holds metadata and the entry point into the skiplist.
ion_dictionary_handler_t * handler
ion_dictionary_parent_t * instance
ion_err_t sl_initialize(ion_skiplist_t *skiplist, ion_key_type_t key_type, int key_size, int value_size, int maxheight, int pnum, int pden)
Initializes an in-memory skiplist.
Definition: skip_list.c:41
char ion_err_t
The error type used to store error codes.
Definition: kv_system.h:226
ion_dictionary_type_t type
#define UNUSED(x)
Definition: kv_system.h:102
ion_dictionary_compare_t compare

Here is the call graph for this function:

Here is the caller graph for this function:

ion_status_t sldict_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 412 of file skip_list_handler.c.

415  {
416  return sl_delete((ion_skiplist_t *) dictionary->instance, key);
417 }
ion_status_t sl_delete(ion_skiplist_t *skiplist, ion_key_t key)
Attempts to delete all key/value pairs stored at the given key.
Definition: skip_list.c:261
Struct of the Skiplist, holds metadata and the entry point into the skiplist.
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:

ion_err_t sldict_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 420 of file skip_list_handler.c.

422  {
423  ion_err_t result = sl_destroy((ion_skiplist_t *) dictionary->instance);
424 
425  free(dictionary->instance);
426  dictionary->instance = NULL;
427  return result;
428 }
Struct of the Skiplist, holds metadata and the entry point into the skiplist.
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 sl_destroy(ion_skiplist_t *skiplist)
Destroys the skiplist in memory.
Definition: skip_list.c:95

Here is the call graph for this function:

Here is the caller graph for this function:

ion_err_t sldict_destroy_dictionary ( ion_dictionary_id_t  id)

Deletes an instance of a closed dictionary.

Parameters
idThe identifier identifying the dictionary to destroy.
Returns
Status of dictionary deletion.

Definition at line 431 of file skip_list_handler.c.

433  {
434  UNUSED(id);
435  return err_not_implemented;
436 }
#define UNUSED(x)
Definition: kv_system.h:102

Here is the caller graph for this function:

void sldict_init ( ion_dictionary_handler_t handler)

Registers a skiplist handler to a dictionary instance.

Binds each unique skiplist function to the generic dictionary interface. Only needs to be called once when the skiplist 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 351 of file skip_list_handler.c.

353  {
354  handler->insert = sldict_insert;
355  handler->get = sldict_get;
357  handler->remove = sldict_delete;
360  handler->update = sldict_update;
361  handler->find = sldict_find;
364 }
ion_status_t(* insert)(ion_dictionary_t *, ion_key_t, ion_value_t)
ion_err_t sldict_find(ion_dictionary_t *dictionary, ion_predicate_t *predicate, ion_dict_cursor_t **cursor)
Finds multiple keys based on the provided predicate.
ion_status_t sldict_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_err_t sldict_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 sldict_close_dictionary(ion_dictionary_t *dictionary)
Closes a skiplist instance of a dictionary.
ion_status_t(* update)(ion_dictionary_t *, ion_key_t, ion_value_t)
ion_status_t sldict_delete(ion_dictionary_t *dictionary, ion_key_t key)
Deletes the key and associated value from the given dictionary instance.
ion_err_t sldict_destroy_dictionary(ion_dictionary_id_t id)
Deletes an instance of a closed dictionary.
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_status_t sldict_insert(ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
Inserts a key and value pair into the dictionary.
ion_err_t(* find)(ion_dictionary_t *, ion_predicate_t *, ion_dict_cursor_t **)
ion_err_t sldict_delete_dictionary(ion_dictionary_t *dictionary)
Deletes an instance of a dictionary and its associated data.
ion_status_t sldict_get(ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
Queries a dictionary instance for a given key and returns the corresponding value.
ion_err_t sldict_open_dictionary(ion_dictionary_handler_t *handler, ion_dictionary_t *dictionary, ion_dictionary_config_info_t *config, ion_dictionary_compare_t compare)
Opens a specific skiplist instance of a dictionary.
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 sldict_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 367 of file skip_list_handler.c.

371  {
372  return sl_insert((ion_skiplist_t *) dictionary->instance, key, value);
373 }
ion_status_t sl_insert(ion_skiplist_t *skiplist, ion_key_t key, ion_value_t value)
Inserts a key value pair into the skiplist.
Definition: skip_list.c:115
Struct of the Skiplist, holds metadata and the entry point into the skiplist.
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:

ion_status_t sldict_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 439 of file skip_list_handler.c.

443  {
444  return sl_update((ion_skiplist_t *) dictionary->instance, key, value);
445 }
Struct of the Skiplist, holds metadata and the entry point into the skiplist.
ion_dictionary_parent_t * instance
#define key(k)
Definition: bpp_tree.c:75
ion_status_t sl_update(ion_skiplist_t *skiplist, ion_key_t key, ion_value_t value)
Updates the value stored at key with the new value.
Definition: skip_list.c:225

Here is the call graph for this function:

Here is the caller graph for this function: