{"id":15497281,"url":"https://github.com/jwerle/doublelist","last_synced_at":"2025-03-14T03:17:54.637Z","repository":{"id":148540504,"uuid":"272249407","full_name":"jwerle/doublelist","owner":"jwerle","description":"A doubly linked list suitable for stack allocation.","archived":false,"fork":false,"pushed_at":"2020-11-07T16:10:19.000Z","size":21,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-17T01:08:53.040Z","etag":null,"topics":["doubly-linked-list","list","zz"],"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/jwerle.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-06-14T17:19:40.000Z","updated_at":"2021-02-05T22:50:57.000Z","dependencies_parsed_at":"2023-05-20T11:15:31.732Z","dependency_job_id":null,"html_url":"https://github.com/jwerle/doublelist","commit_stats":{"total_commits":9,"total_committers":2,"mean_commits":4.5,"dds":"0.11111111111111116","last_synced_commit":"1c608533ad4a514da7b5dbd24c38eeac3edd6f69"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fdoublelist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fdoublelist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fdoublelist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fdoublelist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwerle","download_url":"https://codeload.github.com/jwerle/doublelist/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243515525,"owners_count":20303258,"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":["doubly-linked-list","list","zz"],"created_at":"2024-10-02T08:32:28.838Z","updated_at":"2025-03-14T03:17:54.612Z","avatar_url":"https://github.com/jwerle.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"doublelist\n==========\n\n\u003e A doubly linked list suitable for stack allocation.\n\n## Installation\n\nAdd this to `zz.toml`:\n\n```toml\n[dependencies]\ndoublelist = \"*\"\n\n[repos]\ndoublelist = \"git://github.com/jwerle/doublelist\"\n```\n\n## Usage\n\n```c++\nusing doublelist\nusing log\n\nfn main () -\u003e int {\n  // allocate a new mutable list with tail size of 2 (the number of possible elements)\n  new+2 mut items = doublelist::make();\n\n  items.push(\"hello\");\n  items.push(\"world\");\n\n  // get an iterator to the list\n  let mut it = items.iterator();\n  while !it.ended {\n    let node = it.next();\n    log::info(\"%s\", node);\n  }\n\n  return 0;\n}\n```\n\n## API\n\n### List\n\nA doubly linked list suitable for stack allocation.\n\n#### `new+tail l = doublelist::make()`\n\n`List` constructor. Initializes a `List` pointer.\n\n```c++\nnew+4 items = doublelist::make();\n```\n\n#### `node = l.rpush(value)`\n\nPushes a value to the right of the list updating the tail returning the\nnewly created list node.\n\n```c++\nlet hello = l.rpush(\"hello\");\nlet world = l.rpush(\"world\");\n```\n\n_See the [Node API](#node) for more information about list nodes._\n\n#### `node = l.lpush(value)`\n\nPushes a value to the left of the list updating the head returning the\nnewly created list node.\n\n```c++\nlet world = l.lpush(\"world\");\nlet hello = l.lpush(\"hello\");\n```\n\n_See the [Node API](#node) for more information about list nodes._\n\n#### `value = l.rpop()`\n\nPops a value from the tail of the list.\n\n```c++\nlet value = l.rpop();\n```\n\n#### `value = l.lpop()`\n\nPops a value from the head of the list.\n\n```c++\nlet value = l.lpop();\n```\n\n#### `l.push(value)`\n\nAn alias for `l.rpush(value)`.\n\n```c++\nl.push(value);\n```\n\n#### `l.unshift(value)`\n\nAn alias for `l.lpush(value)`.\n\n```c++\nl.unshift(value);\n```\n\n#### `l.pop()`\n\nAn alias for `l.rpop()`.\n\n```c++\nlet value = l.pop();\n```\n\n#### `l.shift()`\n\nAn alias for `l.lpop()`.\n\n```c++\nlet value = l.shift();\n```\n\n#### `it = l.iterator()`\n\nCreates and returns a stack allocated [iterator](#iterator) for a list instance\nin the default iterator direction.\n\n```c++\nlet it = l.iterator();\n```\n\n_See the [Iterator API](#iterator) for more information about list iterators._\n\n#### `it = l.iterator_head()`\n\nCreates and returns a stack allocated [iterator](#iterator]) for a list instance\nin the \"head\" direction.\n\n```c++\nlet it = list.iterator_head();\n```\n\n_See the [Iterator API](#iterator) for more information about list iterators._\n\n#### `it = l.iterator_tail()`\n\nCreates and returns a stack allocated iterator for a list instance\nin the \"tail\" direction.\n\n```c++\nlet it = list.iterator_tail();\n```\n\n_See the [Iterator API](#iterator) for more information about list iterators._\n\n#### `it = l.iterator_tail(direction)`\n\nCreates and returns a stack allocated iterator for a list instance\nin a given direction.\n\n```c++\nlet it = list.iterator_with_direction(doublelist::HEAD); // default\n// or\nlet it = list.iterator_with_direction(doublelist::TAIL);\n```\n\n_See the [Iterator API](#iterator) for more information about list iterators._\n\n#### `node = l.find(value)`\n\nFinds and returns a list node that points to a value that matches the given\nvalue pointer. A user supplied comparator function can be used by setting\n`l.compare` to a `CompareNodeValueFunction(void a*, void *b) -\u003e bool` type,\notherwise simple pointer comparison is used by default.\n\n```c++\nlet node = l.find(\"hello\");\n```\n\n#### `node = l.at(index)`\n\nFinds and returns the list node at a given index.\n\n```c++\nl.rpush(\"hello\");\nl.rpush(\"world\");\nlet node = l.at(1);\n\nstatic_attest(safe(node));\nlog::info(\"%s\", node-\u003evalue);\n```\n\n#### `l.remove(value)`\n\nFinds a list node that points to a given value and removes it from the list.\n\n```c++\nlist.rpush(\"hello\");\nlist.rpush(\"world\");\nlist.remove(\"world\");\n```\n\n#### `l.contains(value)`\n\nReturns a boolean indicating if a list contains a value.\n\n```c++\nl.push(\"hello\");\n\nif l.contains(\"hello\") {\n  l.push(\"world\");\n}\n```\n\n#### `size = l.slice(values, offset, count)`\n\nTake a slice from the list at a depth offset.\n\n```c++\nvoid * mut values[2];\n\nl.push(\"hello\");\nl.push(\"world\");\nl.slice(values, 0, 2);\n\nlog::info(\"%s %s\", values[0], values[1]);\n```\n\n#### `i = l.index(value)`\n\nCompute the index of a node's value and return it. If not found, then -1 is returned.\n-1 is also returned if a compare function is not found.\n\n```c++\nnew+2 l = doublelist::make();\n\nl.push(\"hello\");\nl.push(\"world\");\n\nassert(0 == l.index(\"hello\"));\nassert(1 == l.index(\"world\"));\n```\n\n### Iterator\n\nAn iterator context for a list.\n\n#### `new it = doublelist::iterator::make(list, direction)`\n\n`Iterator` stack constructor with direction from a list. Initializes a\n`Iterator` pointer with a `List` pointer and `direction`. Typically, you\nwill never need to call this function.\n\n#### `it.ended`\n\nA boolean that is set to `true` when the iterator has reach the end of\nthe list after subsequent calls to `it.next()`.\n\n#### `it.direction`\n\nThe direction in which the iterator will traverse the list. See\n[Iterator Directions](#iterator-directions) for more information on this\nvalue.\n\n#### `node = it.next()`\n\nReturns a pointer to the next node in the list. This function will set\n`it.ended = true` when it has reach the end of the list.\n\n```c+++\nlet it = l.iterator();\nwhile !it.ended {\n  let node = it.next();\n}\n```\n\n#### `it.seek(node)`\n\nSeeks the iterator to the node.\n\n```c++\nit.seek(l.at(l.index(\"foo\")));\n```\n\n#### `it.end()`\n\nMarks the iterator as \"ended\". This will set `it.ended = true` and\nremove a reference to any nodes in the list.\n\n#### Iterator Directions\n\nIterators can traverse a list in the `doublelist::HEAD`\n(`doublelist::iterator::Direction::Head`) or `doublelist::TAIL`\n(`doublelist::iterator::Direction::Tail`) directions.\n\n### Node\n\nA node structure to contain pointers to a list node's value,\ncontaining List structure, and next/prev nodes.\n\n#### `node.value`\n\nA pointer to the value this node points to.\n\n#### `node.next`\n\nA pointer to the next node in the list.\n\n#### `node.prev`\n\nA pointer to the previous node in the list.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwerle%2Fdoublelist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwerle%2Fdoublelist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwerle%2Fdoublelist/lists"}