Skip to content

Commit f58b617

Browse files
committed
carray capi version 1.0.0
1 parent a98065b commit f58b617

1 file changed

Lines changed: 46 additions & 4 deletions

File tree

carray_capi.h

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#endif
1212

1313
#define CARRAY_CAPI_ID_STRING "_capi_carray"
14-
#define CARRAY_CAPI_VERSION_MAJOR -2
14+
#define CARRAY_CAPI_VERSION_MAJOR 1
1515
#define CARRAY_CAPI_VERSION_MINOR 0
1616
#define CARRAY_CAPI_VERSION_PATCH 0
1717

@@ -77,7 +77,7 @@ enum carray_attr
7777

7878
struct carray_info
7979
{
80-
carray_type type;
80+
carray_type elementType;
8181
carray_attr attr;
8282
size_t elementSize;
8383
size_t elementCount;
@@ -206,13 +206,55 @@ struct carray_capi
206206
* newElementCount - new number of elements. If this is larger than the current
207207
* element count, the new elements are uninitialized.
208208
*
209-
* shrinkCapacity - flag, if true the capacity is set to the new size.
209+
* reservePercent - if < 0 the capacity is set to the new size,
210+
* if == 0 the capacity remains if the new size is smaller
211+
* than current capacity.
212+
* if > 0 the capacity gets a reserve of reservePercent percent
213+
* if capacity needs to be increased. E.g. if reservePercent == 100
214+
* the capacity is doubled if newElementCount exceeds the current
215+
* capacity.
210216
*
211217
* Returns pointer to the first element in the array. The caller may read
212218
* or write newElementCount elements at this pointer.
213219
* Returns NULL on failure or if newElementCount == 0.
214220
*/
215-
void* (*resizeCarray)(carray* a, size_t newElementCount, int shrinkCapacity);
221+
void* (*resizeCarray)(carray* a, size_t newElementCount, int reservePercent);
222+
223+
/**
224+
* Insert Elements.
225+
*
226+
* offset - index of the first new element, 0 <= offset <= elementCount
227+
* insertCount - number of elements to be inserted
228+
*
229+
* reservePercent - if < 0 the capacity is set to the new size,
230+
* if == 0 the capacity remains if the new size is smaller
231+
* than current capacity.
232+
* if > 0 the capacity gets a reserve of reservePercent percent
233+
* if capacity needs to be increased. E.g. if reservePercent == 100
234+
* the capacity is doubled if new element count exceeds the current
235+
* capacity.
236+
*
237+
* Returns pointer to the first new element in the array. The caller may write
238+
* insertCount elements at this pointer.
239+
* Returns NULL on failure or if insertCount == 0.
240+
*/
241+
void* (*insertElements)(carray* a, size_t offset, size_t insertCount, int reservePercent);
242+
243+
/**
244+
* Insert Elements.
245+
*
246+
* offset - index of the first element to be removed, 0 <= offset < elementCount
247+
* removeCount - number of elements to be removed
248+
*
249+
* reservePercent - if < 0 the capacity is set to the new size,
250+
* if == 0 the capacity remains if the new size is smaller
251+
* than current capacity.
252+
* if > 0 the capacity gets a reserve of reservePercent percent
253+
* if capacity needs to be increased. E.g. if reservePercent == 100
254+
* the capacity is doubled if new element count exceeds the current
255+
* capacity.
256+
*/
257+
void (*removeElements)(carray* a, size_t offset, size_t count, int reservePercent);
216258
};
217259

218260
#if CARRAY_CAPI_IMPLEMENT_SET_CAPI

0 commit comments

Comments
 (0)