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


8
9
#ifndef LOCAL2GLOBAL_H_INCLUDED
#define LOCAL2GLOBAL_H_INCLUDED
inge's avatar
inge committed
10
11
12

#include "kom-types.h"

13
14
15
16
17
/* Set the block size.  This function must be called exactly once
   before any other function declared in this file is called.  Once
   the block size has been set it cannot be changed.  */
void l2g_set_block_size(int sz);

Per Cederqvist's avatar
Per Cederqvist committed
18
19
20
/* Contstructor.  Take raw memory and create an empty
   Local_to_global mapping. */
void l2g_init(Local_to_global *l2g);
inge's avatar
inge committed
21

Per Cederqvist's avatar
Per Cederqvist committed
22
23
24
25
26
27
28
29
30
31
32
33
/* Destructor.  Frees all memory associated with ``l2g'' and destruct
   the object, turning it into raw memory once again.  */
void l2g_destruct(Local_to_global *l2g);

/* Re-initialize ``l2g''.  "lg2_clear(&foo)" is equivalent to
   "l2g_destruct(&foo); l2g_init(&foo)" but slightly more efficient. */
void l2g_clear(Local_to_global *l2g);

/* Copy ``src'' to ``dest''.  Both ``src'' and ``dest'' must be
   constructed Local_to_global objects.  This operation will ensure
   that they contain the same data.  */
void l2g_copy(Local_to_global *dest, const Local_to_global *src);
inge's avatar
inge committed
34

Per Cederqvist's avatar
Per Cederqvist committed
35
36
37
/* Append a new mapping from LNO to TNO.  LNO must be higher than any
   LNO previously stored in the structure.
   Invalidates all iterators.  */
Per Cederqvist's avatar
Per Cederqvist committed
38
39
void l2g_append(Local_to_global *l2g, Local_text_no lno, Text_no tno);

Per Cederqvist's avatar
Per Cederqvist committed
40
/* Delete LNO from the structure.  Invalidates all iterators.  */
Per Cederqvist's avatar
Per Cederqvist committed
41
void l2g_delete(Local_to_global *l2g, Local_text_no lno);
Per Cederqvist's avatar
Per Cederqvist committed
42
43
44

/* Return the TNO previously stored under LNO.  Returns 0 if no such
   LNO exists.  */
Per Cederqvist's avatar
Per Cederqvist committed
45
Text_no l2g_lookup(const Local_to_global *l2g, Local_text_no lno);
46
47
48

/* Returns the next local text number, or 0 if lno is larger than the
   largest local text number.  */
Per Cederqvist's avatar
Per Cederqvist committed
49
Local_text_no l2g_next_key(const Local_to_global *l2g, Local_text_no lno);
50
51

/* Returns the lowest local text number that has never been present in
Per Cederqvist's avatar
Per Cederqvist committed
52
53
54
   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
55
   structure has always been empty. */
Per Cederqvist's avatar
Per Cederqvist committed
56
Local_text_no l2g_first_appendable_key(const Local_to_global *l2g);
57

58
59
60
61
62
63
64
/* Set the first the number returned by l2g_first_appendable_key.  You
   can only set it to a higher value than it already has.  This
   function is probably only useful when reading in a Local_to_global
   structure that was saved with something other than l2g_write.  */
void l2g_set_first_appendable_key(Local_to_global *l2g,
				  Local_text_no    key);

65
66
67
68
/* 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
69

70
71
72
/* 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. */
Per Cederqvist's avatar
Per Cederqvist committed
73
74
75
76
77
void l2g_dump(FILE *file, const Local_to_global *l2g);

/* Write an external representation of the mapping to ``file''. */
void l2g_write(FILE *file, const Local_to_global *l2g);

78
79
/* Initialize the mapping from the representation found in ``file''.
   ``l2g'' must already be constructed.  */
Per Cederqvist's avatar
Per Cederqvist committed
80
Success l2g_read(FILE *file, Local_to_global *l2g);
81

Per Cederqvist's avatar
Per Cederqvist committed
82
83
/* Dump global usage statistics to ``file''. */
void dump_l2g_stats(FILE *file);
84

inge's avatar
inge committed
85
86
87
88
89
90
91
92
93
94
95
96
97


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


/*
 * Iterator for a Local_to_global.
 *
 * Usage:
 *
 * Local_to_global  l2g;
 * L2g_iterator     l2gi;
 *
98
 * for (l2gi_searchall(&l2gi, &l2g); !l2gi.search_ended; l2gi_next(&l2gi)) {
inge's avatar
inge committed
99
100
101
102
103
104
105
 *     use(l2gi.lno, l2gi.tno);
 * }
 *
 * or:
 *
 * for (l2gi_searchsome(&l2gi, &l2g, startval, endval);
 *      !l2gi.search_ended;
106
 *      l2gi_next(&l2gi)) 
inge's avatar
inge committed
107
108
109
110
111
 * {
 *     use(l2gi.lno, l2gi.tno);
 * }
 */

112
113
/* 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
114

115
116
117
/* 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
118
   The search will be unbound if end is set to 0. */
119
120
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
121
122

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

125
126
127
128
129
130
131
132
133
/* 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
134
135

#endif /* LOCAL2GLOBAL__H */