Skip to content

Commit

Permalink
Daha önce bir takım sebeplerle dokunulmamış eksiklikler giderildi.
Browse files Browse the repository at this point in the history
  • Loading branch information
Enes1313 committed Sep 27, 2020
1 parent 6da63a7 commit 80b36f6
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 192 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
/Projects/Eclipse/dsSimulation/Debug
/Projects/DevCpp/dsTest/obj
/Projects/DevCpp/dsSimulation/obj
/Test/test
/Test/simulation
6 changes: 2 additions & 4 deletions DS/eaDSCircularBuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ eaDSCircularBuffer eaDSCircularBufferInit(size_t sizeOfData, void * (*dataCreate

eaDSCircularBuffer eaDSCircularBufferInitWithDetails(size_t sizeOfData, void * (*dataCreate)(size_t), void * (*dataCopy)(void *, const void *, size_t), int (*dataCompare)(const void *, const void *, size_t), void (*dataClear)(void *), size_t capacity)
{
eaDSCircularBuffer circularBuffer;

circularBuffer = (eaDSCircularBuffer) calloc(1, sizeof(struct _eaDSCircularBuffer));
eaDSCircularBuffer circularBuffer = (eaDSCircularBuffer) calloc(1, sizeof(struct _eaDSCircularBuffer));

if (NULL == circularBuffer)
{
Expand Down Expand Up @@ -170,7 +168,7 @@ int eaDSCircularBufferGet(eaDSCircularBuffer circularBuffer, void * data, size_t
return EXIT_SUCCESS;
}

int eaDSCircularBufferGetWhereIsIt(eaDSCircularBuffer circularBuffer, const void * data, size_t numberOfData, size_t * len)
int eaDSCircularBufferGetWhereIsIt(const eaDSCircularBuffer circularBuffer, const void * data, size_t numberOfData, size_t * len)
{
size_t i;

Expand Down
122 changes: 73 additions & 49 deletions DS/eaDSDynamicArray.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ eaDSDynamicArray eaDSDynamicArrayInit(void * (*dataCreateAndCopy)(const void *),

eaDSDynamicArray eaDSDynamicArrayInitWithDetails(void * (*dataCreateAndCopy)(const void *), int (*dataCompare)(const void *, const void *), void (*dataClear)(void *), unsigned short expFactor, unsigned short startingCapacity)
{
eaDSDynamicArray dynamicArray = NULL;

dynamicArray = (eaDSDynamicArray) malloc(sizeof(struct _eaDSDynamicArray));
eaDSDynamicArray dynamicArray = (eaDSDynamicArray) malloc(sizeof(struct _eaDSDynamicArray));

if (NULL == dynamicArray)
{
Expand All @@ -56,9 +54,9 @@ eaDSDynamicArray eaDSDynamicArrayInitWithDetails(void * (*dataCreateAndCopy)(con
dynamicArray->Count = 0;
dynamicArray->Capacity = dynamicArray->StartingCapacity;
dynamicArray->ExpFactor = (expFactor < 2) ? DEFAULT_EXP_FACTOR : expFactor;
dynamicArray->dataCreateAndCopy = (dataCreateAndCopy == NULL) ? copyAddress : dataCreateAndCopy;
dynamicArray->dataCompare = (dataCompare == NULL) ? compareAddress : dataCompare;
dynamicArray->dataClear = (dataClear == NULL) ? free : dataClear;
dynamicArray->dataCreateAndCopy = (NULL == dataCreateAndCopy) ? copyAddress : dataCreateAndCopy;
dynamicArray->dataCompare = (NULL == dataCompare) ? compareAddress : dataCompare;
dynamicArray->dataClear = (NULL == dataClear) ? free : dataClear;
}
}

Expand Down Expand Up @@ -122,9 +120,7 @@ void eaDSDynamicArrayClear(eaDSDynamicArray dynamicArray)
void eaDSDynamicArraySort(eaDSDynamicArray dynamicArray)
{
void * buf;
size_t i, j, N;

N = dynamicArray->Count;
size_t i, j, N = dynamicArray->Count;

for(i = 1; i < N; i++)
{
Expand All @@ -149,9 +145,9 @@ size_t eaDSDynamicArrayGetCapacity(const eaDSDynamicArray dynamicArray)

int eaDSDynamicArrayAdd(eaDSDynamicArray dynamicArray, const void * data)
{
void * item;
void * item = dynamicArray->dataCreateAndCopy(data);

if (NULL == (item = dynamicArray->dataCreateAndCopy(data)))
if (NULL == item)
{
perror(NULL);

Expand All @@ -160,11 +156,10 @@ int eaDSDynamicArrayAdd(eaDSDynamicArray dynamicArray, const void * data)

if (dynamicArray->Count == dynamicArray->Capacity)
{
size_t i;
void ** tmp;

dynamicArray->Capacity *= dynamicArray->ExpFactor;
tmp = (void **) malloc(dynamicArray->Capacity * sizeof(void *));
tmp = (void **) realloc(dynamicArray->Data, dynamicArray->Capacity * sizeof(void *));

if (NULL == tmp)
{
Expand All @@ -174,12 +169,6 @@ int eaDSDynamicArrayAdd(eaDSDynamicArray dynamicArray, const void * data)
return EXIT_FAILURE;
}

for (i = 0; i < dynamicArray->Count; i++)
{
tmp[i] = dynamicArray->Data[i];
}

free(dynamicArray->Data);
dynamicArray->Data = tmp;
}

Expand All @@ -189,11 +178,9 @@ int eaDSDynamicArrayAdd(eaDSDynamicArray dynamicArray, const void * data)
return EXIT_SUCCESS;
}

int eaDSDynamicArrayInsert(eaDSDynamicArray dynamicArray, const void * data, const size_t index)
int eaDSDynamicArrayInsert(eaDSDynamicArray dynamicArray, const void * data, size_t index)
{
size_t j, cnt;

cnt = dynamicArray->Count;
size_t j, cnt = dynamicArray->Count;

if(index <= cnt)
{
Expand All @@ -211,7 +198,7 @@ int eaDSDynamicArrayInsert(eaDSDynamicArray dynamicArray, const void * data, con
void ** tmp;

dynamicArray->Capacity *= dynamicArray->ExpFactor;
tmp = (void **) malloc(dynamicArray->Capacity * sizeof(void *));
tmp = (void **) realloc(dynamicArray->Data, dynamicArray->Capacity * sizeof(void *));

if(NULL == tmp)
{
Expand All @@ -221,12 +208,6 @@ int eaDSDynamicArrayInsert(eaDSDynamicArray dynamicArray, const void * data, con
return EXIT_FAILURE;
}

for (j = 0; j < dynamicArray->Count; j++)
{
tmp[j] = dynamicArray->Data[j];
}

free(dynamicArray->Data);
dynamicArray->Data = tmp;
}

Expand Down Expand Up @@ -254,14 +235,30 @@ int eaDSDynamicArrayInsert(eaDSDynamicArray dynamicArray, const void * data, con

void eaDSDynamicArrayRemove(eaDSDynamicArray dynamicArray, const void * data)
{
size_t i, cnt;

cnt = dynamicArray->Count;
size_t i, cnt = dynamicArray->Count;

for (i = 0; i < cnt; i++)
{
if (!dynamicArray->dataCompare(data, dynamicArray->Data[i]))
{
if ((DEFAULT_STARTING_CAPACITY < dynamicArray->Capacity) && (dynamicArray->Count < dynamicArray->Capacity / dynamicArray->ExpFactor))
{
void ** tmp;

dynamicArray->Capacity /= dynamicArray->ExpFactor;
tmp = (void **) realloc(dynamicArray->Data, dynamicArray->Capacity * sizeof(void *));

if (NULL != tmp)
{
dynamicArray->Data = tmp;
}
else
{
dynamicArray->Capacity *= dynamicArray->ExpFactor;
}

}

dynamicArray->Count--;
dynamicArray->dataClear(dynamicArray->Data[i]);

Expand All @@ -277,14 +274,29 @@ void eaDSDynamicArrayRemove(eaDSDynamicArray dynamicArray, const void * data)

void eaDSDynamicArrayRemoveAll(eaDSDynamicArray dynamicArray, const void * data)
{
size_t i, cnt;

cnt = dynamicArray->Count;
size_t i, cnt = dynamicArray->Count;

for (i = 0; i < cnt; i++)
{
if (!dynamicArray->dataCompare(data, dynamicArray->Data[i]))
{
if ((DEFAULT_STARTING_CAPACITY < dynamicArray->Capacity) && (dynamicArray->Count < dynamicArray->Capacity / dynamicArray->ExpFactor))
{
void ** tmp;

dynamicArray->Capacity /= dynamicArray->ExpFactor;
tmp = (void **) realloc(dynamicArray->Data, dynamicArray->Capacity * sizeof(void *));

if (NULL != tmp)
{
dynamicArray->Data = tmp;
}
else
{
dynamicArray->Capacity *= dynamicArray->ExpFactor;
}
}

dynamicArray->Count--;
dynamicArray->dataClear(dynamicArray->Data[i]);

Expand All @@ -299,14 +311,13 @@ void eaDSDynamicArrayRemoveAll(eaDSDynamicArray dynamicArray, const void * data)
}
}

void eaDSDynamicArrayRemoveAt(eaDSDynamicArray dynamicArray, const size_t index)
void eaDSDynamicArrayRemoveAt(eaDSDynamicArray dynamicArray, size_t index)
{
size_t j, cnt;

cnt = dynamicArray->Count;
size_t j, cnt = dynamicArray->Count;

if(cnt && (index < cnt))
{

dynamicArray->dataClear(dynamicArray->Data[index]);

for (j = index; j < cnt - 1; j++)
Expand All @@ -318,14 +329,29 @@ void eaDSDynamicArrayRemoveAt(eaDSDynamicArray dynamicArray, const size_t index)
}
}

void eaDSDynamicArrayRemoveAtCopyLastItem(eaDSDynamicArray dynamicArray, const size_t index)
void eaDSDynamicArrayRemoveAtCopyLastItem(eaDSDynamicArray dynamicArray, size_t index)
{
size_t cnt;

cnt = dynamicArray->Count;
size_t cnt = dynamicArray->Count;

if(cnt && (index < cnt))
{
if ((DEFAULT_STARTING_CAPACITY < dynamicArray->Capacity) && (dynamicArray->Count < dynamicArray->Capacity / dynamicArray->ExpFactor))
{
void ** tmp;

dynamicArray->Capacity /= dynamicArray->ExpFactor;
tmp = (void **) realloc(dynamicArray->Data, dynamicArray->Capacity * sizeof(void *));

if (NULL != tmp)
{
dynamicArray->Data = tmp;
}
else
{
dynamicArray->Capacity *= dynamicArray->ExpFactor;
}
}

dynamicArray->dataClear(dynamicArray->Data[index]);

if (cnt - 1)
Expand All @@ -337,11 +363,9 @@ void eaDSDynamicArrayRemoveAtCopyLastItem(eaDSDynamicArray dynamicArray, const s
}
}

void * eaDSDynamicArrayGetFrom(const eaDSDynamicArray dynamicArray, const size_t index)
void * eaDSDynamicArrayGetFrom(const eaDSDynamicArray dynamicArray, size_t index)
{
void * data;

data = NULL;
void * data = NULL;

if(index < dynamicArray->Count)
{
Expand All @@ -354,7 +378,7 @@ void * eaDSDynamicArrayGetFrom(const eaDSDynamicArray dynamicArray, const size_t
return data;
}

void * eaDSDynamicArrayGetAddressFrom(const eaDSDynamicArray dynamicArray, const size_t index)
void * eaDSDynamicArrayGetAddressFrom(const eaDSDynamicArray dynamicArray, size_t index)
{
if(index < dynamicArray->Count)
{
Expand Down
Loading

0 comments on commit 80b36f6

Please sign in to comment.