Description
- See also
- For more information, refer to dictionary.h.
- 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 dictionary.c.
Functions | |
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 filename for any implementation instance. More... | |
char | dictionary_compare_char_array (ion_key_t first_key, ion_key_t second_key, ion_key_size_t key_size) |
Compare any two character (byte) arrays. These are not assumed to be null-terminated. More... | |
char | dictionary_compare_null_terminated_string (ion_key_t first_key, ion_key_t second_key, ion_key_size_t key_size) |
Compare any two null-terminated strings. More... | |
ion_dictionary_compare_t | dictionary_switch_compare (ion_key_type_t key_type) |
ion_err_t | dictionary_create (ion_dictionary_handler_t *handler, ion_dictionary_t *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) |
Creates as instance of a specific type of dictionary. More... | |
ion_status_t | dictionary_insert (ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value) |
Insert a value into a dictionary. More... | |
ion_status_t | dictionary_get (ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value) |
Retrieve a value given a key. More... | |
ion_status_t | dictionary_update (ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value) |
Update all records with a given key. More... | |
ion_err_t | dictionary_delete_dictionary (ion_dictionary_t *dictionary) |
Destroys dictionary. More... | |
ion_err_t | dictionary_destroy_dictionary (ion_dictionary_handler_t *handler, ion_dictionary_id_t id) |
Destroys dictionary. More... | |
ion_status_t | dictionary_delete (ion_dictionary_t *dictionary, ion_key_t key) |
Delete a value given a key. More... | |
char | dictionary_compare_unsigned_value (ion_key_t first_key, ion_key_t second_key, ion_key_size_t key_size) |
Compares two unsigned integer numeric keys. More... | |
char | dictionary_compare_signed_value (ion_key_t first_key, ion_key_t second_key, ion_key_size_t key_size) |
Compares two signed integer numeric keys. More... | |
ion_err_t | dictionary_open (ion_dictionary_handler_t *handler, ion_dictionary_t *dictionary, ion_dictionary_config_info_t *config) |
Opens a dictionary, given the desired config. More... | |
ion_err_t | dictionary_close (ion_dictionary_t *dictionary) |
Closes a dictionary. More... | |
void | dictionary_destroy_predicate_equality (ion_predicate_t **predicate) |
Destroys an equality predicate. More... | |
void | dictionary_destroy_predicate_range (ion_predicate_t **predicate) |
Destroys a range predicate. More... | |
void | dictionary_destroy_predicate_all_records (ion_predicate_t **predicate) |
Destroys an all records predicate. More... | |
ion_err_t | dictionary_build_predicate (ion_predicate_t *predicate, ion_predicate_type_t type,...) |
Builds a predicate based on the type given. More... | |
ion_err_t | dictionary_find (ion_dictionary_t *dictionary, ion_predicate_t *predicate, ion_dict_cursor_t **cursor) |
Uses the given predicate and cursor to search the dictionary. More... | |
ion_boolean_t | test_predicate (ion_dict_cursor_t *cursor, ion_key_t key) |
Tests the supplied key against the predicate registered in the cursor . If the supplied cursor if of the type equality, the key is tested for equality with that cursor's equality value and returns boolean_true if the test passes. If the supplied cursor is of the type predicate_range, the key is tested for whether it falls in the range of that cursor's registered upper_bound and lower_bound and returns boolean_true if it does. In the case that the supplied cursor is of the type predicate_all_records, boolean_true is returned. If any of the above tests fail, or if the type of the cursor is not mentioned above, boolean_false is returned. More... | |
Function Documentation
ion_err_t dictionary_build_predicate | ( | ion_predicate_t * | predicate, |
ion_predicate_type_t | type, | ||
... | |||
) |
Builds a predicate based on the type given.
The caller is responsible for allocating the memory needed for the predicate.
- Parameters
-
predicate A pointer to the pre-allocated predicate to be initialized. type The type of predicate to build. ... Extra variables necessary for initializing the predicate. This depends on the type of predicate being initialized. Equality: 1st vparam is target key. Range: 1st vparam is lower bound, 2nd vparam is upper bound. All_records: No vparams used. Predicate: Not yet implemented
- Returns
- An error describing the result of open operation.
Definition at line 512 of file dictionary.c.
ion_err_t dictionary_close | ( | ion_dictionary_t * | dictionary | ) |
Closes a dictionary.
- Parameters
-
dictionary A pointer to the dictionary object to be closed.
- Returns
- An error describing the result of open operation.
Definition at line 372 of file dictionary.c.
char dictionary_compare_char_array | ( | ion_key_t | first_key, |
ion_key_t | second_key, | ||
ion_key_size_t | key_size | ||
) |
Compare any two character (byte) arrays. These are not assumed to be null-terminated.
- Parameters
-
first_key The first (left) key being compared. second_key The second (right) key being compared. key_size The size of the keys being compared.
- Returns
- The resulting comparison value.
Definition at line 61 of file dictionary.c.
char dictionary_compare_null_terminated_string | ( | ion_key_t | first_key, |
ion_key_t | second_key, | ||
ion_key_size_t | key_size | ||
) |
Compare any two null-terminated strings.
- Parameters
-
first_key The first (left) key being compared. second_key The second (right) key being compared. key_size The (maximum) size of the keys being compared.
- Returns
- The resulting comparison value.
Definition at line 80 of file dictionary.c.
char dictionary_compare_signed_value | ( | ion_key_t | first_key, |
ion_key_t | second_key, | ||
ion_key_size_t | key_size | ||
) |
Compares two signed integer numeric keys.
Compares two ion_key_t assuming that they are of arbitrary length and integer, signed and numeric (ie not a char[]). The following values will be returned:
@p first_key > @p second_key return 1 @p first_key == @p second_key return 0 @p first_key < @p second_key return -1
This works for all integer numeric types for signed values as long as both keys are of the same type.
- Parameters
-
first_key The pointer to the first key in the comparison. second_key The pointer to the second key in the comparison. key_size The length of the key in bytes.
- Returns
- The resulting comparison value.
Definition at line 239 of file dictionary.c.
char dictionary_compare_unsigned_value | ( | ion_key_t | first_key, |
ion_key_t | second_key, | ||
ion_key_size_t | key_size | ||
) |
Compares two unsigned integer numeric keys.
Compares two ion_key_t assuming that they are of arbitrary length and integer, unsigned and numeric (ie not a char[]). The following values will be returned:
@p first_key > @p second_key return 1 @p first_key == @p second_key return 0 @p first_key < @p second_key return -1
This works for all integer numeric types for unsigned values as long as both keys are of the same type. You'll notice a weird math expression being expressed when computing the return value. This value is written in this a weird way to give us the desired {-1, 0, 1} range of return values. Draw out a table and the reasoning will become immediately obvious.
- Parameters
-
first_key The pointer to the first key in the comparison. second_key The pointer to the second key in the comaparison. key_size The length of the key in bytes.
- Returns
- The resulting comparison value.
Definition at line 207 of file dictionary.c.
ion_err_t dictionary_create | ( | ion_dictionary_handler_t * | handler, |
ion_dictionary_t * | 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 | ||
) |
Creates as instance of a specific type of dictionary.
This function is not to be used if you are using the master table.
- Parameters
-
handler A pointer to a handler object containing pointers to all the functions necessary for this dictionary instance. dictionary A pointer to a dictionary object that will be used to access all dictionary operations. id The identifier used to identify the dictionary. key_type The type of the key. key_size The size of the key type to store. value_size The size of the value to store. dictionary_size The implementation specific dictionary size. The interpretation of this value is dependent on the dictionary implementaion being used.
- Returns
- A status describing the result of dictionary creation.
Definition at line 125 of file dictionary.c.
ion_status_t dictionary_delete | ( | ion_dictionary_t * | dictionary, |
ion_key_t | key | ||
) |
Delete a value given a key.
- Parameters
-
dictionary A pointer to the dictionary to be intialized. key The key to retrieve the value for.
- Returns
- A status describing the result of the deletion.
Definition at line 199 of file dictionary.c.
ion_err_t dictionary_delete_dictionary | ( | ion_dictionary_t * | dictionary | ) |
Destroys dictionary.
- Parameters
-
dictionary The dictionary instance to destroy.
- Returns
- The status of the total destruction of the dictionary.
Definition at line 178 of file dictionary.c.
ion_err_t dictionary_destroy_dictionary | ( | ion_dictionary_handler_t * | handler, |
ion_dictionary_id_t | id | ||
) |
Destroys dictionary.
- Parameters
-
handler A pointer to the implementation of dictionary to destroy. id The identifier identifying the dictionary to destroy.
- Returns
- The status of the total destruction of the dictionary.
Definition at line 185 of file dictionary.c.
void dictionary_destroy_predicate_all_records | ( | ion_predicate_t ** | predicate | ) |
Destroys an all records predicate.
This function should not be called directly. Instead, it is set while building the predicate.
- Parameters
-
predicate A pointer to the pointer to the predicate object being destroyed.
Definition at line 502 of file dictionary.c.
void dictionary_destroy_predicate_equality | ( | ion_predicate_t ** | predicate | ) |
Destroys an equality predicate.
This function should not be called directly. Instead, it is set while building the predicate.
- Parameters
-
predicate A pointer to the pointer to the predicate object being destroyed.
Definition at line 463 of file dictionary.c.
void dictionary_destroy_predicate_range | ( | ion_predicate_t ** | predicate | ) |
Destroys a range predicate.
This function should not be called directly. Instead, it is set while building the predicate.
- Parameters
-
predicate A pointer to the pointer to the predicate object being destroyed.
Definition at line 482 of file dictionary.c.
ion_err_t dictionary_find | ( | ion_dictionary_t * | dictionary, |
ion_predicate_t * | predicate, | ||
ion_dict_cursor_t ** | cursor | ||
) |
Uses the given predicate and cursor to search the dictionary.
This function will allocate and initialize the cursor. This means that it must freed once we are done. This function sets up a cursor for traversal.
- Parameters
-
dictionary A pointer to the dictionary object to be created. predicate A pointer predicate object to be used for the search. cursor A pointer to the pointer for a cursor object. Note that if the cursor pointer object is pointing to a valid cursor already, we will leak memory.
- Returns
- An error code describing the result of the operation.
Definition at line 562 of file dictionary.c.
ion_status_t dictionary_get | ( | ion_dictionary_t * | dictionary, |
ion_key_t | key, | ||
ion_value_t | value | ||
) |
Retrieve a value given a key.
- Parameters
-
dictionary A pointer to the dictionary to be intialized. key The key to retrieve the value for. value A pointer to the value byte array to copy data into.
- Returns
- A status describing the result of the retrieval.
Definition at line 160 of file dictionary.c.
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 filename for any implementation instance.
- Parameters
-
[in] id Given ID to use to generate a unique filename. [in] ext Given implementation specific filename extension to be used. [out] filename Char buffer to write-back into. This must be allocated memory.
- Returns
- How many characters would have been written. It is a good idea to check that this does not exceed ION_MAX_FILENAME_LENGTH.
Definition at line 41 of file dictionary.c.
ion_status_t dictionary_insert | ( | ion_dictionary_t * | dictionary, |
ion_key_t | key, | ||
ion_value_t | value | ||
) |
Insert a value into a dictionary.
- Parameters
-
dictionary The dictionary that the value is to be inserted to key The key that identifies value
.value The value to store under key
.
- Returns
- A status describing the result of the insertion.
Definition at line 151 of file dictionary.c.
ion_err_t dictionary_open | ( | ion_dictionary_handler_t * | handler, |
ion_dictionary_t * | dictionary, | ||
ion_dictionary_config_info_t * | config | ||
) |
Opens a dictionary, given the desired config.
- Parameters
-
handler A pointer to the dictionary handler object to be used. dictionary A pointer to the dictionary object to be manipulated. config A pointer to the configuration object to be used to open the dictionary with.
- Returns
- An error describing the result of open operation.
Definition at line 287 of file dictionary.c.
ion_dictionary_compare_t dictionary_switch_compare | ( | ion_key_type_t | key_type | ) |
Definition at line 89 of file dictionary.c.
ion_status_t dictionary_update | ( | ion_dictionary_t * | dictionary, |
ion_key_t | key, | ||
ion_value_t | value | ||
) |
Update all records with a given key.
- Parameters
-
dictionary A pointer to the dictionary instance to update. key The key to identify records for updating. value The value to update records with.
Definition at line 169 of file dictionary.c.
ion_boolean_t test_predicate | ( | ion_dict_cursor_t * | cursor, |
ion_key_t | key | ||
) |
Tests the supplied key
against the predicate registered in the cursor
. If the supplied cursor
if of the type equality, the key is tested for equality with that cursor's equality value and returns boolean_true if the test passes. If the supplied cursor
is of the type predicate_range, the key is tested for whether it falls in the range of that cursor's registered upper_bound and lower_bound and returns boolean_true if it does. In the case that the supplied cursor
is of the type predicate_all_records, boolean_true is returned. If any of the above tests fail, or if the type of the cursor
is not mentioned above, boolean_false is returned.
- Parameters
-
cursor The cursor and predicate being used to test key
against.key The key to test.
- Returns
- The result is the key passes or fails the predicate test.
Definition at line 571 of file dictionary.c.