d3409d5e |
1 | /* -*-c-*- |
2 | * |
3 | * $Id: mpalloc.h,v 1.1 1999/11/17 18:02:16 mdw Exp $ |
4 | * |
5 | * Allocation and freeing of MP buffers |
6 | * |
7 | * (c) 1999 Straylight/Edgeware |
8 | */ |
9 | |
10 | /*----- Licensing notice --------------------------------------------------* |
11 | * |
12 | * This file is part of Catacomb. |
13 | * |
14 | * Catacomb is free software; you can redistribute it and/or modify |
15 | * it under the terms of the GNU Library General Public License as |
16 | * published by the Free Software Foundation; either version 2 of the |
17 | * License, or (at your option) any later version. |
18 | * |
19 | * Catacomb is distributed in the hope that it will be useful, |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | * GNU Library General Public License for more details. |
23 | * |
24 | * You should have received a copy of the GNU Library General Public |
25 | * License along with Catacomb; if not, write to the Free |
26 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
27 | * MA 02111-1307, USA. |
28 | */ |
29 | |
30 | /*----- Revision history --------------------------------------------------* |
31 | * |
32 | * $Log: mpalloc.h,v $ |
33 | * Revision 1.1 1999/11/17 18:02:16 mdw |
34 | * New multiprecision integer arithmetic suite. |
35 | * |
36 | */ |
37 | |
38 | #ifndef MPARENA_H |
39 | #define MPARENA_H |
40 | |
41 | #ifdef __cplusplus |
42 | extern "C" { |
43 | #endif |
44 | |
45 | /*----- Header files ------------------------------------------------------*/ |
46 | |
47 | #ifndef MPW_H |
48 | # include "mpw.h" |
49 | #endif |
50 | |
51 | /*----- Data structures ---------------------------------------------------*/ |
52 | |
53 | typedef struct mparena_node { |
54 | struct mparena_node *left, *right; |
55 | mpw *v; |
56 | } mparena_node; |
57 | |
58 | typedef struct mparena { |
59 | mparena_node *root; |
60 | } mparena_arena; |
61 | |
62 | /*----- Magical constants -------------------------------------------------*/ |
63 | |
64 | #define MPARENA_GLOBAL ((mparena *)0) |
65 | |
66 | /*----- Functions provided ------------------------------------------------*/ |
67 | |
68 | /* --- @mparena_create@ --- * |
69 | * |
70 | * Arguments: @mparena *a@ = pointer to arena block |
71 | * |
72 | * Returns: --- |
73 | * |
74 | * Use: Initializes an MP arena so that blocks can be allocated from |
75 | * it. |
76 | */ |
77 | |
78 | extern void mparena_create(mparena */*a*/); |
79 | |
80 | #define MPARENA_INIT { 0 } |
81 | |
82 | /* --- @mparena_destroy@ --- * |
83 | * |
84 | * Arguments: @mparena *a@ = pointer to arena block |
85 | * |
86 | * Returns: --- |
87 | * |
88 | * Use: Frees an MP arena, and all the vectors held within it. The |
89 | * blocks which are currently allocated can be freed into some |
90 | * other arena. |
91 | */ |
92 | |
93 | extern void mparena_destroy(mparena */*a*/); |
94 | |
95 | /* --- @mp_alloc@ --- * |
96 | * |
97 | * Arguments: @mparena *a@ = pointer to arena block |
98 | * @size_t n@ = number of digits required |
99 | * |
100 | * Returns: Pointer to a suitably sized block. |
101 | * |
102 | * Use: Allocates a lump of data suitable for use as an array of MP |
103 | * digits. |
104 | */ |
105 | |
106 | extern mpw *mp_alloc(mparena */*a*/, size_t /*n*/); |
107 | |
108 | /* --- @mp_free@ --- * |
109 | * |
110 | * Arguments: @mparena *a@ = pointer to arena block |
111 | * @mpw *v@ = pointer to allocated vector |
112 | * |
113 | * Returns: --- |
114 | * |
115 | * Use: Returns an MP vector to an arena. It doesn't have to be |
116 | * returned to the arena from which it was allocated. |
117 | */ |
118 | |
119 | extern mpw *mp_free(mparena */*a*/, mpw */*v*/); |
120 | |
121 | /*----- That's all, folks -------------------------------------------------*/ |
122 | |
123 | #ifdef __cplusplus |
124 | } |
125 | #endif |
126 | |
127 | #endif |