{"id":19923805,"url":"https://github.com/porem5002/dts2","last_synced_at":"2025-03-01T10:21:39.276Z","repository":{"id":180277448,"uuid":"651469256","full_name":"Porem5002/dts2","owner":"Porem5002","description":"A simple library that provides various generic data structures for C programmers.","archived":false,"fork":false,"pushed_at":"2023-11-01T20:36:40.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-12T00:17:29.086Z","etag":null,"topics":["c","data-structures","header","header-only","header-only-lib","header-only-library"],"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/Porem5002.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}},"created_at":"2023-06-09T09:56:17.000Z","updated_at":"2023-07-11T00:18:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"6467551b-22ab-4d98-8f3e-b9d3b1855df7","html_url":"https://github.com/Porem5002/dts2","commit_stats":null,"previous_names":["porem5002/dts2"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Porem5002%2Fdts2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Porem5002%2Fdts2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Porem5002%2Fdts2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Porem5002%2Fdts2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Porem5002","download_url":"https://codeload.github.com/Porem5002/dts2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241349282,"owners_count":19948348,"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","data-structures","header","header-only","header-only-lib","header-only-library"],"created_at":"2024-11-12T22:15:30.435Z","updated_at":"2025-03-01T10:21:39.252Z","avatar_url":"https://github.com/Porem5002.png","language":"C","readme":"# dts2\nA simple library that provides various generic data structures for C programmers.\n\n# Setup\nTo setup the library for your project do the following:\n\n- Create new directory inside your project's directory and call it \"dts2\"\n\n- Copy the the **LICENSE** file and all files ending in **.h** to the \"dts2\" directory\n\nThe library uses C99 features, so to compile a project that uses it, make sure you have a compiler that supports the C99 standard.\n\n# Usage\nThe library is composed of a bunch of header files, each of those files represents a data structure or feature.\n\nTo use one of those constructs, first you need to include the file that contains it, for example:\n\n```C\n#include \"dts2/array.h\" // This will allow you to use arrays\n```\n\nAfter including the functionality that you want, you can now use it in your code.\n\nAdditionally, there's also a macro called **DTS2_DEBUG_ACTIVE** that you can define when compiling your project. If defined, this will enable multiple checks and assertions, inside of the functions and macros of the library, that will help you find bugs in your code.\n\n## Demonstrations\nHere are some demonstrations of the different data structures and features that the library supports.\n\n### Arrays\n```C\n#include \u003cstdio.h\u003e\n// Allow usage of arrays\n#include \"dts2/array.h\"\n\nint main()\n{\n    array(int) a = array_init_new(5, int);\n\n    array_eset(\u0026a, 0, 100);\n    array_eset(\u0026a, 1, 261);\n    array_eset(\u0026a, 2, 123);\n    array_eset(\u0026a, 3, 90);\n    array_eset(\u0026a, 4, 456);\n\n    for(size_t i = 0; i \u003c a.size; i++)\n    {\n        int v = array_eget(\u0026a, i);\n        printf(\"%d \", v);\n    }\n\n    array_free(\u0026a);\n    return 0;\n}\n\n// This will print:\n// 100 261 123 90 456\n```\n\n### Dynamic Arrays\n```C\n#include \u003cstdio.h\u003e\n// Allow usage of dynamic arrays\n#include \"dts2/dynarray.h\"\n\nint main()\n{\n    dynarray(const char*) a = dynarray_init_new(0, const char*);\n\n    dynarray_add(\u0026a, \"John\");\n    dynarray_add(\u0026a, \"Bob\");\n    dynarray_add(\u0026a, \"Adam\");\n    \n    // Add \"Joe\" at index 1, by pushing every element\n    // with index \u003e= 1 forward and\n    // setting value at index 1 to \"Joe\"\n    dynarray_addat(\u0026a, 1, \"Joe\");\n    \n    dynarray_addat(\u0026a, 1, \"Guy\");\n\n    // Removes element at index 1\n    dynarray_remat(\u0026a, 1);\n    // Removes last element\n    dynarray_rem(\u0026a);\n\n    for(size_t i = 0; i \u003c a.size; i++)\n    {\n        const char* v = dynarray_eget(\u0026a, i);\n        printf(\"%s \", v);\n    }\n\n    dynarray_free(\u0026a);\n    return 0;\n}\n\n// This will print:\n// John Joe Bob\n```\n\n### Deques\n```C\n#include \u003cstdio.h\u003e\n// Allow usage of deques\n#include \"dts2/deque.h\"\n\nint main()\n{\n    deque(float) a = deque_init_new(0);\n\n    deque_add(\u0026a, 12.67);\n    deque_add(\u0026a, 3.789);\n    deque_add(\u0026a, 9002);\n\n    float* p1 = deque_eptr(\u0026a, 1);\n\n    deque_add(\u0026a, 5.59);\n    deque_add(\u0026a, 171);\n    // Remove last element\n    deque_rem(\u0026a);\n\n    // Modify value in deque through pointer\n    *p1 = 666.69;\n\n    for(size_t i = 0; i \u003c a.size; i++)\n    {\n        float v = deque_eget(\u0026a, i);\n        printf(\"%.2f \", v);\n    }\n\n    deque_free(\u0026a);\n    return 0;\n}\n\n// This will print:\n// 12.67 666.69 9002.00 5.59\n```\n\n### Conversion of Data Structures\n```C\n#include \u003cstdio.h\u003e\n\n#include \"dts2/array.h\" // Allow usage of arrays\n#include \"dts2/dynarray.h\" // Allow usage of dynarrays\n#include \"dts2/convert.h\" // Allow usage of conversions\n\nint main()\n{\n    array(char) a = array_init_new(2, char);\n\n    array_eset(\u0026a, 0, 'o');\n    array_eset(\u0026a, 1, 'd');\n\n    dynarray(char) b;\n    // Convert a to dynarray and store it in b\n    dynarray_from_array(\u0026b, \u0026a);\n    \n    dynarray_addat(\u0026b, 0, 'w');\n    dynarray_addat(\u0026b, 2, 'r');\n    dynarray_add(\u0026b, '\\0');\n    \n    // Convert b back to array and store it in a\n    array_from_dynarray(\u0026a, \u0026b);\n\n    printf(\"%s\\n\", a.data);\n    array_free(\u0026a);\n\n    return 0;\n}\n\n// This will print:\n// word\n```\n\n# License\n[MIT](https://choosealicense.com/licenses/mit/)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fporem5002%2Fdts2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fporem5002%2Fdts2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fporem5002%2Fdts2/lists"}