comparison src/dynarr.h @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children e121b013d1f0
comparison
equal deleted inserted replaced
-1:000000000000 0:376386a54a3c
1 /* Simple 'n' stupid dynamic-array module -- include file.
2 Copyright (C) 1993 Sun Microsystems, Inc.
3
4 This file is part of XEmacs.
5
6 XEmacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
10
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with XEmacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 /* Synched up with: Not in FSF. */
22
23 /* Written by Ben Wing, December 1993. */
24
25 #ifndef _XEMACS_DYNARR_H_
26 #define _XEMACS_DYNARR_H_
27
28 #define Dynarr_declare(type) \
29 type *base; \
30 int elsize; \
31 int cur; \
32 int largest; \
33 int max
34
35 typedef struct dynarr
36 {
37 Dynarr_declare (void);
38 } Dynarr;
39
40 void *Dynarr_newf (int elsize);
41 void Dynarr_resize (void *dy, int size);
42 void Dynarr_insert_many (void *d, CONST void *el, int len, int start);
43 void Dynarr_delete_many (void *d, int start, int len);
44 void Dynarr_free (void *d);
45
46 #define Dynarr_new(type) Dynarr_newf (sizeof(* (type *) NULL))
47 #define Dynarr_at(d, pos) ((d)->base[pos])
48 #define Dynarr_atp(d, pos) (&Dynarr_at (d, pos))
49 #define Dynarr_length(d) ((d)->cur)
50 #define Dynarr_largest(d) ((d)->largest)
51 #define Dynarr_reset(d) ((d)->cur = 0)
52 #define Dynarr_add_many(d, el, len) Dynarr_insert_many (d, el, len, (d)->cur)
53 #define Dynarr_insert_many_at_start(d, el, len) \
54 Dynarr_insert_many (d, el, len, 0)
55
56 #define Dynarr_add(d, el) ( \
57 (d)->cur >= (d)->max ? Dynarr_resize ((d), (d)->cur+1) : (void) 0, \
58 ((d)->base)[(d)->cur++] = (el), \
59 (d)->cur > (d)->largest ? (d)->largest = (d)->cur : (int) 0)
60
61 /* The following defines will get you into real trouble if you aren't
62 careful. But they can save a lot of execution time when used wisely. */
63 #define Dynarr_increment(d) ((d)->cur++)
64 #define Dynarr_set_size(d, n) ((d)->cur = n)
65
66 /* Minimum size in elements for dynamic array when resized; default is 32 */
67 extern int Dynarr_min_size;
68
69 #ifdef MEMORY_USAGE_STATS
70
71 struct overhead_stats;
72
73 int Dynarr_memory_usage (void *d, struct overhead_stats *stats);
74
75 #endif
76
77 #endif /* _XEMACS_DYNARR_H_ */