{"id":17209169,"url":"https://github.com/rswinkle/cvector","last_synced_at":"2025-04-13T22:32:01.192Z","repository":{"id":146964813,"uuid":"1625252","full_name":"rswinkle/CVector","owner":"rswinkle","description":"A C vector library similar to the C++ STL vector","archived":false,"fork":false,"pushed_at":"2025-01-04T03:10:03.000Z","size":4166,"stargazers_count":18,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-05T10:34:22.947Z","etag":null,"topics":["c","cvector","dynamic-array","single-header-lib","standalone-library"],"latest_commit_sha":null,"homepage":"https://www.robertwinkler.com/projects/cvector.html","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/rswinkle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"liberapay":"rswinkle","custom":"http://www.robertwinkler.com/donations.html"}},"created_at":"2011-04-17T03:57:33.000Z","updated_at":"2025-01-04T03:10:04.000Z","dependencies_parsed_at":"2024-06-02T03:29:37.760Z","dependency_job_id":"db8ffcfc-7e38-4136-aa0e-0af7e1c7f0d8","html_url":"https://github.com/rswinkle/CVector","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rswinkle%2FCVector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rswinkle%2FCVector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rswinkle%2FCVector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rswinkle%2FCVector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rswinkle","download_url":"https://codeload.github.com/rswinkle/CVector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248790663,"owners_count":21162069,"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":["c","cvector","dynamic-array","single-header-lib","standalone-library"],"created_at":"2024-10-15T02:50:57.487Z","updated_at":"2025-04-13T22:32:00.995Z","avatar_url":"https://github.com/rswinkle.png","language":"C","readme":"CVECTOR\n=======\n\n[Download](https://github.com/rswinkle/cvector)\n\nThis is a relatively simple ANSI compliant C vector library with specific structures and\nfunctions for int's, double's and string's and support for all other types\nusing a generic structure where the type is passed in as void\\* and stored in a byte array\n(to avoid dereferencing void\\* warnings and frequent casting) .\nThe generic vector is very flexible and allows you to provide free and init functions\nif you like that it will call at appropriate times similar to the way C++ containers\nwill call destructors and copy constructors.\n\nOther modifiable parameters are at the top of the respective cvector.c's\n\n\tcvec_sz CVEC_I_START_SZ = 50;\n\tcvec_sz CVEC_D_START_SZ = 50;\n\tcvec_sz CVEC_STR_START_SZ = 20;\n\tcvec_sz CVEC_VOID_START_SZ = 20;\n\n\t#define CVEC_I_ALLOCATOR(x) ((x+1) * 2)\n\t#define CVEC_D_ALLOCATOR(x) ((x+1) * 2)\n\t#define CVEC_STR_ALLOCATOR(x) ((x+1) * 2)\n\t#define CVEC_VOID_ALLOCATOR(x) ((x+1) * 2)\n\nThe allocator macros are used in all functions that increase the size by 1.\nIn others (constructors, insert_array, reserve) CVEC_X_START_SZ is the amount\nextra allocated.\n\nNote that the (x+1) portion allows you to use the non-void vectors\nwithout calling any of the init functions first *if* you zero them out.  This\nmeans size, capacity, and a are 0/NULL which is valid because realloc, acts like\nmalloc when given a NULL pointer.  With cvector_void you still have to set\nelem_size, and optionally elem_free/elem_init. See the zero_init_x_test()'s\nin cvector_tests.c for example of that use.\n\nThe `cvec_sz` type defaults to `size_t` but you can define CVEC_SIZE_T to your\npreferred type before including the header which in turn is then `typedef`'d\nto `cvec_sz`.  It has to be defined before every header inclusion.  Note, if\nyou use a signed type, passing a negative value is undefined behavior\n(ie it'll likely crash immediately).  Of course if you passed a negative while\nusing the default `size_t` you'd probably crash anyway as it would wrap around\nto a problematically large number.\n\nThere are also 2 templates, one for basic types and one for types that contain\ndynamically allocated memory and you might want a free and/or init function.\nIn other words the first template is based off cvector_i and the second is based\noff of cvector_void, so look at the corresponding documentation for behavior.\n\nThere are 2 ways to use/create your own cvector types.  The easiest way is to use\nthe macros defined in cvector_macro.h which are also included in the all-in-one header\ncvector.h.  You can see how to use them in cvector_tests.c:\n\n\t#define RESIZE(a) (((a)+1)*2)\n\n\tCVEC_NEW_DECLS(short)\n\tCVEC_NEW_DECLS2(f_struct)\n\n\tCVEC_NEW_DEFS(short, RESIZE)\n\tCVEC_NEW_DEFS2(f_struct, RESIZE)\n\nThe RESIZE macro has to be defined before using the macros for now, serving the\nsame purpose as the regular allocator macros above.  Obviously the DECL macros\ndeclare type and prototypes while the DEFS define them.  Using the macros for\nuser made types is much easier than the files because you can call the macro\nright in the header where you define the type instead of having to include the\ntype in the generated file.  Basically 1 step rather than 2-3 and no extra files\nneeded.\n\nThe other way, and the only way in previous versions of CVector, is to generate\nyour own files from the template files which are located in cvector_template.h\nand cvector_template2.h.\n\nTo generate your own cvector files for a type just run:\n\n\tpython3 generate_code.py yourtype\n\nwhich will generate the results for both templates so just delete the one\nyou don't want.\n\ncvector_short and cvector_f_struct are examples of the generated files.\n\nBuilding\n========\nI use [premake](http://premake.github.io/) generated makefiles which are\nincluded in the build subdirectory.  However if you modified premake4.lua\nthe command to regenerate them is `premake4 gmake`.  cd into the build\ndirectory and run `make` or `make config=release`. I have not tried it on\nwindows though it should work (well I'm not sure about CUnit ...).\n\nThere is no output of any kind, no errors or warnings.\n\nIt has been relatively well tested using CUnit tests which all pass.\nI've also run it under valgrind and there are no memory leaks.\n\n\t$ valgrind --leak-check=full -v ./cvector\n\t==116175==\n\t==116175== HEAP SUMMARY:\n\t==116175==     in use at exit: 0 bytes in 0 blocks\n\t==116175==   total heap usage: 10,612 allocs, 10,612 frees, 1,151,748 bytes allocated\n\t==116175==\n\t==116175== All heap blocks were freed -- no leaks are possible\n\t==116175==\n\t==116175== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)\n\t$ grep FAIL CUnitAutomated-Results.xml\n\t\u003cFAILED\u003e 0 \u003c/FAILED\u003e \n\t\u003cFAILED\u003e 0 \u003c/FAILED\u003e \n\t\u003cFAILED\u003e 0 \u003c/FAILED\u003e \n\n\nI plan to continue to improve/modify it but probably only in minor ways and\nonly if I think something should be changed.  This library is mostly\nfor my own use but I thought I would share it and use it as a platform\nto learn CUnit and Doxygen.\n\nYou can probably get Cunit from your package manager but\nif you want to get the most up to date version of CUnit go here:\n\nhttp://cunit.sourceforge.net/index.html\nhttp://sourceforge.net/projects/cunit/\n\nI'm using version 2.1-3.\n\nUsage\n=====\nTo actually use the library just copy the appropriate c/h file pair(s) to your project\nor just use cvector.h.  To get a good idea of how to use the library and see it in\naction and how it should behave, you can look at cvector_tests.c but for more practical\nexamples, you can look at my other projects that use cvector like [C_Interpreter](https://github.com/rswinkle/c_interpreter),\n[CPIM2](https://github.com/rswinkle/cpim2), [sdl_img](https://github.com/rswinkle/sdl_img),\n[c_bigint](https://github.com/rswinkle/c_bigint) and [spelling_game](https://github.com/rswinkle/spelling_game).\n\nDocumentation\n=============\nThe Doxygen documentation is generated with the command\n\n\tdoxygen Doxyfile\n\nin the root directory.  The Doxygen generated html docs are\n[online here](http://www.robertwinkler.com/projects/cvector/)\n\nTest Results\n============\nThe automated Travis build also runs the tests and fails if any tests fail.\nIf you want a pretty visualization of the test results (updated with every release\nnot every commit), you can see it\n[here](http://www.robertwinkler.com/projects/cvector/CUnitAutomated-Results.xml).\n\nLICENSE\n=======\nCVector is licensed under the MIT License.\n\nCopyright (c) 2011-2025 Robert Winkler\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\ndocumentation files (the \"Software\"), to deal in the Software without restriction, including without limitation\nthe rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and\nto permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED\nTO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\nTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF\nCONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\nIN THE SOFTWARE.\n\n","funding_links":["https://liberapay.com/rswinkle","http://www.robertwinkler.com/donations.html"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frswinkle%2Fcvector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frswinkle%2Fcvector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frswinkle%2Fcvector/lists"}