annotate src/dynarr.h @ 181:bfd6434d15b3 r20-3b17

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