Added daPopDiscard function
This commit is contained in:
parent
e305cc2c66
commit
1c135b3d09
19
da.h
19
da.h
|
@ -17,6 +17,7 @@ typedef void * dynarr;
|
|||
dynarr _daCreate(size_t initCapacity, size_t type, size_t size);
|
||||
dynarr _daPush(dynarr da, void * item);
|
||||
void _daPop(dynarr da, void * element);
|
||||
void daPopDiscard(dynarr da);
|
||||
void daFree(dynarr da);
|
||||
|
||||
size_t daSize(dynarr da);
|
||||
|
@ -86,6 +87,11 @@ void _daPop(dynarr da, void * elem)
|
|||
memcpy(elem, (char *)da + daSize(da) * daType(da), daType(da));
|
||||
}
|
||||
|
||||
void daPopDiscard(dynarr da)
|
||||
{
|
||||
*daField(da, SIZE) -= 1;
|
||||
}
|
||||
|
||||
size_t * daField(dynarr da, enum daFields field)
|
||||
{
|
||||
if (field < SIZE || field > TYPE)
|
||||
|
@ -94,7 +100,8 @@ size_t * daField(dynarr da, enum daFields field)
|
|||
fprintf(stderr, "ERROR: Wrong field: %d\n", field);
|
||||
fprintf(stderr, "AVAILABLE: SIZE, CAPACITY, TYPE\n");
|
||||
fprintf(stderr, "*------------------------------*\n");
|
||||
exit(1);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ((size_t *) da - DATA + field);
|
||||
|
@ -124,7 +131,7 @@ void daForeach(dynarr da, func f)
|
|||
heapstr daToCStr(dynarr da)
|
||||
{
|
||||
char * buffer = (char *) calloc(1, daSize(da) + 1);
|
||||
memcpy(buffer, da,daSize(da) * daType(da));
|
||||
memcpy(buffer, da, daSize(da) * daType(da));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -138,10 +145,10 @@ void * daGetRef(dynarr da, size_t index)
|
|||
{
|
||||
if (index >= daSize(da))
|
||||
{
|
||||
fprintf(stderr, "*------------------------------*\n");
|
||||
fprintf(stderr, "ERROR: Access out of bounds\n");
|
||||
fprintf(stderr, "*------------------------------*\n");
|
||||
exit(1);
|
||||
fprintf(stderr, ("*------------------------------*\n"));
|
||||
fprintf(stderr, ("ERROR: Access out of bounds\n"));
|
||||
fprintf(stderr, ("*------------------------------*\n"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (void *)((char *)da + index * daType(da));
|
||||
|
|
Loading…
Reference in New Issue