local-to-global.h 2.6 KB
Newer Older
inge's avatar
inge committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * File: local_to_global.h
 *
 * Copyright 1996 Inge Wallin, Per Cederqvist
 */


#ifndef LOCAL2GLOBAL__H
#define LOCAL2GLOBAL__H

#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_append  (Local_to_global *l2g, Local_text_no lno, 
			                            Text_no       tno);
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 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);
inge's avatar
inge committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
void             l2g_write   (Local_to_global *l2g, FILE *file);


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


/*
 * Iterator for a Local_to_global.
 *
 * Usage:
 *
 * Local_to_global  l2g;
 * L2g_iterator     l2gi;
 *
 * for (l2gi_searchall(&l2gi, &l2g); !l2gi.search_ended; l2gi_next(l2gi)) {
 *     use(l2gi.lno, l2gi.tno);
 * }
 *
 * or:
 *
 * for (l2gi_searchsome(&l2gi, &l2g, startval, endval);
 *      !l2gi.search_ended;
 *      l2gi_next(l2gi)) 
 * {
 *     use(l2gi.lno, l2gi.tno);
 * }
 */


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);
void l2gi_next(L2g_iterator *l2gi);

inge's avatar
inge committed
96
97

#endif /* LOCAL2GLOBAL__H */