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 
45 #include "Cursor.h"
46 
47 template<typename K, typename V>
48 class Dictionary {
49 public:
50 
58 
60 ) {
61  this->deleteDictionary();
62 }
63 
85  ion_dictionary_id_t dict_id,
86  ion_key_type_t k_type,
87  ion_key_size_t k_size,
88  ion_value_size_t v_size,
89  ion_dictionary_size_t dictionary_size
90 ) {
91  key_type = k_type;
92  key_size = k_size;
93  value_size = v_size;
94  dict_size = dictionary_size;
95 
96  ion_err_t err = dictionary_create(&handler, &dict, dict_id, k_type, k_size, v_size, dictionary_size);
97 
98  return err;
99 }
100 
112  K key,
113  V value
114 ) {
115  ion_key_t ion_key = &key;
116  ion_value_t ion_value = &value;
117 
118  ion_status_t status = dictionary_insert(&dict, ion_key, ion_value);
119 
120  this->last_status = status;
121 
122  return status;
123 }
124 
133 V
134 get(
135  K key
136 ) {
137  ion_key_t ion_key = &key;
138  ion_byte_t ion_value[dict.instance->record.value_size];
139 
140  this->last_status = dictionary_get(&dict, ion_key, ion_value);
141 
142  return *((V *) ion_value);
143 }
144 
154  K key
155 ) {
156  ion_key_t ion_key = &key;
157  ion_status_t status = dictionary_delete(&dict, ion_key);
158 
159  this->last_status = status;
160 
161  return status;
162 }
163 
175  K key,
176  V value
177 ) {
178  ion_key_t ion_key = &key;
179  ion_value_t ion_value = &value;
180  ion_status_t status = dictionary_update(&dict, ion_key, ion_value);
181 
182  this->last_status = status;
183 
184  return status;
185 }
186 
192 ion_err_t
194 ) {
196 
197  return err;
198 }
199 
206 ion_err_t
209 ) {
211 
212  return error;
213 }
214 
222 ion_err_t
224  ion_dictionary_config_info_t config_info
225 ) {
226  ion_err_t err = dictionary_open(&handler, &dict, &config_info);
227 
228  return err;
229 }
230 
234 ion_err_t
236 ) {
237  ion_err_t err = dictionary_close(&dict);
238 
239  return err;
240 }
241 
252 Cursor<K, V> *
254  K min_key,
255  K max_key
256 ) {
258  ion_key_t ion_min_key = &min_key;
259  ion_key_t ion_max_key = &max_key;
260 
261  dictionary_build_predicate(&predicate, predicate_range, ion_min_key, ion_max_key);
262  return new Cursor<K, V>(&dict, &predicate);
263 }
264 
273 Cursor<K, V> *
275  K key
276 ) {
278  ion_key_t ion_key = &key;
279 
280  dictionary_build_predicate(&predicate, predicate_equality, ion_key);
281  return new Cursor<K, V>(&dict, &predicate);
282 }
283 
290 Cursor<K, V> *
292 ) {
294 
296  return new Cursor<K, V>(&dict, &predicate);
297 }
298 };
299 
300 /* Comment to trigger commit and therefore pc-build */
301 
302 #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:53
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:55
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:291
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:153
#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_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:223
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:111
ion_key_size_t key_size
Definition: Dictionary.h:54
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:253
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:274
ion_err_t destroyDictionary(ion_dictionary_id_t id)
Destroys dictionary.
Definition: Dictionary.h:207
ion_status_t last_status
Definition: Dictionary.h:57
ion_dictionary_handler_t handler
Definition: Dictionary.h:51
ion_err_t dictionary_close(ion_dictionary_t *dictionary)
Closes a dictionary.
Definition: dictionary.c:372
#define error(rc)
Definition: bpp_tree.c:139
ion_status_t update(K key, V value)
Update all records with a given key.
Definition: Dictionary.h:174
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
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:52
ion_err_t close()
Closes a dictionary.
Definition: Dictionary.h:235
ion_err_t deleteDictionary()
Deletes dictionary.
Definition: Dictionary.h:193
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:84
ion_dictionary_size_t dict_size
Definition: Dictionary.h:56
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