Mercurial > hg > xemacs-beta
comparison src/dynarr.c @ 771:943eaba38521
[xemacs-hg @ 2002-03-13 08:51:24 by ben]
The big ben-mule-21-5 check-in!
Various files were added and deleted. See CHANGES-ben-mule.
There are still some test suite failures. No crashes, though.
Many of the failures have to do with problems in the test suite itself
rather than in the actual code. I'll be addressing these in the next
day or so -- none of the test suite failures are at all critical.
Meanwhile I'll be trying to address the biggest issues -- i.e. build
or run failures, which will almost certainly happen on various platforms.
All comments should be sent to ben@xemacs.org -- use a Cc: if necessary
when sending to mailing lists. There will be pre- and post- tags,
something like
pre-ben-mule-21-5-merge-in, and
post-ben-mule-21-5-merge-in.
author | ben |
---|---|
date | Wed, 13 Mar 2002 08:54:06 +0000 |
parents | fdefd0186b75 |
children | e38acbeb1cae |
comparison
equal
deleted
inserted
replaced
770:336a418893b5 | 771:943eaba38521 |
---|---|
1 /* Simple 'n' stupid dynamic-array module. | 1 /* Simple 'n' stupid dynamic-array module. |
2 Copyright (C) 1993 Sun Microsystems, Inc. | 2 Copyright (C) 1993 Sun Microsystems, Inc. |
3 Copyright (C) 2002 Ben Wing. | |
3 | 4 |
4 This file is part of XEmacs. | 5 This file is part of XEmacs. |
5 | 6 |
6 XEmacs is free software; you can redistribute it and/or modify it | 7 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 under the terms of the GNU General Public License as published by the |
63 to the element; the element itself is stored in the array, however. | 64 to the element; the element itself is stored in the array, however. |
64 No function call is performed unless the array needs to be resized. | 65 No function call is performed unless the array needs to be resized. |
65 | 66 |
66 Dynarr_add_many(d, base, len) | 67 Dynarr_add_many(d, base, len) |
67 [MACRO] Add LEN elements to the end of the dynamic array. The elements | 68 [MACRO] Add LEN elements to the end of the dynamic array. The elements |
68 should be contiguous in memory, starting at BASE. | 69 should be contiguous in memory, starting at BASE. If BASE if NULL, |
70 just make space for the elements; don't actually add them. | |
69 | 71 |
70 Dynarr_insert_many_at_start(d, base, len) | 72 Dynarr_insert_many_at_start(d, base, len) |
71 [MACRO] Append LEN elements to the beginning of the dynamic array. | 73 [MACRO] Append LEN elements to the beginning of the dynamic array. |
72 The elements should be contiguous in memory, starting at BASE. | 74 The elements should be contiguous in memory, starting at BASE. |
75 If BASE if NULL, just make space for the elements; don't actually | |
76 add them. | |
73 | 77 |
74 Dynarr_insert_many(d, base, len, start) | 78 Dynarr_insert_many(d, base, len, start) |
75 Insert LEN elements to the dynamic array starting at position | 79 Insert LEN elements to the dynamic array starting at position |
76 START. The elements should be contiguous in memory, starting at BASE. | 80 START. The elements should be contiguous in memory, starting at BASE. |
81 If BASE if NULL, just make space for the elements; don't actually | |
82 add them. | |
83 | |
84 Dynarr_delete(d, i) | |
85 [MACRO] Delete an element from the dynamic array at position I. | |
86 | |
87 Dynarr_delete_many(d, start, len) | |
88 Delete LEN elements from the dynamic array starting at position | |
89 START. | |
90 | |
91 Dynarr_delete_by_pointer(d, p) | |
92 [MACRO] Delete an element from the dynamic array at pointer P, | |
93 which must point within the block of memory that stores the data. | |
94 P should be obtained using Dynarr_atp(). | |
77 | 95 |
78 int Dynarr_length(d) | 96 int Dynarr_length(d) |
79 [MACRO] Return the number of elements currently in a dynamic array. | 97 [MACRO] Return the number of elements currently in a dynamic array. |
80 | 98 |
81 int Dynarr_largest(d) | 99 int Dynarr_largest(d) |
114 Dynarr_realloc (Dynarr *dy, int new_size) | 132 Dynarr_realloc (Dynarr *dy, int new_size) |
115 { | 133 { |
116 if (DUMPEDP (dy->base)) | 134 if (DUMPEDP (dy->base)) |
117 { | 135 { |
118 void *new_base = malloc (new_size); | 136 void *new_base = malloc (new_size); |
119 memcpy (new_base, dy->base, dy->max > new_size ? new_size : dy->max); | 137 memcpy (new_base, dy->base, dy->max > new_size ? dy->max : new_size); |
120 dy->base = new_base; | 138 dy->base = new_base; |
121 } | 139 } |
122 else | 140 else |
123 dy->base = xrealloc (dy->base, new_size); | 141 dy->base = xrealloc (dy->base, new_size); |
124 } | 142 } |
172 { | 190 { |
173 memmove ((char *) dy->base + (start + len)*dy->elsize, | 191 memmove ((char *) dy->base + (start + len)*dy->elsize, |
174 (char *) dy->base + start*dy->elsize, | 192 (char *) dy->base + start*dy->elsize, |
175 (dy->cur - start)*dy->elsize); | 193 (dy->cur - start)*dy->elsize); |
176 } | 194 } |
177 memcpy ((char *) dy->base + start*dy->elsize, el, len*dy->elsize); | 195 if (el) |
196 memcpy ((char *) dy->base + start*dy->elsize, el, len*dy->elsize); | |
178 dy->cur += len; | 197 dy->cur += len; |
179 | 198 |
180 if (dy->cur > dy->largest) | 199 if (dy->cur > dy->largest) |
181 dy->largest = dy->cur; | 200 dy->largest = dy->cur; |
182 } | 201 } |