dynamic string implemented
MMakefile
| @@ -1,3 +1,3 @@ | |||
|---|---|---|---|
| 1 | 1 | all: | |
| 2 | - | gcc -Og -g -march=native -shared -fPIC -fstrict-aliasing vector.c -o cutils.so -flto \ | |
| 2 | + | gcc -Og -g -march=native -shared -fPIC -fstrict-aliasing vector.c dyn_string.c -o cutils.so -flto \ | |
| 3 | 3 | -Wall -Werror -Wpedantic -Wnull-dereference -Wshadow -Wconversion -Wstrict-prototypes -Wmissing-prototypes -Wcast-qual -Wstrict-overflow=5 -Wunreachable-code -Wno-unused-parameter | |
Mcutils.h
| @@ -1,4 +1,5 @@ | |||
|---|---|---|---|
| 1 | 1 | #ifndef CUTILS_H | |
| 2 | 2 | #define CUTILS_H | |
| 3 | 3 | #include <vector.h> | |
| 4 | + | #include <dyn_string.h> | |
| 4 | 5 | #endif //CUTILS_H | |
Mvector.c
| @@ -12,7 +12,7 @@ Vector* new_vector(void) | |||
|---|---|---|---|
| 12 | 12 | return NULL; | |
| 13 | 13 | } | |
| 14 | 14 | vector->length = 0; | |
| 15 | - | vector->capacity = 4; | |
| 15 | + | vector->capacity = VECTOR_DEFAULT_SIZE; | |
| 16 | 16 | ||
| 17 | 17 | return vector; | |
| 18 | 18 | } | |
| @@ -84,7 +84,7 @@ FindReturn vector_find(const Vector* haystack, const void* needle, bool (*cmp)(c | |||
|---|---|---|---|
| 84 | 84 | ||
| 85 | 85 | bool vector_insert(Vector* vector, size_t index, void* item) | |
| 86 | 86 | { | |
| 87 | - | if(!vector_adjust_size(vector, ++vector->length)) | |
| 87 | + | if(!vector_adjust_size(vector, vector->length)) | |
| 88 | 88 | return false; | |
| 89 | 89 | ||
| 90 | 90 | memmove(vector->items+index+1, vector->items+index, (vector->length-index)*sizeof(*vector->items)); | |