Commit b91f7803 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(L2G_BLOCKSIZE): Moved to local-to-global.c.

(L2g_block_info): Likewise.
(Local_to_global): Likewise.
(l2g_copy): Switched placement of src and dest to match other copy
	functions in the lyskomd code.  Added const qualifier.
(l2g_lookup): Added const qualifier to the l2g argument.
(l2g_next_key): Likewise.
(l2g_compact): Removed.
(l2g_first_appendable_key): New function.
(l2g_delete_global_in_sorted): New function.
(l2g_dump): Switch placement of l2g and file arguments to match
	other similar functions in the lyskomd code.  Added const
	qualifier.
(l2g_write): Likewise.
(l2g_read): Likewise.
(l2g_searchall): Added const qualifier.
(L2g_iterator): Moved to kom-types.h.
(l2gi_searchsome): Added const qualifier.
(l2gi_begin): New function.
(l2gi_end): New function.
parent fbecb1e2
......@@ -5,49 +5,53 @@
*/
#ifndef LOCAL2GLOBAL__H
#define LOCAL2GLOBAL__H
#ifndef LOCAL2GLOBAL_H_INCLUDED
#define LOCAL2GLOBAL_H_INCLUDED
#include "kom-types.h"
#define L2G_BLOCKSIZE 10 /* Doesn't seem to matter much. */
typedef struct block_info {
int first_free; /* Insert new texts here. */
int zeroes; /* Used as optimization for compacting. */
Local_text_no start; /* First local text no in this block. */
Local_text_no * key_block;
Text_no * value_block;
} L2g_block_info;
typedef struct local_to_global {
int num_blocks;
L2g_block_info * blocks;
} Local_to_global;
void l2g_destruct(Local_to_global *l2g);
void l2g_init (Local_to_global *l2g);
void l2g_clear (Local_to_global *l2g);
void l2g_copy (Local_to_global *from, Local_to_global *to);
void l2g_copy (Local_to_global *dest,
const Local_to_global *src);
/* Invalidates all iterators. */
void l2g_append (Local_to_global *l2g, Local_text_no lno,
Text_no tno);
/* Invalidates all iterators. */
void l2g_delete (Local_to_global *l2g, Local_text_no lno);
Text_no l2g_lookup (Local_to_global *l2g, Local_text_no lno);
Local_text_no l2g_next_key(Local_to_global *l2g, Local_text_no lno);
void l2g_compact (Local_to_global *l2g);
Text_no l2g_lookup (const Local_to_global *l2g, Local_text_no lno);
/* Returns the next local text number, or 0 if lno is larger than the
largest local text number. */
Local_text_no l2g_next_key(const Local_to_global *l2g, Local_text_no lno);
/* Returns the lowest local text number that has never been present in
the structure. This is the same as one plus the highest local text number
that is present in the structure (unless it has been deleted --
deletions do not cause this to decrease). Returns 1 if the
structure has always been empty. */
Local_text_no l2g_first_appendable_key(const Local_to_global *l2g);
/* Delete global text number TNO. This function can only be called if
both the local and global text numbers are monotonous series, as
they are in the Person::created_text_map field. */
void l2g_delete_global_in_sorted(Local_to_global *l2g, Text_no tno);
/* Text file representation, e.g. for the database. */
void l2g_dump (Local_to_global *l2g, FILE *file);
void l2g_read (Local_to_global *l2g, FILE *file);
void l2g_write (Local_to_global *l2g, FILE *file);
/* Dump all internal state. This is used by the test suite to peek at
the internal representation. It should not be used except for such
debugging purposes. */
void l2g_dump (FILE *file, const Local_to_global *l2g);
/* Write an external representation of the mapping to a file. */
void l2g_write (FILE *file, const Local_to_global *l2g);
/* Initialize the mapping from the representation found in file. */
Success l2g_read (FILE *file, Local_to_global *l2g);
/* ================================================================ */
......@@ -61,7 +65,7 @@ void l2g_write (Local_to_global *l2g, FILE *file);
* Local_to_global l2g;
* L2g_iterator l2gi;
*
* for (l2gi_searchall(&l2gi, &l2g); !l2gi.search_ended; l2gi_next(l2gi)) {
* for (l2gi_searchall(&l2gi, &l2g); !l2gi.search_ended; l2gi_next(&l2gi)) {
* use(l2gi.lno, l2gi.tno);
* }
*
......@@ -69,29 +73,31 @@ void l2g_write (Local_to_global *l2g, FILE *file);
*
* for (l2gi_searchsome(&l2gi, &l2g, startval, endval);
* !l2gi.search_ended;
* l2gi_next(l2gi))
* l2gi_next(&l2gi))
* {
* use(l2gi.lno, l2gi.tno);
* }
*/
/* Create an iterator that will loop through all texts. */
void l2gi_searchall (L2g_iterator *l2gi, const Local_to_global *l2g);
typedef struct {
Local_to_global * l2g;
L2g_block_info * binfo;
int arrindex;
Local_text_no endval; /* Last index in the search + 1 */
int search_ended; /* 1 if finished, 0 otherwise */
Local_text_no lno; /* The Local_text_no to use */
Text_no tno; /* The Text_no to use */
} L2g_iterator;
void l2gi_searchall (L2g_iterator *l2gi, Local_to_global *l2g);
void l2gi_searchsome(L2g_iterator *l2gi, Local_to_global *l2g,
Local_text_no start, Local_text_no end);
/* Create an iterator that will iterate through all existing texts
with a local text number lno such that
begin <= lno < end
*/
void l2gi_searchsome(L2g_iterator *l2gi, const Local_to_global *l2g,
Local_text_no begin, Local_text_no end);
void l2gi_next(L2g_iterator *l2gi);
/* This can only be used on iterators created with l2gi_searchsome.
Returns the value supplied to the end argument when the iterator
was created. */
Local_text_no l2gi_end(const L2g_iterator *l2gi);
/* This can only be used on iterators created with l2gi_searchsome.
Returns the value supplied to the start argument when the iterator
was created. */
Local_text_no l2gi_begin(const L2g_iterator *l2gi);
#endif /* LOCAL2GLOBAL__H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment