erase() function should be fairly good
This commit is contained in:
+2
-2
@@ -9,8 +9,8 @@ SpaceBeforeCpp11BracedList: true
|
|||||||
SeparateDefinitionBlocks: Always
|
SeparateDefinitionBlocks: Always
|
||||||
Cpp11BracedListStyle: false
|
Cpp11BracedListStyle: false
|
||||||
BreakAfterReturnType: TopLevel
|
BreakAfterReturnType: TopLevel
|
||||||
AlignTrailingComments:
|
# AlignTrailingComments:
|
||||||
Kind: Always
|
# Kind: Always
|
||||||
ReflowComments: Always
|
ReflowComments: Always
|
||||||
AllowShortFunctionsOnASingleLine: All
|
AllowShortFunctionsOnASingleLine: All
|
||||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||||
|
|||||||
@@ -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)
|
||||||
+35
-12
@@ -12,16 +12,17 @@
|
|||||||
* > at() Returns an indexed element from a vector
|
* > at() Returns an indexed element from a vector
|
||||||
* > back() Returns the last element of a vector
|
* > back() Returns the last element of a vector
|
||||||
* > begin() Returns an iterator pointing to the beginning 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
|
* > capacity() Returns the number of elements that a vector's reserved memory is able to store
|
||||||
* is able to store > front() Returns the first element of a vector > end()
|
* > front() Returns the first element of a vector
|
||||||
* Returns an iterator pointing to the end of a vector > push_back() Adds an
|
* > end() Returns an iterator pointing to the end of a vector
|
||||||
* element to the end of a vector > size() Returns the number of elements
|
* > push_back() Adds an element to the end of a vector
|
||||||
* in 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
|
* 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
|
* 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
|
* 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
|
* 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()
|
* 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;
|
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
|
void
|
||||||
print_vec(const Vec8_t* vec)
|
print_vec(const Vec8_t* vec)
|
||||||
{
|
{
|
||||||
@@ -173,6 +187,15 @@ back(const Vec8_t* vec)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
empty(const Vec8_t* vec) {
|
||||||
|
|
||||||
|
if(vec->size > 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Vec8_t
|
Vec8_t
|
||||||
add_back(Vec8_t* vec, const char val)
|
add_back(Vec8_t* vec, const char val)
|
||||||
{
|
{
|
||||||
@@ -201,11 +224,11 @@ main()
|
|||||||
vec = add_back(&vec, '6');
|
vec = add_back(&vec, '6');
|
||||||
vec = add_back(&vec, '8');
|
vec = add_back(&vec, '8');
|
||||||
vec = add_back(&vec, '6');
|
vec = add_back(&vec, '6');
|
||||||
clear(&vec);
|
vec = *erase(&vec, begin(&vec) + 2);
|
||||||
for(int i = 0; i < vec.size; i++) {
|
// for(int i = 0; i < vec.size; i++) {
|
||||||
printf("%i\n", at(&vec, i));
|
// printf("%i\n", at(&vec, i));
|
||||||
}
|
// }
|
||||||
// print_vec(&vec);
|
print_vec(&vec);
|
||||||
// printf("%c", at(nullptr, 0));
|
// printf("%c", at(nullptr, 0));
|
||||||
|
|
||||||
delete(&vec);
|
delete(&vec);
|
||||||
|
|||||||
Reference in New Issue
Block a user