local-to-global.h 3.73 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

Per Cederqvist's avatar
Per Cederqvist committed
20
21
22
/* Append a new mapping from LNO to TNO.  LNO must be higher than any
   LNO previously stored in the structure.
   Invalidates all iterators.  */
inge's avatar
inge committed
23
24
void             l2g_append  (Local_to_global *l2g, Local_text_no lno, 
			                            Text_no       tno);
Per Cederqvist's avatar
Per Cederqvist committed
25
/* Delete LNO from the structure.  Invalidates all iterators.  */
inge's avatar
inge committed
26
void             l2g_delete  (Local_to_global *l2g, Local_text_no lno);
Per Cederqvist's avatar
Per Cederqvist committed
27
28
29

/* Return the TNO previously stored under LNO.  Returns 0 if no such
   LNO exists.  */
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
47
48

/* Text file representation, e.g. for the database. */
49
50
51
52
53
54
55
56
57
58
59

/* 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
60
61
62
63
64
65
66
67
68
69
70
71
72


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


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

87
88
/* 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
89

90
91
92
/* 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
93
   The search will be unbound if end is set to 0. */
94
95
void l2gi_searchsome(L2g_iterator *l2gi, const Local_to_global *l2g, 
		     Local_text_no begin, Local_text_no end);
Per Cederqvist's avatar
Per Cederqvist committed
96
97

/* Step the iterator forward.  */
inge's avatar
inge committed
98
99
void l2gi_next(L2g_iterator *l2gi);

100
101
102
103
104
105
106
107
108
/* 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
109
110

#endif /* LOCAL2GLOBAL__H */