{"id":16473105,"url":"https://github.com/binki/pebble-v","last_synced_at":"2026-06-05T21:31:45.216Z","repository":{"id":57321680,"uuid":"74237500","full_name":"binki/pebble-v","owner":"binki","description":null,"archived":false,"fork":false,"pushed_at":"2016-11-20T19:57:41.000Z","size":81,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-11T02:19:18.257Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/binki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-19T21:49:07.000Z","updated_at":"2016-11-20T00:25:01.000Z","dependencies_parsed_at":"2022-08-25T22:41:40.579Z","dependency_job_id":null,"html_url":"https://github.com/binki/pebble-v","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binki%2Fpebble-v","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binki%2Fpebble-v/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binki%2Fpebble-v/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binki%2Fpebble-v/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binki","download_url":"https://codeload.github.com/binki/pebble-v/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241110928,"owners_count":19911415,"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":[],"created_at":"2024-10-11T12:25:21.633Z","updated_at":"2025-02-28T06:21:11.832Z","avatar_url":"https://github.com/binki.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/binki/pebble-v.svg?branch=master)](https://travis-ci.org/binki/pebble-v)\n\nSimple C vector library for Pebble.\n\n# Synopsis\n\n    #include \u003cpebble-v/v.h\u003e\n\n# Example\n\n## Variables\n\n    // Define the record we want to store as a struct:\n    typedef struct {\n      int id;\n      const char *name;\n    } Thing;\n    \n    // A thing you want to be able to store in the vector.\n    // It is up to you how exactly you want to store it,\n    // but it is recommended that if you have a seldom-changing\n    // list of data that you store it as a value instead of\n    // storing pointers.\n    Thing thing = {\n      .id = 1,\n      .name = \"Cat\",\n    };\n    \n    // Vector state is stored on the stack. However, you should\n    // treat the contents of the struct as opaque as only the\n    // documented API functions will be preserved as new versions\n    // of the library are released. Note that behavior is undefined\n    // if different units of code access the same vector instance\n    // using different versions of the library.\n    V myVector;\n\n## Initialization\n\n    // We decided to store the record itself rather than a\n    // pointer to it in the vector. Thus, initialize\n    // myVector with that information. Don’t forget to arrange\n    // your code in such a way that you ensure you call\n    // v_deinit() later. Note that you are responsible for\n    // allocating the myVector struct itself. As we are here,\n    // declaring it it as a local is an option. You might also\n    // declare it as a static or global.\n    v_init(\u0026myVector, sizeof(thing));\n\n## Add\n\n    // Add the thing. Copies slice_size bytes (second parameter\n    // of v_init()) pointed to by the second parameter into the\n    // vector. For our case, the contents of thing are now in\n    // the vector.\n    v_add(\u0026myVector, \u0026thing);\n\n## Get\n\n    // You can get an item by index. Here we access the name\n    // of the first item in the vector.\n    const char *name = ((Thing *)v_get(\u0026myVector, 0))-\u003ename;\n\n## Compact\n\n    // This library uses a strategy of increasing the capacity\n    // of the backing array more than necessary each time a call\n    // to v_add() requires more capacity. If you know that the\n    // vector’s size will remaing constant for a while, you\n    // should compact it to reclaim memory. Do this for fairly\n    // static data but do not bother for one-off vectors.\n    v_compact(\u0026myVector);\n\n## Find\n\n    // If you have a strcmp()-like comparer for your struct,\n    // you can use v_find() to find the first match. To find\n    // the position of the thing we inserted earlier, we could\n    // use this (see below for an example thingcmp implementation).\n    int i = v_find(\u0026myVector, thingcmp, \u0026thing);\n    // i is now 0.\n    \n    // If nothing in the vector matches, -1 is returned:\n    thing.id = 2;\n    i = v_find(\u0026myVector, thingcmp, \u0026thing);\n    // i is now -1.\n\n### Comparers\n\nExample of a cmp-like function for `Thing`:\n\n    static int thingcmp(void *a, void *b) {\n      // Leave void * in the function signature to avoid compiler\n      // warnings. If optimizations are on, the next lines should\n      // compile to no-ops.\n      Thing *thingA = a, *thingB = b;\n    \n      if (a-\u003eid != b-\u003eid) {\n        return a-\u003eid - b-\u003eid;\n      }\n      return strcmp(a-\u003ename, b-\u003ename);\n    }\n\nYou may also implement a cmp-like function to search for a particular\nfield. However, mind that the API is documented such that you may not\nassume that the sought item is either a or b, so you must mark that\nyourself in the record or make a case for this being defined\nbehavior. However, for something as simple as searching for a\nparticular record, you do not need to know which of a or b is the\nneedle or the haystack:\n\n    static int thing_name_cmp(void *a, void *b) {\n      Thing *thingA = a, *thingB = b;\n    \n      return strcmp(a-\u003ename, b-\u003ename);\n    }\n\n## Iteration\n\n    // To iterate, simply use a usual for loop with v_count() as\n    // the upper bound and v_get() within the loop body.\n    for (int j = 0; j \u003c v_count(\u0026myVector); j++) {\n      Thing *thingPtr = v_get(\u0026myVector, j);\n      // Do something with thingPtr now…\n    }\n\n## Remove\n\n    // You may remove things from the list at any index.\n    v_remove(\u0026myVector, 0);\n\n## Deinitialization\n\n    // Do not forget to call v_deinit() on each vector when you\n    // are done with it. Note that any resources referenced by\n    // members of the vector are your responsibility. You might\n    // want to use an iteration pattern to clean up individual\n    // entries first.\n    v_deinit(\u0026myVector);\n\n# API\n\nPlease see [`pebble-v/v.h`](include/v.h) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinki%2Fpebble-v","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinki%2Fpebble-v","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinki%2Fpebble-v/lists"}