{"id":18644298,"url":"https://github.com/rphii/c-vector","last_synced_at":"2025-08-20T14:06:53.652Z","repository":{"id":153522441,"uuid":"628171332","full_name":"rphii/c-vector","owner":"rphii","description":"Compile Time Generic Dynamic Vector in C","archived":false,"fork":false,"pushed_at":"2024-07-24T18:56:56.000Z","size":119,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-17T17:40:07.954Z","etag":null,"topics":["array","c","c99","clang","compile-time","gcc","generic","tcc","vec","vector","vectors"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rphii.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-15T05:49:51.000Z","updated_at":"2024-07-24T18:57:01.000Z","dependencies_parsed_at":"2024-01-16T01:36:02.620Z","dependency_job_id":"580272bc-3a7f-45a5-bbdc-8ffa315e8454","html_url":"https://github.com/rphii/c-vector","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rphii/c-vector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rphii%2Fc-vector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rphii%2Fc-vector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rphii%2Fc-vector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rphii%2Fc-vector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rphii","download_url":"https://codeload.github.com/rphii/c-vector/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rphii%2Fc-vector/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271330292,"owners_count":24740815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-20T02:00:09.606Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","c","c99","clang","compile-time","gcc","generic","tcc","vec","vector","vectors"],"created_at":"2024-11-07T06:11:13.942Z","updated_at":"2025-08-20T14:06:53.600Z","avatar_url":"https://github.com/rphii.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Things may still change\n# Very untested as of now\n\n# c-vector\nCompile Time Generic Dynamic Vector in C.\n\n## First Things First\nOn it's own, no code is being compiled. You first have to include and implement a vector of your desires. For that, there are two macros.\n```c\n#include \"vec.h\"\nVEC_INCLUDE(N, A, T, M);\nVEC_IMPLEMENT(N, A, T, M, F);\n```\n1. `N` - **N**ame - the resulting name of the vector struct\n2. `A` - **A**bbreviation - functions get prefixed with that\n3. `T` - **T**ype - the type of your elements within the vector\n4. `M` - **M**ode - storage type, either `BY_VAL` (by value) or `BY_REF` (by reference)\n5. `F` - **F**ree - provide a freeing function for your elements, if available\n\n## Example\n\n### Basic Vectors\n```c\nVEC_INCLUDE(VecU8, vec_u8, unsigned char, BY_VAL);\nVEC_IMPLEMENT(VecU8, vec_u8, unsigned char, BY_VAL, 0);\n```\n\n```c\nVEC_INCLUDE(VecSize, vec_size, size_t, BY_VAL);\nVEC_IMPLEMENT(VecSize, vec_size, size_t, BY_VAL, 0);\n```\n\n### Struct Vectors\n```c\nVEC_INCLUDE(Vec2U8, vec2_u8, VecU8, BY_VAL);\nVEC_IMPLEMENT(Vec2U8, vec2_u8, VecU8, BY_VAL, vec_u8_free);\n```\n\n```c\nVEC_INCLUDE(Vec2U8, vec2_u8, VecU8, BY_REF);\nVEC_IMPLEMENT(Vec2U8, vec2_u8, VecU8, BY_REF, vec_u8_free);\n```\n\n## Design Considerations\n- Both `BY_VAL` and `BY_REF` can be used on either basic types or (complex) structs. Either way, if\n  you (e.g.) push back a value, its content is copied\n- Generally speaking, I'd use the latter when dealing with structs where `sizeof struct \u003e sizeof(void *)`.\n- I went ahead and compared the very basic performance between the two approaches [here](https://github.com/rphii/vec_test).\n\n## Metaprogramming\n### Advantages\n- Compiler optimized code\n- Flexibility, reusability (generics / templates)\n- Type safety\n### Disadvantages\n- Maintenance challenges\n- Debugging difficulties\n- Compilation overhead\n\n## How to use it\n### Examples\n- `$ cd examples \u0026\u0026 make` (binaries in subfolder \"bin\") -\u003e WIP, I want to add more examples\n\n### Tests\n- `$ cd test \u0026\u0026 make` (binaries in subfolder \"bin\") -\u003e WIP, I want to add more tests to make the vector bug free\n- Ignore the `compile_flags.txt` files -\u003e I added those only so that my LSP knows what's up.\n\n### Available Functions\nThe `A##` means the `A` specified in the two macros.\n- `A##_zero` set vector to zero without freeing\n- `A##_clear` clear vector but keep capacity\n- `A##_length` return length of of the vector in items\n- `A##_capacity` return capacity of the vector\n- `A##_empty` return if it's empty\n- `A##_resize` resize vector to optimal given length in items\n- `A##_free` free all memory used\n- `A##_reserved` return bytes allocated\n- `A##_reserve` reserve more memory in items\n- `A##_shrink` shrinks vector to minimal possible capacity\n- `A##_set_at` overwrite item at index, free any previous item\n- `A##_push_front` insert item in the front\n- `A##_push_back` insert item at the back\n- `A##_push_at` insert item after index\n- `A##_pop_front` pop item in the front\n- `A##_pop_back` pop item at the back\n- `A##_get_at` get item at index\n- `A##_get_front` get item in the front\n- `A##_get_back` get item at the back\n- `A##_swap` swap two items by index\n- `A##_reverse` reverse the vector\n- `A##_iter_begin` return beginning iterator\n- `A##_iter_end` return end of iterator\n\n### Additional Settings\nThere are various settings one can adjust to fit the vector to their needs. To use those, I strongly\nrecommend the following:\n- In header files (using the `INCLUDE` macro) -\u003e `#define` the respective settings before\n  including `vec.h`. Before the end of your header `#undef` them, so that other possible vectors\n  that may create a vector of such a \"modified\" vector with custom settings reverts back to the\n  defaults\n- In source files (using the `IMPLEMENT` macro) -\u003e `#define` the respective settings after you\n  included your custom vector header and have them be equally set.\n\n#### Settings list\n- `VEC_SETTINGS_KEEP_ZERO_END` number; specify how much zero memory should be kept at the end when\n  reserving memory (e.g. string implementation)\n- `VEC_SETTINGS_STRUCT_ITEMS` literal; specify the name of the `items` placeholder to something\n  else, if you so desire (e.g. string implementation, where it makes more sense to use another\n  literal besides the previously mentioned for the string placeholder)\n- `VEC_SETTINGS_DEFAULT_SIZE` number; specify how many item spaces shall be reserved minimally\n\n# todo so I don't forget\n- add `pop_at` pop item at index\n- add `emplace` insert item before index\n- add stuff that allows to pop/push/insert/emplace an entire array, or a subsection...\n- if we pushed from the front, then N.first can actually be reduced, instead of moving everything\n  one back!\n- bundle the snippets I copied around used for freeing into it's own function\n- comparing stuff requiring a comparing function: cmp, find, match, rfind, rmatch, invert\n- cat, back/at/front, pop_at, pop_slice, apply\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frphii%2Fc-vector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frphii%2Fc-vector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frphii%2Fc-vector/lists"}