linear_hash.h
Go to the documentation of this file.
1 /******************************************************************************/
35 /******************************************************************************/
36 
37 #include <stdio.h>
38 #include "linear_hash_types.h"
39 
40 #if defined(ARDUINO)
41 #include "../../serial/serial_c_iface.h"
42 #endif
43 
47  ion_dictionary_size_t dictionary_size,
48  ion_key_type_t key_type,
49  ion_key_size_t key_size,
50  ion_value_size_t value_size,
51  int initial_size,
52  int split_threshold,
53  int records_per_bucket,
54  linear_hash_table_t *linear_hash
55 );
56 
59  linear_hash_table_t *linear_hash
60 );
61 
64  linear_hash_table_t *linear_hash
65 );
66 
69  linear_hash_table_t *linear_hash
70 );
71 
72 /* decrement the count of the records stored in the linear hash */
75  linear_hash_table_t *linear_hash
76 );
77 
80  linear_hash_table_t *linear_hash
81 );
82 
85  linear_hash_table_t *linear_hash
86 );
87 
88 int
90  linear_hash_bucket_t bucket,
91  linear_hash_table_t *linear_hash
92 );
93 
94 /* split function */
96 split(
97  linear_hash_table_t *linear_hash
98 );
99 
102  ion_key_t key,
103  ion_value_t value,
104  int hash_bucket_idx,
105  linear_hash_table_t *linear_hash
106 );
107 
108 /* linear hash operations */
111  ion_byte_t *key,
112  ion_byte_t *value,
113  linear_hash_table_t *linear_hash
114 );
115 
118  ion_key_t key,
119  ion_value_t value,
120  linear_hash_table_t *linear_hash
121 );
122 
125  ion_byte_t *key,
126  linear_hash_table_t *linear_hash
127 );
128 
129 ion_err_t
131  ion_fpos_t loc,
132  ion_byte_t *key,
133  ion_byte_t *value,
134  ion_byte_t *status,
135  linear_hash_table_t *linear_hash
136 );
137 
138 ion_err_t
140  ion_fpos_t record_loc,
141  ion_byte_t *key,
142  ion_byte_t *value,
143  ion_byte_t *status,
144  linear_hash_table_t *linear_hash
145 );
146 
147 /* check if linear hash is above its split threshold */
150  linear_hash_table_t *linear_hash
151 );
152 
153 /* BUCKET OPERATIONS */
154 ion_err_t
156  int idx,
157  linear_hash_table_t *linear_hash
158 );
159 
160 /* returns the struct representing the bucket at the specified index */
161 ion_err_t
163  ion_fpos_t bucket_loc,
164  linear_hash_bucket_t *bucket,
165  linear_hash_table_t *linear_hash
166 );
167 
168 ion_err_t
170  ion_fpos_t bucket_loc,
171  linear_hash_bucket_t *bucket,
172  linear_hash_table_t *linear_hash
173 );
174 
175 ion_err_t
177  int bucket_idx,
178  ion_fpos_t *overflow_location,
179  linear_hash_table_t *linear_hash
180 );
181 
184  ion_fpos_t bucket_loc
185 );
186 
187 ion_err_t
189  ion_byte_t *key,
190  int record_count,
191  ion_byte_t *records,
192  linear_hash_table_t *linear_hash
193 );
194 
195 /* hash methods */
196 int
198  ion_byte_t *key,
199  linear_hash_table_t *linear_hash
200 );
201 
202 int
204  ion_byte_t *key,
205  linear_hash_table_t *linear_hash
206 );
207 
208 /* returns the struct representing the bucket at the specified index */
211  ion_fpos_t loc
212 );
213 
214 /* Returns the file offset where bucket with index idx begins */
217  int idx,
218  linear_hash_table_t *linear_hash
219 );
220 
221 ion_err_t
223  linear_hash_table_t *linear_hash
224 );
225 
226 void
228  linear_hash_bucket_t bucket
229 );
230 
231 void
233  linear_hash_table_t *linear_hash
234 );
235 
236 /* Write the offset of bucket idx to the map in linear hash state */
237 ion_err_t
239  int idx,
240  ion_fpos_t bucket_loc,
241  linear_hash_table_t *linear_hash
242 );
243 
244 /* ARRAY_LIST METHODS */
245 ion_err_t
247  int init_size,
248  array_list_t *array_list
249 );
250 
251 ion_err_t
253  int bucket_idx,
254  ion_fpos_t bucket_loc,
255  array_list_t *array_list
256 );
257 
260  int bucket_idx,
261  array_list_t *array_list
262 );
263 
264 ion_err_t
266  linear_hash_table_t *linear_hash
267 );
268 
269 ion_err_t
271  linear_hash_table_t *linear_hash
272 );
273 
274 void
276  linear_hash_table_t *linear_hash
277 );
ion_status_t linear_hash_delete(ion_byte_t *key, linear_hash_table_t *linear_hash)
Delete all records with keys matching the key specified in the linear hash.
Definition: linear_hash.c:867
unsigned char ion_byte_t
A byte type.
Definition: kv_system.h:232
ion_err_t linear_hash_decrement_num_records(linear_hash_table_t *linear_hash)
Helper method to decrement the number of records in the linear hash.
Definition: linear_hash.c:313
ion_err_t linear_hash_init(ion_dictionary_id_t id, ion_dictionary_size_t dictionary_size, ion_key_type_t key_type, ion_key_size_t key_size, ion_value_size_t value_size, int initial_size, int split_threshold, int records_per_bucket, linear_hash_table_t *linear_hash)
Definition: linear_hash.c:47
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_err_t linear_hash_increment_num_buckets(linear_hash_table_t *linear_hash)
Helper method to increment the number of buckets in the linear hash.
Definition: linear_hash.c:328
ion_fpos_t get_bucket_records_location(ion_fpos_t bucket_loc)
ion_err_t create_overflow_bucket(int bucket_idx, ion_fpos_t *overflow_location, linear_hash_table_t *linear_hash)
Create an overflow bucket and write it to the linear hash&#39;s .lhd file.
Definition: linear_hash.c:1240
int ion_value_size_t
The size (length) of a dictionary value in bytes.
Definition: kv_system.h:256
void print_linear_hash_distribution(linear_hash_table_t *linear_hash)
ion_err_t linear_hash_increment_next_split(linear_hash_table_t *linear_hash)
Helper method to increment the split linear hash.
Definition: linear_hash.c:349
ion_err_t split(linear_hash_table_t *linear_hash)
Performs the split operation on a linear hash instance.
Definition: linear_hash.c:364
void print_linear_hash_bucket(linear_hash_bucket_t bucket)
ion_err_t array_list_insert(int bucket_idx, ion_fpos_t bucket_loc, array_list_t *array_list)
Insert a value into an array list.
Definition: linear_hash.c:1404
int linear_hash_bucket_is_full(linear_hash_bucket_t bucket, linear_hash_table_t *linear_hash)
Helper method to check if a linear hash bucket is full.
Definition: linear_hash.c:270
ion_err_t linear_hash_update_state(linear_hash_table_t *linear_hash)
ion_err_t write_new_bucket(int idx, linear_hash_table_t *linear_hash)
Write a new bucket to the linear hash&#39;s .lhd file.
Definition: linear_hash.c:1099
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
ion_err_t linear_hash_write_record(ion_fpos_t record_loc, ion_byte_t *key, ion_byte_t *value, ion_byte_t *status, linear_hash_table_t *linear_hash)
Write record data to the location specified from the linear hash&#39;s .lhd file.
Definition: linear_hash.c:1059
#define key(k)
Definition: bpp_tree.c:75
ion_err_t linear_hash_destroy(linear_hash_table_t *linear_hash)
Close a linear hash instance and delete its associated .lhs and .lhd files.
Definition: linear_hash.c:1507
int insert_hash_to_bucket(ion_byte_t *key, linear_hash_table_t *linear_hash)
Map a key to the address space of the linear hash. Used to map records to buckets with an index less ...
Definition: linear_hash.c:1358
ion_status_t linear_hash_update(ion_key_t key, ion_value_t value, linear_hash_table_t *linear_hash)
Update the value of the first record matching the key specified in the linear hash.
Definition: linear_hash.c:774
int hash_to_bucket(ion_byte_t *key, linear_hash_table_t *linear_hash)
Map a key to the address space of the linear hash. Used to map records to buckets with an index great...
Definition: linear_hash.c:1339
char ion_err_t
The error type used to store error codes.
Definition: kv_system.h:226
void * ion_key_t
A dictionary key.
Definition: kv_system.h:241
ion_err_t linear_hash_update_bucket(ion_fpos_t bucket_loc, linear_hash_bucket_t *bucket, linear_hash_table_t *linear_hash)
Write the bucket provided at the location specified from in linear hash&#39;s .lhd file.
Definition: linear_hash.c:1205
void print_linear_hash_bucket_map(linear_hash_table_t *linear_hash)
void * ion_value_t
A dictionary value.
Definition: kv_system.h:246
Header for linear hash types.
ion_status_t linear_hash_get(ion_byte_t *key, ion_byte_t *value, linear_hash_table_t *linear_hash)
Retrieve a record from the linear hash. The key and value will be written to the key and value pointe...
Definition: linear_hash.c:673
ion_err_t linear_hash_get_record(ion_fpos_t loc, ion_byte_t *key, ion_byte_t *value, ion_byte_t *status, linear_hash_table_t *linear_hash)
Read the record data at the location specified from the linear hash&#39;s .lhd file.
Definition: linear_hash.c:1017
ion_err_t linear_hash_write_state(linear_hash_table_t *linear_hash)
Writes the current state of the linear hash to a .lhs file.
Definition: linear_hash.c:168
ion_fpos_t bucket_idx_to_ion_fpos_t(int idx, linear_hash_table_t *linear_hash)
Helper method to get the location of a bucket chain from the linear hash&#39;s bucket map...
Definition: linear_hash.c:1298
ion_err_t array_list_init(int init_size, array_list_t *array_list)
Initialize an array list.
Definition: linear_hash.c:1377
ion_err_t invalidate_buffer_records(ion_byte_t *key, int record_count, ion_byte_t *records, linear_hash_table_t *linear_hash)
ion_fpos_t array_list_get(int bucket_idx, array_list_t *array_list)
Retreive a value from an array list.
Definition: linear_hash.c:1444
ion_err_t linear_hash_get_bucket(ion_fpos_t bucket_loc, linear_hash_bucket_t *bucket, linear_hash_table_t *linear_hash)
Read the bucket at the location specified from the linear hash&#39;s .lhd file.
Definition: linear_hash.c:1163
linear_hash_bucket_t linear_hash_get_overflow_bucket(ion_fpos_t loc)
long ion_fpos_t
A file position type.
Definition: kv_system.h:237
ion_err_t linear_hash_close(linear_hash_table_t *linear_hash)
Close a linear hash instance with proper resource clean-up.
Definition: linear_hash.c:1466
int ion_key_size_t
The size (length) of a dictionary key in bytes.
Definition: kv_system.h:251
ion_err_t linear_hash_read_state(linear_hash_table_t *linear_hash)
Read the state of a linear hash from a .lhs file.
Definition: linear_hash.c:219
char ion_boolean_t
A boolean type.
Definition: kv_system.h:269
ion_err_t linear_hash_increment_num_records(linear_hash_table_t *linear_hash)
Helper method to increment the number of records in the linear hash.
Definition: linear_hash.c:285
ion_boolean_t linear_hash_above_threshold(linear_hash_table_t *linear_hash)
Helper method to increment check if a linear hash&#39;s load is above its split threshold.
Definition: linear_hash.c:477
A status object that describes the result of a dictionary operation.
Definition: kv_system.h:290
ion_err_t store_bucket_loc_in_map(int idx, ion_fpos_t bucket_loc, linear_hash_table_t *linear_hash)
ion_status_t linear_hash_insert(ion_key_t key, ion_value_t value, int hash_bucket_idx, linear_hash_table_t *linear_hash)
Insert a record into the linear hash.
Definition: linear_hash.c:573