{"id":19152598,"url":"https://github.com/bamless/cvector","last_synced_at":"2025-02-22T21:15:18.650Z","repository":{"id":114070234,"uuid":"282021048","full_name":"bamless/cvector","owner":"bamless","description":"A C99 implementation of a growable array that mimics C++ std::vector","archived":false,"fork":false,"pushed_at":"2020-11-25T12:18:45.000Z","size":22,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-03T18:47:14.359Z","etag":null,"topics":["array","c","c99","dynamic-array","vector"],"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/bamless.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":"2020-07-23T17:58:32.000Z","updated_at":"2024-05-04T08:08:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"c5dd8687-36ea-4735-9418-ac52104dc9ab","html_url":"https://github.com/bamless/cvector","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bamless%2Fcvector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bamless%2Fcvector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bamless%2Fcvector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bamless%2Fcvector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bamless","download_url":"https://codeload.github.com/bamless/cvector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240236361,"owners_count":19769580,"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","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","dynamic-array","vector"],"created_at":"2024-11-09T08:18:29.156Z","updated_at":"2025-02-22T21:15:18.645Z","avatar_url":"https://github.com/bamless.png","language":"C","readme":"# cvector\n![test](https://github.com/bamless/cvector/workflows/test/badge.svg)\n\nThis is a dynamic growable array implementation that makes an effort to mimic the C++ `std::vector` \ninterface. The vector uses `void*` to store data internally, sacrificing type safety in order to\nmake it possible to store data of any type.\n\n## How to use\n\nThe following example shows a typical usage of `Vector`:\n\n```c\n#include \"vector.h\"\n\nint main() {\n    // Create a vector of ints\n    Vector vec = vecNew(sizeof(int));\n\n    // Or alternatively:\n    Vector vec;\n    vecInit(\u0026vec, sizeof(int))\n\n    for(int i = 0; i \u003c 10; i++) {\n        vecPush(\u0026vec, \u0026i); // Copy `i` to the end of the vector\n    }\n\n    // Print the vector's elements\n    vecForeach(int* it, vec) {\n        printf(\"%d\\n\", *it);\n    }\n\n    // Free the vector's data\n    vecFree(\u0026vec);\n}\n```\n\nThe interface tries to emulate copy/move constructors and assignments using functions:\n\n```c\n#include \"vector.h\"\n\nint main() {\n    Vector vec = vecNew(sizeof(int));\n    for(int i = 0; i \u003c 5; i++) {\n        vecPush(\u0026vec, \u0026i);\n    }\n\n    // 'Copy constructor', copies the contents of `vec` into `vecCpy`\n    Vector vecCpy = vecCopy(\u0026vec);\n\n    // Copy assignments work similarly, but operate on a vector that is already \n    // initialized, freeing its element before copying the other vector's data\n    Vector vec2 = vecNew(sizeof(int));\n   \n    // [...]\n\n    // Copy the the contents of `vec` into `vec2`, releasing `vec2` data\n    vecCopyAssign(\u0026vec2, \u0026vec);\n\n    // Move the contents of `vec` into `vecMov`. Now `vec` is in\n    // an 'uninitialized state' and shouldn't be used anymore\n    Vector vecMov = vecMove(\u0026vec);\n\n    // Move assignment\n    Vector vec3 = vecNew(sizeof(int));\n    \n    // [...]\n\n    // Similar to the above, but releases `vec3` data\n    vecMoveAssign(\u0026vec3, \u0026vec);\n}\n```\n\nBeware that assignment 'operators' should be used only on previously initialized vectors, else \nundefined behaviour is invoked. A vector is initialized after a call to `vecNew` or `vecInit` and\nuninitialized after the corresponding `vecFree` call. You can even query the vector's state\nusing the `vecIsInitialized(Vector *vec)` function.\n\nIterators are also supported in the form of pointers to the underlying data:\n```c\n#include \"vector.h\"\n\nint main() {\n    Vector vec = vecNew(sizeof(int));\n    \n    // [...]\n\n    // A pointer to the first element of the vector\n    int* iteratorToStart = vecBegin(\u0026vec);\n\n    // A pointer to one past the end of the vector\n    int* iteratorToEnd = vecBegin(\u0026vec);\n\n    // A pointer to the fifth element of the vector\n    int* iterator = vecIterator(\u0026vec, 5);\n\n    // You can retrieve an index from an iterator\n    size_t index = vecIteratorIndex(\u0026vec, iterator);\n\n    // You can then iterate over the vector like this:\n    for(int *it = vecBegin(\u0026vec), it != vecEnd(\u0026vec); it++) {\n        printf(\"%d\\n\", *it);\n    }\n\n    // Alternatively you can use the vecForeach helper macro\n    vecForeach(int *it, vec) {\n        printf(\"%d\\n\", *it);\n    }\n}\n```\n\n## Integration\n\nYou can simply copy `vector.h` and `vector.c` inside your project and you're done!\n\n## Compilation\n\nA simple Makefile is provided for building a static library if you prefer linking instead of copying \nthe files in your project. Simply type this in the terminal:\n\n`make config=Release cvector`\n\nsupported `config` values are `Debug` and `Release`.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbamless%2Fcvector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbamless%2Fcvector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbamless%2Fcvector/lists"}