local-to-global.h 3.47 KB
Newer Older
inge's avatar
inge committed
1
2
3
4
5
6
7
/*
 * File: local_to_global.h
 *
 * Copyright 1996 Inge Wallin, Per Cederqvist
 */


8
9
#ifndef LOCAL2GLOBAL_H_INCLUDED
#define LOCAL2GLOBAL_H_INCLUDED
inge's avatar
inge committed
10
11
12
13
14
15
16

#include "kom-types.h"

void             l2g_destruct(Local_to_global *l2g);

void             l2g_init    (Local_to_global *l2g);
void             l2g_clear   (Local_to_global *l2g);
17
18
void             l2g_copy    (Local_to_global *dest,
			      const Local_to_global *src);
inge's avatar
inge committed
19

20
/* Invalidates all iterators.  */
inge's avatar
inge committed
21
22
void             l2g_append  (Local_to_global *l2g, Local_text_no lno, 
			                            Text_no       tno);
23
/* Invalidates all iterators.  */
inge's avatar
inge committed
24
void             l2g_delete  (Local_to_global *l2g, Local_text_no lno);
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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);
inge's avatar
inge committed
42
43

/* Text file representation, e.g. for the database. */
44
45
46
47
48
49
50
51
52
53
54

/* 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);
inge's avatar
inge committed
55
56
57
58
59
60
61
62
63
64
65
66
67


/* ================================================================ */


/*
 * Iterator for a Local_to_global.
 *
 * Usage:
 *
 * Local_to_global  l2g;
 * L2g_iterator     l2gi;
 *
68
 * for (l2gi_searchall(&l2gi, &l2g); !l2gi.search_ended; l2gi_next(&l2gi)) {
inge's avatar
inge committed
69
70
71
72
73
74
75
 *     use(l2gi.lno, l2gi.tno);
 * }
 *
 * or:
 *
 * for (l2gi_searchsome(&l2gi, &l2g, startval, endval);
 *      !l2gi.search_ended;
76
 *      l2gi_next(&l2gi)) 
inge's avatar
inge committed
77
78
79
80
81
 * {
 *     use(l2gi.lno, l2gi.tno);
 * }
 */

82
83
/* Create an iterator that will loop through all texts. */
void l2gi_searchall (L2g_iterator *l2gi, const Local_to_global *l2g);
inge's avatar
inge committed
84

85
86
87
/* Create an iterator that will iterate through all existing texts
   with a local text number lno such that
   	begin <= lno < end
Per Cederqvist's avatar
Per Cederqvist committed
88
   The search will be unbound if end is set to 0. */
89
90
void l2gi_searchsome(L2g_iterator *l2gi, const Local_to_global *l2g, 
		     Local_text_no begin, Local_text_no end);
inge's avatar
inge committed
91
92
void l2gi_next(L2g_iterator *l2gi);

93
94
95
96
97
98
99
100
101
/* 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);
inge's avatar
inge committed
102
103

#endif /* LOCAL2GLOBAL__H */