From 0a8819b7986f9c28d859a260c0c9bbe275765aed Mon Sep 17 00:00:00 2001 From: Andrew Haynes Date: Tue, 28 Apr 2026 13:44:56 -0400 Subject: [PATCH] erase() function should be fairly good --- .clang-format | 4 ++-- AGENTS.md | 12 ++++++++++++ src/main.c | 47 +++++++++++++++++++++++++++++++++++------------ 3 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 AGENTS.md diff --git a/.clang-format b/.clang-format index 369e701..8d75679 100644 --- a/.clang-format +++ b/.clang-format @@ -9,8 +9,8 @@ SpaceBeforeCpp11BracedList: true SeparateDefinitionBlocks: Always Cpp11BracedListStyle: false BreakAfterReturnType: TopLevel -AlignTrailingComments: - Kind: Always +# AlignTrailingComments: +# Kind: Always ReflowComments: Always AllowShortFunctionsOnASingleLine: All AllowShortIfStatementsOnASingleLine: AllIfsAndElse diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..da65e01 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,12 @@ +# AI Agent Rules + +## AI Usage Policy (from src/main.c:46-55) +- Absolutely no AI is permitted when writing source code. +- AI is allowed to generate tests for code; however, test results and the AI cannot give code as to how to fix the source aside from pseudo code that has no clear relation to the source aside from a recreation of the problem in a different way entirely. +- Source code comments are for the author's short-term memory and do not affect AI behavior. + +## Project Code Conventions +- **Formatting**: Follow `.clang-format` (Google-based style, tabs (width 8), Allman braces, short functions/if/loops can be single-line) +- **Linting**: Follow `.clang-tidy` (bugprone, concurrency, misc, modernize, performance, readability, portability checks; `lower_case` naming for variables and functions) +- **Build**: C23 standard, CMake 3.16+ +- **Naming**: Variables and functions use `lower_case` (enforced by clang-tidy) diff --git a/src/main.c b/src/main.c index 281e5e5..642a5c4 100644 --- a/src/main.c +++ b/src/main.c @@ -12,16 +12,17 @@ * > at() Returns an indexed element from a vector * > back() Returns the last element of a vector * > begin() Returns an iterator pointing to the beginning of a vector - * > capacity() Returns the number of elements that a vector's reserved memory - * is able to store > front() Returns the first element of a vector > end() - * Returns an iterator pointing to the end of a vector > push_back() Adds an - * element to the end of a vector > size() Returns the number of elements - * in a vector + * > capacity() Returns the number of elements that a vector's reserved memory is able to store + * > front() Returns the first element of a vector + * > end() Returns an iterator pointing to the end of a vector + * > push_back() Adds an element to the end of a vector + * > size() Returns the number of elements in a vector + * > clear() Removes all of the contents of a vector + * > empty() Checks whether a vector is empty or not * * assign() Fills a vector with multiple values - * clear() Removes all of the contents of a vector * data() Returns a pointer to the block of memory where a vector's elements are - * stored empty() Checks whether a vector is empty or not erase() Removes + * stored erase() Removes * a number of elements from a vector insert() Inserts a number of elements * into a vector max_size() Returns the maximum number of elements that a * vector can have pop_back() Removes the last element of a vector rbegin() @@ -124,6 +125,19 @@ at(const Vec8_t* vec, const int idx) return -1; } +Vec8_t* +erase(Vec8_t* vec, const int iter) { + /* + * Clear the value at iter to 0 + * shift all the values in the vector over to the left one + * */ + if(vec == nullptr) return nullptr; + if(vec->arr == nullptr) return nullptr; + vec->arr[iter] = 0; + memmove(&vec[iter], &vec[iter + 1], (vec->size * sizeof(char)) -1); + return vec; +} + void print_vec(const Vec8_t* vec) { @@ -173,6 +187,15 @@ back(const Vec8_t* vec) return -1; } +int +empty(const Vec8_t* vec) { + + if(vec->size > 0) { + return 1; + } + return 0; +} + Vec8_t add_back(Vec8_t* vec, const char val) { @@ -201,11 +224,11 @@ main() vec = add_back(&vec, '6'); vec = add_back(&vec, '8'); vec = add_back(&vec, '6'); - clear(&vec); - for(int i = 0; i < vec.size; i++) { - printf("%i\n", at(&vec, i)); - } - // print_vec(&vec); + vec = *erase(&vec, begin(&vec) + 2); + // for(int i = 0; i < vec.size; i++) { + // printf("%i\n", at(&vec, i)); + // } + print_vec(&vec); // printf("%c", at(nullptr, 0)); delete(&vec);