Dictionary.h
Go to the documentation of this file.
1 /******************************************************************************/
36 /******************************************************************************/
37 
38 #if !defined(PROJECT_CPP_DICTIONARY_H)
39 #define PROJECT_CPP_DICTIONARY_H
40 
41 #include "../dictionary/dictionary.h"
42 #include "../dictionary/dictionary_types.h"
43 #include "../key_value/kv_system.h"
44 #include "../dictionary/ion_master_table.h"
45 
46 #include "Cursor.h"
47 
48 template<typename K, typename V>
49 class Dictionary {
50 public:
51 
59 
61 ) {
62  this->deleteDictionary();
63 }
64 
86  ion_dictionary_id_t dict_id,
87  ion_key_type_t k_type,
88  ion_key_size_t k_size,
89  ion_value_size_t v_size,
90  ion_dictionary_size_t dictionary_size
91 ) {
92  key_type = k_type;
93  key_size = k_size;
94  value_size = v_size;
95  dict_size = dictionary_size;
96 
97  ion_err_t err = dictionary_create(&handler, &dict, dict_id, k_type, k_size, v_size, dictionary_size);
98 
99  last_status.error = err;
100 
101  return err;
102 }
103 
115  K key,
116  V value
117 ) {
118  ion_key_t ion_key = &key;
119  ion_value_t ion_value = &value;
120 
121  ion_status_t status = dictionary_insert(&dict, ion_key, ion_value);
122 
123  this->last_status = status;
124 
125  return status;
126 }
127 
136 V
137 get(
138  K key
139 ) {
140  ion_key_t ion_key = &key;
141  ion_byte_t ion_value[dict.instance->record.value_size];
142 
143  this->last_status = dictionary_get(&dict, ion_key, ion_value);
144 
145  return *((V *) ion_value);
146 }
147 
157  K key
158 ) {
159  ion_key_t ion_key = &key;
160  ion_status_t status = dictionary_delete(&dict, ion_key);
161 
162  this->last_status = status;
163 
164  return status;
165 }
166 
178  K key,
179  V value
180 ) {
181  ion_key_t ion_key = &key;
182  ion_value_t ion_value = &value;
183  ion_status_t status = dictionary_update(&dict, ion_key, ion_value);
184 
185  this->last_status = status;
186 
187  return status;
188 }
189 
195 ion_err_t
197 ) {
199 
200  last_status.error = err;
201 
202  return err;
203 }
204 
211 ion_err_t
214 ) {
216 
217  last_status.error = error;
218 
219  return error;
220 }
221 
229 ion_err_t
231  ion_dictionary_config_info_t config_info
232 ) {
233  ion_err_t err = dictionary_open(&handler, &dict, &config_info);
234 
235  key_type = config_info.type;
236  key_size = config_info.key_size;
237  value_size = config_info.value_size;
238  dict_size = config_info.dictionary_size;
239  last_status.error = err;
240 
241  return err;
242 }
243 
247 ion_err_t
249 ) {
250  ion_err_t err = dictionary_close(&dict);
251 
252  last_status.error = err;
253 
254  return err;
255 }
256 
267 Cursor<K, V> *
269  K min_key,
270  K max_key
271 ) {
273  ion_key_t ion_min_key = &min_key;
274  ion_key_t ion_max_key = &max_key;
275 
276  dictionary_build_predicate(&predicate, predicate_range, ion_min_key, ion_max_key);
277  return new Cursor<K, V>(&dict, &predicate);
278 }
279 
288 Cursor<K, V> *
290  K key
291 ) {
293  ion_key_t ion_key = &key;
294 
295  dictionary_build_predicate(&predicate, predicate_equality, ion_key);
296  return new Cursor<K, V>(&dict, &predicate);
297 }
298 
305 Cursor<K, V> *
307 ) {
309 
311  return new Cursor<K, V>(&dict, &predicate);
312 }
313 };
314 
315 #endif /* PROJECT_CPP_DICTIONARY_H */
unsigned char ion_byte_t
A byte type.
Definition: kv_system.h:232
ion_key_type_t key_type
Definition: Dictionary.h:54
enum ION_KEY_TYPE ion_key_type_t
This is the available key types for ION_DB. All types will be based on system defines.
ion_record_info_t record
int ion_value_size_t
The size (length) of a dictionary value in bytes.
Definition: kv_system.h:256
ion_value_size_t value_size
Definition: Dictionary.h:56
ion_dictionary_parent_t * instance
Cursor< K, V > * allRecords()
Sets up cursor and predicate in order to find all records present in the dictionary.
Definition: Dictionary.h:306
unsigned int ion_dictionary_id_t
A type used to identify dictionaries, specifically in the master table.
unsigned int ion_dictionary_size_t
The implementation specific size of the dictionary.
Definition: kv_system.h:264
Struct containing details for opening a dictionary previously created.
ion_status_t deleteRecord(K key)
Delete a value given a key.
Definition: Dictionary.h:156
#define key(k)
Definition: bpp_tree.c:75
ion_status_t dictionary_update(ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
Update all records with a given key.
Definition: dictionary.c:169
ion_err_t error
Definition: kv_system.h:291
ion_status_t dictionary_delete(ion_dictionary_t *dictionary, ion_key_t key)
Delete a value given a key.
Definition: dictionary.c:199
ion_status_t dictionary_insert(ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
Insert a value into a dictionary.
Definition: dictionary.c:151
char ion_err_t
The error type used to store error codes.
Definition: kv_system.h:226
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.
Definition: dictionary.c:125
void * ion_key_t
A dictionary key.
Definition: kv_system.h:241
void * ion_value_t
A dictionary value.
Definition: kv_system.h:246
ion_err_t open(ion_dictionary_config_info_t config_info)
Opens a dictionary, given the desired config.
Definition: Dictionary.h:230
A dictionary contains information regarding an instance of the storage element and the associated han...
ion_status_t dictionary_get(ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
Retrieve a value given a key.
Definition: dictionary.c:160
Definition: Cursor.h:42
ion_status_t insert(K key, V value)
Insert a value into a dictionary.
Definition: Dictionary.h:114
ion_key_size_t key_size
Definition: Dictionary.h:55
ion_err_t dictionary_destroy_dictionary(ion_dictionary_handler_t *handler, ion_dictionary_id_t id)
Destroys dictionary.
Definition: dictionary.c:185
A simple implementation of an iterator for the C++ Wrapper interface of IonDB.
Cursor< K, V > * range(K min_key, K max_key)
Sets up cursor and predicate to perform a range query on a dictionary.
Definition: Dictionary.h:268
A supertype for cursor predicate objects.
ion_err_t dictionary_delete_dictionary(ion_dictionary_t *dictionary)
Destroys dictionary.
Definition: dictionary.c:178
Cursor< K, V > * equality(K key)
Sets up cursor and predicate perform an equality query on a dictionary for a given key...
Definition: Dictionary.h:289
ion_err_t destroyDictionary(ion_dictionary_id_t id)
Destroys dictionary.
Definition: Dictionary.h:212
ion_status_t last_status
Definition: Dictionary.h:58
ion_dictionary_handler_t handler
Definition: Dictionary.h:52
ion_err_t dictionary_close(ion_dictionary_t *dictionary)
Closes a dictionary.
Definition: dictionary.c:372
#define error(rc)
Definition: bpp_tree.c:151
ion_status_t update(K key, V value)
Update all records with a given key.
Definition: Dictionary.h:177
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.
Definition: dictionary.c:287
ion_dictionary_size_t dictionary_size
int ion_key_size_t
The size (length) of a dictionary key in bytes.
Definition: kv_system.h:251
ion_dictionary_t dict
Definition: Dictionary.h:53
ion_err_t close()
Closes a dictionary.
Definition: Dictionary.h:248
ion_err_t deleteDictionary()
Deletes dictionary.
Definition: Dictionary.h:196
ion_err_t initializeDictionary(ion_dictionary_id_t dict_id, ion_key_type_t k_type, ion_key_size_t k_size, ion_value_size_t v_size, ion_dictionary_size_t dictionary_size)
Creates a dictionary with a specific identifier (for use through the master table).
Definition: Dictionary.h:85
ion_dictionary_size_t dict_size
Definition: Dictionary.h:57
ion_value_size_t value_size
Definition: kv_system.h:309
ion_err_t dictionary_build_predicate(ion_predicate_t *predicate, ion_predicate_type_t type,...)
Builds a predicate based on the type given.
Definition: dictionary.c:512
A dictionary_handler is responsible for dealing with the specific interface for an underlying diction...
A status object that describes the result of a dictionary operation.
Definition: kv_system.h:290