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

/* 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
62

63
64
65
/* 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
66
67
68
69
70
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);

71
72
/* Initialize the mapping from the representation found in ``file''.
   ``l2g'' must already be constructed.  */
Per Cederqvist's avatar
Per Cederqvist committed
73
Success l2g_read(FILE *file, Local_to_global *l2g);
74

Per Cederqvist's avatar
Per Cederqvist committed
75
76
/* Dump global usage statistics to ``file''. */
void dump_l2g_stats(FILE *file);
77

inge's avatar
inge committed
78
79
80
81
82
83
84
85
86
87
88
89
90


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


/*
 * Iterator for a Local_to_global.
 *
 * Usage:
 *
 * Local_to_global  l2g;
 * L2g_iterator     l2gi;
 *
91
 * for (l2gi_searchall(&l2gi, &l2g); !l2gi.search_ended; l2gi_next(&l2gi)) {
inge's avatar
inge committed
92
93
94
95
96
97
98
 *     use(l2gi.lno, l2gi.tno);
 * }
 *
 * or:
 *
 * for (l2gi_searchsome(&l2gi, &l2g, startval, endval);
 *      !l2gi.search_ended;
99
 *      l2gi_next(&l2gi)) 
inge's avatar
inge committed
100
101
102
103
104
 * {
 *     use(l2gi.lno, l2gi.tno);
 * }
 */

105
106
/* 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
107

108
109
110
/* 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
111
   The search will be unbound if end is set to 0. */
112
113
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
114
115

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

118
119
120
121
122
123
124
125
126
/* 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
127
128

#endif /* LOCAL2GLOBAL__H */