#include "skip_list_handler.h"
Description
Handler liaison between dictionary API and skiplist implementation.
- Copyright
- Copyright 2017 The University of British Columbia, IonDB Project Contributors (see AUTHORS.md)
- 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.c.
Function Documentation
ion_err_t sldict_close_dictionary | ( | ion_dictionary_t * | dictionary | ) |
Closes a skiplist instance of a dictionary.
- Parameters
-
dictionary A pointer to the specific dictionary instance to be closed.
- Returns
- The status of closing the dictionary.
Definition at line 125 of file skip_list_handler.c.
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_size Size of the key in bytes. value_size Size of the value in bytes. dictionary_size compare handler Handler to be bound to the dictionary instance being created. Assumption is that the handler has been initialized prior. dictionary Pointer 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.
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
-
dictionary The instance of the dictionary to delete from. key The key to be deleted.
- Returns
- Status of deletion.
Definition at line 412 of file skip_list_handler.c.
ion_err_t sldict_delete_dictionary | ( | ion_dictionary_t * | dictionary | ) |
Deletes an instance of a dictionary and its associated data.
- Parameters
-
dictionary The instance of the dictionary to be deleted.
- Returns
- Status of dictionary deletion.
Definition at line 420 of file skip_list_handler.c.
void sldict_destroy_cursor | ( | ion_dict_cursor_t ** | cursor | ) |
Destroys the cursor.
Destroys the cursor when the user is finished with it. All memory internally used by the cursor is freed as well. Cursor pointers will be set to NULL as per IonDB specification.
- Parameters
-
cursor Pointer to a pointer of a cursor.
Definition at line 143 of file skip_list_handler.c.
ion_err_t sldict_destroy_dictionary | ( | ion_dictionary_id_t | id | ) |
Deletes an instance of a closed dictionary.
- Parameters
-
id The identifier identifying the dictionary to destroy.
- Returns
- Status of dictionary deletion.
Definition at line 431 of file skip_list_handler.c.
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.
Finds multiple keys based on the provided predicate. Gives a cursor that allows traversal of all key/value pairs that satisfy the predicate
. Not all implementations support a find.
- Parameters
-
dictionary The instance of a dictionary to search within. predicate The predicate used to match. cursor The pointer to a cursor declared by the caller, but initialized and populated within the function.
- Returns
- Status of find.
Definition at line 168 of file skip_list_handler.c.
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
.
Queries a dictionary instance for a given key
and returns the value
within, copied into the pointer provided by the user. Assumption is that the pointer is passed unallocated, for this function to allocate. The responsibility is then on the user to free the given memory.
- Parameters
-
dictionary The instance of the dictionary to query key The key to search for. value A pointer used to hold the returned value from the query. The memory for value is assumed to be allocated and freed by the user.
- Returns
- Status of query.
Definition at line 60 of file skip_list_handler.c.
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
-
handler An 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.
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
-
dictionary The dictionary instance to insert the value into. key The key to use. value The value to use.
- Returns
- Status of insertion.
Definition at line 367 of file skip_list_handler.c.
ion_cursor_status_t sldict_next | ( | ion_dict_cursor_t * | cursor, |
ion_record_t * | record | ||
) |
Next function queries and retrieves the next key/value pair that satisfies the predicate of the cursor.
- Parameters
-
cursor The cursor used to iterate over results. record A record pointer that is allocated by the caller in which the cursor will fill with the next key/value result. The assumption is that the caller will also free this memory.
- Returns
- Status of cursor.
Definition at line 81 of file skip_list_handler.c.
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.
- Parameters
-
handler A pointer to the handler for the specific dictionary being opened. dictionary The pointer declared by the caller that will reference the instance of the dictionary opened. config The configuration info of the specific dictionary to be opened. compare Function pointer for the comparison function for the dictionary.
- Returns
- The status of opening the dictionary.
Definition at line 337 of file skip_list_handler.c.
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
-
dictionary The instance of the dictionary to be updated. key The key that is to be updated. value The new value to be used.
- Returns
- Status of update.
Definition at line 439 of file skip_list_handler.c.