MasterTable.h
Go to the documentation of this file.
1 /******************************************************************************/
36 /******************************************************************************/
37 
38 #if !defined(PROJECT_CPP_MASTERTABLE_H)
39 #define PROJECT_CPP_MASTERTABLE_H
40 
41 #include "../dictionary/ion_master_table.h"
42 #include "Dictionary.h"
43 #include "BppTree.h"
44 #include "FlatFile.h"
45 #include "OpenAddressFileHash.h"
46 #include "OpenAddressHash.h"
47 #include "SkipList.h"
48 #include "LinearHash.h"
49 
50 class MasterTable {
51 public:
52 
54 
56 ) {
57  this->initializeMasterTable();
58 }
59 
61 ) {
62  this->deleteMasterTable();
63 }
64 
72 ) {
73  return ion_init_master_table();
74 }
75 
82 ) {
83  return ion_close_master_table();
84 }
85 
94 ) {
96 }
97 
102 ion_err_t
104 ) {
105  return ion_delete_master_table();
106 }
107 
118 template<typename K, typename V>
119 ion_err_t
122  ion_dictionary_size_t dictionary_size
123 ) {
125 
127 
128  if (err_ok != err) {
129  return err;
130  }
131 
132  dictionary->dict.instance->id = id;
133 
135  .id = dictionary->dict.instance->id, .use_type = 0, .type = dictionary->dict.instance->key_type, .key_size = dictionary->dict.instance->record.key_size, .value_size = dictionary->dict.instance->record.value_size, .dictionary_size = dictionary_size, .dictionary_type = dictionary->dict.instance->type
136  };
137 
139 }
140 
147 ) {
149 }
150 
158 ion_err_t
161 ) {
162  return ion_switch_handler(type, &handler);
163 }
164 
175 ion_err_t
179 ) {
180  return ion_lookup_in_master_table(id, config);
181 }
182 
200 ion_err_t
203  ion_dict_use_t use_type,
204  char whence
205 ) {
206  return ion_find_by_use_master_table(config, use_type, whence);
207 }
208 
213 ion_err_t
216 ) {
217  return ion_delete_from_master_table(id);
218 }
219 
230 template<typename K, typename V>
231 ion_err_t
235 ) {
236  ion_err_t err;
238 
239  err = ion_lookup_in_master_table(id, &config);
240 
241  /* Lookup for id failed. */
242  if (err_ok != err) {
243  return err_uninitialized;
244  }
245 
246  err = ion_switch_handler(config.dictionary_type, &handler);
247 
248  if (err_ok != err) {
249  return err;
250  }
251 
252  dictionary->dict.handler = &handler;
253 
254  err = dictionary->open(config);
255 
256  return err;
257 }
258 
266 template<typename K, typename V>
267 ion_err_t
270 ) {
271  ion_err_t err = dictionary->close();
272 
273  return err;
274 }
275 
297 template<typename K, typename V>
300  ion_key_type_t key_type,
301  K k,
302  V v,
303  ion_key_size_t key_size,
304  ion_value_size_t value_size,
305  ion_dictionary_size_t dictionary_size,
306  ion_dictionary_type_t dictionary_type
307 ) {
308  UNUSED(k);
309  UNUSED(v);
310 
312 
314 
315  switch (dictionary_type) {
317  dictionary = new BppTree<K, V>(id, key_type, key_size, value_size);
318 
319  break;
320  }
321 
323  dictionary = new FlatFile<K, V>(id, key_type, key_size, value_size, dictionary_size);
324 
325  break;
326  }
327 
329  dictionary = new OpenAddressFileHash<K, V>(id, key_type, key_size, value_size, dictionary_size);
330 
331  break;
332  }
333 
335  dictionary = new OpenAddressHash<K, V>(id, key_type, key_size, value_size, dictionary_size);
336 
337  break;
338  }
339 
341  dictionary = new SkipList<K, V>(id, key_type, key_size, value_size, dictionary_size);
342 
343  break;
344  }
345 
347  dictionary = new LinearHash<K, V>(id, key_type, key_size, value_size, dictionary_size);
348 
349  break;
350  }
351 
353  dictionary = new SkipList<K, V>(id, key_type, key_size, value_size, dictionary_size);
355  break;
356  }
357  }
358 
359  if ((dictionary_type != dictionary_type_error_t) && (ion_dictionary_status_error != dictionary->dict.status)) {
360  ion_err_t err = addToMasterTable(dictionary, dictionary_size);
361 
362  if (err_ok != err) {
364  }
365  }
366 
367  return dictionary;
368 }
369 
370 template<typename K, typename V>
371 ion_err_t
374 ) {
375  ion_dictionary_id_t id = dictionary->dict.instance->id;
376 
377  delete dictionary;
378 
379  return ion_delete_from_master_table(id);
380 }
381 };
382 
383 #endif /* PROJECT_CPP_MASTERTABLE_H */
C++ implementation of a B+ tree dictionary.
ion_err_t ion_lookup_in_master_table(ion_dictionary_id_t id, ion_dictionary_config_info_t *config)
Looks up the config of the given id.
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
ion_byte_t ion_dict_use_t
A type describing how a dictionary is used.
ion_dictionary_id_t getNextID()
Returns the next dictionary ID.
Definition: MasterTable.h:146
ion_dictionary_type_t dictionary_type
ion_err_t initializeMasterTable()
Opens the master table.
Definition: MasterTable.h:71
int ion_value_size_t
The size (length) of a dictionary value in bytes.
Definition: kv_system.h:256
ion_err_t findByUse(ion_dictionary_config_info_t *config, ion_dict_use_t use_type, char whence)
Find first or last dictionary in master table with a given use.
Definition: MasterTable.h:201
The C++ implementation of a linear hash dictionary.
ion_dictionary_handler_t * handler
ion_dictionary_parent_t * instance
ion_err_t ion_switch_handler(ion_dictionary_type_t type, ion_dictionary_handler_t *handler)
Retrieves the type of dictionary stored under a particular id in the master table.
enum ION_DICTIONARY_TYPE ion_dictionary_type_t
This is the available dictionary types for ION_DB. All types will be based on system defines...
ion_err_t openDictionary(Dictionary< K, V > *dictionary, ion_dictionary_id_t id)
Finds the target dictionary and opens it.
Definition: MasterTable.h:232
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_err_t closeDictionary(Dictionary< K, V > *dictionary)
Closes a given dictionary.
Definition: MasterTable.h:268
ion_err_t deleteMasterTable()
Deletes the master table.
Definition: MasterTable.h:103
ion_err_t ion_delete_master_table(void)
Deletes the master table.
ion_dictionary_handler_t handler
Definition: MasterTable.h:53
ion_err_t ion_master_table_write(ion_dictionary_config_info_t *config, long where)
Write a record to the master table.
char ion_err_t
The error type used to store error codes.
Definition: kv_system.h:226
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_err_t ion_delete_from_master_table(ion_dictionary_id_t id)
Deletes a dictionary from the master table.
ion_dictionary_id_t id
ion_err_t lookupMasterTable(ion_dictionary_id_t id, ion_dictionary_config_info_t *config)
Looks up the config of the given id.
Definition: MasterTable.h:176
ion_err_t ion_init_master_table(void)
Opens the master table.
ion_err_t deleteFromMasterTable(ion_dictionary_id_t id)
Deletes a dictionary from the master table.
Definition: MasterTable.h:214
The C++ implementation of a skip list dictionary.
ion_key_size_t key_size
Definition: kv_system.h:307
The C++ implementation of an open address hash based dictionary.
ion_dictionary_type_t type
#define UNUSED(x)
Definition: kv_system.h:102
ion_dictionary_id_t ion_master_table_next_id
Master table resposible for managing instances.
The C++ implementation of a flat file dictionary.
ion_err_t ion_close_master_table(void)
Closes the master table.
ion_err_t closeAllMasterTable()
Closes the master table and all dictionary instances in it.
Definition: MasterTable.h:93
ion_key_type_t key_type
Interface describing how user interacts with general dictionaries using C++.
ion_err_t addToMasterTable(Dictionary< K, V > *dictionary, ion_dictionary_size_t dictionary_size)
Adds the given dictionary to the master table.
Definition: MasterTable.h:120
#define ION_MASTER_TABLE_WRITE_FROM_END
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 ion_close_all_master_table(void)
Closes the master table and all dictionary instances within it.
ion_err_t initializeHandler(ion_dictionary_type_t type)
Retrieves the type of dictionary stored under a particular id in the master table.
Definition: MasterTable.h:159
ion_err_t ion_find_by_use_master_table(ion_dictionary_config_info_t *config, ion_dict_use_t use_type, char whence)
Find first or last dictionary in master table with a given use.
ion_err_t ion_master_table_get_next_id(ion_dictionary_id_t *id)
Returns the next dictionary ID, then increments.
The C++ implementation of an open address file hash based dictionary.
ion_dictionary_status_t status
ion_err_t closeMasterTable()
Closes the master table.
Definition: MasterTable.h:81
ion_value_size_t value_size
Definition: kv_system.h:309
ion_err_t deleteDictionary(Dictionary< K, V > *dictionary)
Definition: MasterTable.h:372
Dictionary< K, V > * initializeDictionary(ion_key_type_t key_type, K k, V v, ion_key_size_t key_size, ion_value_size_t value_size, ion_dictionary_size_t dictionary_size, ion_dictionary_type_t dictionary_type)
Creates a dictionary of a specified implementation.
Definition: MasterTable.h:299
A dictionary_handler is responsible for dealing with the specific interface for an underlying diction...