math/mpreduce.h: Missing include files.
[u/mdw/catacomb] / math / mparena.h
1 /* -*-c-*-
2 *
3 * Allocation and freeing of MP buffers
4 *
5 * (c) 1999 Straylight/Edgeware
6 */
7
8 /*----- Licensing notice --------------------------------------------------*
9 *
10 * This file is part of Catacomb.
11 *
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
16 *
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 * MA 02111-1307, USA.
26 */
27
28 #ifndef CATACOMB_MPARENA_H
29 #define CATACOMB_MPARENA_H
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /*----- Header files ------------------------------------------------------*/
36
37 #include <mLib/arena.h>
38
39 #ifndef CATACOMB_MPW_H
40 # include "mpw.h"
41 #endif
42
43 /*----- Data structures ---------------------------------------------------*/
44
45 /* --- @mparena_node@ --- *
46 *
47 * For internal use by the MP arena manager. The free blocks are held in a
48 * binary tree by size, held in the first digit of each vector.
49 */
50
51 typedef struct mparena_node {
52 struct mparena_node *left, *right;
53 mpw *v;
54 } mparena_node;
55
56 /* --- @mparena@ --- *
57 *
58 * The actual arena.
59 */
60
61 typedef struct mparena {
62 mparena_node *root;
63 unsigned n;
64 arena *a;
65 } mparena;
66
67 /*----- Standard arenas ---------------------------------------------------*/
68
69 extern mparena mparena_global;
70 #define MPARENA_GLOBAL (&mparena_global)
71
72 extern mparena mparena_secure;
73 #define MPARENA_SECURE (&mparena_secure)
74
75 /*----- Functions provided ------------------------------------------------*/
76
77 /* --- @mparena_create@ --- *
78 *
79 * Arguments: @mparena *a@ = pointer to arena block
80 *
81 * Returns: ---
82 *
83 * Use: Initializes an MP arena so that blocks can be allocated from
84 * it.
85 */
86
87 extern void mparena_create(mparena */*a*/);
88
89 #define MPARENA_INIT { 0, 0, &arena_stdlib }
90
91 /* --- @mparena_setarena@ --- *
92 *
93 * Arguments: @mparena *a@ = pointer to MP arena block
94 * @arena *aa@ = pointer to arena
95 *
96 * Returns: ---
97 *
98 * Use: Sets the underlying arena for an MP arena.
99 */
100
101 extern void mparena_setarena(mparena */*a*/, arena */*aa*/);
102
103 /* --- @mparena_destroy@ --- *
104 *
105 * Arguments: @mparena *a@ = pointer to arena block
106 *
107 * Returns: ---
108 *
109 * Use: Frees an MP arena, and all the vectors held within it. The
110 * blocks which are currently allocated can be freed into some
111 * other MP arena, as long as the underlying arenas are the
112 * same.
113 */
114
115 extern void mparena_destroy(mparena */*a*/);
116
117 /* --- @mparena_count@ --- *
118 *
119 * Arguments: @mparena *a@ = pointer to arena block
120 *
121 * Returns: Number of allocated blocks from this arena.
122 *
123 * Use: Reports the number of blocks allocated from the arena and not
124 * yet freed.
125 */
126
127 extern unsigned mparena_count(mparena */*a*/);
128
129 /* --- @mpalloc@ --- *
130 *
131 * Arguments: @mparena *a@ = pointer to arena block
132 * @size_t sz@ = number of digits required
133 *
134 * Returns: Pointer to a suitably sized block.
135 *
136 * Use: Allocates a lump of data suitable for use as an array of MP
137 * digits.
138 */
139
140 extern mpw *mpalloc(mparena */*a*/, size_t /*sz*/);
141
142 /* --- @mpfree@ --- *
143 *
144 * Arguments: @mparena *a@ = pointer to arena block
145 * @mpw *v@ = pointer to allocated vector
146 *
147 * Returns: ---
148 *
149 * Use: Returns an MP vector to an arena.
150 */
151
152 extern void mpfree(mparena */*a*/, mpw */*v*/);
153
154 /*----- That's all, folks -------------------------------------------------*/
155
156 #ifdef __cplusplus
157 }
158 #endif
159
160 #endif