-
Per Cederqvist authored
stdlib.h if HAVE_STDLIB_H. Include stdio.h if we didn't get NULL from stdlib.h. Inlucd lyskomd.h and server/smalloc.h. (L2G_BLOCKSIZE): Moved here from local-to-global.h. (struct l2g_block_info): Likewise. (is_dense): New static function. (is_empty): New static function. (key_value): New static function. (sparse_skip_deleted): New static function. (sparse_locate_value): New static function. (sparse_compact): New static function. (add_block): Use srealloc instead of realloc. Don't initialize start -- the caller is responsible for doing so. (delete_block): Use sfree instead of free, and srealloc instead of realloc. (make_sparse): Don't change the value of start, since there is no need to, and make_sparse may now be called on an empty block, which would cause start to be set to a garbage value. (find_block): Added a const qualifier to the return value and l2g argument. Use key_value to simplify code. (find_block_index_key): Added a const qualifier to the l2g argument. Use helper functions to simplify the code. Use sparse_skip_deleted so that the function never returns a deleted key. Never return deleted keys in dense blocks either. (join_range): New static function. (join_blocks): New static function. (l2g_init): Set first_unused to 1. (l2g_clear): Use sfree instead of free. Set first_unused to 1. (l2g_copy): Added const qualifier to the src argument. Simplified code by using helper functions and relying on the fact that calling l2g_append with a Text_no=0 is a no-op. Set first_unused of the copy. (l2g_append): Send a log message and do nothing if an attempt to set a local number lower than first_unused is detected. Set first_unused. Fixed the logic about when to add a new block, when to compact the last block, and when to make it sparse. Simplify code by using the helper functions. (l2g_delete): Don't increase the zeroes counter if a zero is deleted. Delete the entire block if it became empty. Attempt to join this block to its neighbors. Compact the block if it was sparse and contained too many deleted entries. (l2g_lookup): Added const qualifier to the l2g argument. Don't return uninitialized data. Use helper functions to simplify code and make it slightly faster. (l2g_next_key): Added const qualifier to the l2g argument. (l2g_first_appendable_key): New function. (l2g_delete_global_in_sorted): New function. (l2g_compact): Removed. (l2g_dump): Switch placement of l2g and file arguments to match other similar functions in the lyskomd code. Added const qualifier. Dump first_unused. Use helper functions to simplify code. (l2g_read): Switch placement of l2g and file arguments to match other similar functions in the lyskomd code. Read first_unused. Return a success indicator. Detect unexpected EOF conditions. (l2g_write): Switch placement of l2g and file arguments to match other similar functions in the lyskomd code. Write first_unused. Use helper functions to simplify code. (l2gi_searchall): Added const qualifier to the l2g argument. Simplify code by calling l2gi_searchsome instead of duplicating the code. (l2gi_searchsome): Added const qualifier to the l2g argument. Complain if the begin argument is less than 1. Don't forget to initialize search_ended. Set beginval. Giving end==0 means that the iterator should continue to the end of the set. Use helper functions to simplify the code. (l2gi_next): Use helper functions to simplify code. The iterator is unlimited if endval==0. (l2gi_begin): New function. (l2gi_end): New function.
2b107568