1 /*
2 
3 Copyright (C) 2015-2018 Night Dive Studios, LLC.
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 #ifndef __ARRAY_H
20 #define __ARRAY_H
21 
22 /*
23  * $Source: n:/project/lib/src/dstruct/RCS/array.h $
24  * $Revision: 1.1 $
25  * $Author: mahk $
26  * $Date: 1993/04/16 22:09:58 $
27  *
28  * $Log: array.h $
29  * Revision 1.1  1993/04/16  22:09:58  mahk
30  * Initial revision
31  *
32  * Revision 1.2  1993/03/22  15:23:41  mahk
33  * Added prototype for array_destroy.
34  *
35  * Revision 1.1  1993/03/22  15:21:34  mahk
36  * Initial revision
37  *
38  *
39  */
40 
41 // Includes
42 #include "lg.h"
43 
44 // C Library Includes
45 
46 // System Library Includes
47 #include "error.h"
48 
49 // Master Game Includes
50 
51 // Game Library Includes
52 
53 // Game Object Includes
54 
55 // ======================
56 //  ARRAY TYPE
57 // ======================
58 // Here is an implementation of a dynamically-growing array.
59 // It is intended for used in places where superfluous calls to
60 // Malloc are not desirable.
61 
62 // Defines
63 
64 typedef struct _array
65 {
66    int elemsize;  // How big is each array element
67    int vecsize;   // How many elements in the vector
68    int fullness;  // How many elements are used.
69    int freehead;  // index to head of the free list.
70    int *freevec;  // free list
71    char *vec;     // the actual vector;
72 } Array;
73 
74 
75 // Prototypes
76 
77 
78 // Initialize an array.  Fill in the structure, allocate the vector and free list.
79 errtype array_init(Array* toinit, int elemsize, int vecsize);
80 
81 // Find a place for a new element of the array, extending the array if necessary.
82 // returns the new index in *index
83 errtype array_newelem(Array* a, int* index);
84 
85 // Mark an element as unused and eligible for recycling by a subsequent
86 // array_newelem call.
87 errtype array_dropelem(Array* a, int index);
88 
89 // Destroy an array, deallocating its vec and freevec
90 errtype array_destroy(Array* a);
91 
92 
93 // Globals
94 
95 #endif //__ARRAY_H
96