-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6aa04fc
commit 9ad634f
Showing
16 changed files
with
2,786 additions
and
175 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Joseph | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# GArray | ||
|
||
A small (300 lines) dynamic array. | ||
|
||
## Example | ||
```C | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include "dynamic_array.h" | ||
|
||
|
||
int | ||
main(void) | ||
{ | ||
uint32_t item_size = sizeof(int); | ||
uint32_t initial_size = 10; | ||
uint32_t i; | ||
|
||
GArray *array = GArrayCreate(item_size, initial_size); | ||
if (array == NULL) | ||
{ return EXIT_FAILURE; | ||
} | ||
|
||
/* make all data 0's to show it works */ | ||
for(i = GArrayStart(array); i < GArrayEnd(array); ++i) | ||
{ GArrayReplace(array, NULL, i); | ||
} | ||
|
||
int value = 42; | ||
if (GArrayPushBack(array, &value) != EXIT_SUCCESS) | ||
{ | ||
GArrayWipe(array); | ||
free(array); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
|
||
int *p = (int *)GArrayAt(array, 0); | ||
|
||
if (p) | ||
{ printf("Previous Value at index 0: %d\n", *p); | ||
} | ||
else | ||
{ | ||
GArrayWipe(array); | ||
free(array); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
int new_value = 99; | ||
if (GArrayReplace(array, &new_value, 0) != EXIT_SUCCESS) | ||
{ | ||
GArrayWipe(array); | ||
free(array); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
p = (int *)GArrayAt(array, 0); | ||
if (p) | ||
{ printf("New value at index 0: %d\n", *p); | ||
} | ||
else | ||
{ | ||
GArrayWipe(array); | ||
free(array); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
int insert_value = 55; | ||
if (GArrayInsert(array, &insert_value, 1) != EXIT_SUCCESS) | ||
{ | ||
GArrayWipe(array); | ||
free(array); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
printf("Value at index %d: %d\n", 1, *(int *)GArrayAt(array, 1)); | ||
printf("Deleting Index %d\n", 1); | ||
|
||
if (GArrayDelete(array, 1) != EXIT_SUCCESS) | ||
{ | ||
GArrayWipe(array); | ||
free(array); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
for (i = GArrayStart(array); i < GArrayEnd(array); ++i) | ||
{ | ||
p = (int *)GArrayAt(array, i); | ||
if (p) | ||
{ printf("Value at index %d: %d\n", i, *p); | ||
} | ||
} | ||
|
||
GArrayWipe(array); | ||
free(array); | ||
return EXIT_SUCCESS; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef __F____ARRAY__H__ | ||
#define __F____ARRAY__H__ | ||
|
||
|
||
#include "dynamic_array.h" | ||
#include "array8.h" | ||
#include "array16.h" | ||
#include "array32.h" | ||
#include "array64.h" | ||
#include "array_p.h" | ||
|
||
#endif |
Oops, something went wrong.