{"id":16244309,"url":"https://github.com/ralphtheninja/lib-flat-tree","last_synced_at":"2026-02-22T20:01:36.629Z","repository":{"id":66088748,"uuid":"128280034","full_name":"ralphtheninja/lib-flat-tree","owner":"ralphtheninja","description":"Map a binary tree to a list (c version of mafintosh/flat-tree)","archived":false,"fork":false,"pushed_at":"2018-04-07T00:05:59.000Z","size":40,"stargazers_count":3,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-07T20:34:55.078Z","etag":null,"topics":["binary-trees","c"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ralphtheninja.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-04-06T00:35:36.000Z","updated_at":"2023-06-04T06:12:54.000Z","dependencies_parsed_at":"2023-02-20T20:45:59.373Z","dependency_job_id":null,"html_url":"https://github.com/ralphtheninja/lib-flat-tree","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ralphtheninja/lib-flat-tree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralphtheninja%2Flib-flat-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralphtheninja%2Flib-flat-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralphtheninja%2Flib-flat-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralphtheninja%2Flib-flat-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ralphtheninja","download_url":"https://codeload.github.com/ralphtheninja/lib-flat-tree/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralphtheninja%2Flib-flat-tree/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29725289,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-22T19:57:12.410Z","status":"ssl_error","status_checked_at":"2026-02-22T19:54:50.710Z","response_time":110,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["binary-trees","c"],"created_at":"2024-10-10T14:18:31.006Z","updated_at":"2026-02-22T20:01:36.582Z","avatar_url":"https://github.com/ralphtheninja.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lib-flat-tree\n\n\u003e Map a binary tree to a list (c version of [mafintosh/flat-tree]).\n\n[![npm](https://img.shields.io/npm/v/lib-flat-tree.svg)](https://www.npmjs.com/package/lib-flat-tree.h)\n[![Build Status](https://travis-ci.org/ralphtheninja/lib-flat-tree.svg?branch=master)](https://travis-ci.org/ralphtheninja/lib-flat-tree)\n\n## Usage\n\n```c\n#include \u003clibflattree.h\u003e\n\nint main(void)\n{\n  printf(\"index: %ld\\n\", lft_index(3, 1));\n  printf(\"parent: %ld\\n\", lft_parent(5));\n  return 0;\n}\n```\n\nOutputs:\n\n```\nindex: 23\nparent: 3\n```\n\n## API\n\nThe functions below ending with a `_2` takes a pre computed `depth` parameter. Since calculating `depth` is an iterative process, these functions are an optimization to avoid having to re-calculate `depth`.\n\n### `int64_t lft_index(int64_t depth, int64_t offset);`\n\nReturns an array index for the tree element at the given depth and offset.\n\n### `int64_t lft_depth(int64_t index);`\n\nReturns the depth of an element.\n\n### `int64_t lft_offset(int64_t index);`\n\nReturns the relative offset of an element.\n\n### `int64_t lft_offset_2(int64_t index, int64_t depth);`\n\nAs above but with pre computed depth.\n\n### `int64_t lft_sibling(int64_t index);`\n\nReturns the index of this elements sibling.\n\n### `int64_t lft_sibling_2(int64_t index, int64_t depth);`\n\nAs above but with pre computed depth.\n\n### `int64_t lft_parent(int64_t index);`\n\nReturns the index of the parent element.\n\n### `int64_t lft_parent_2(int64_t index, int64_t depth);`\n\nAs above but with pre computed depth.\n\n### `int64_t lft_left_child(int64_t index);`\n\nReturns the index of the left child. Returns `-1` if `index` is even, i.e. if the element is a leaf.\n\n### `int64_t lft_left_child_2(int64_t index, int64_t depth);`\n\nAs above but with pre computed depth.\n\n### `int64_t lft_right_child(int64_t index);`\n\nReturns the index of the right child. Returns `-1` if `index` is even, i.e. if the element is a leaf.\n\n### `int64_t lft_right_child_2(int64_t index, int64_t depth);`\n\nAs above but with pre computed depth.\n\n### `int64_t lft_left_span(int64_t index);`\n\nReturns the left spanning index in the tree `index` spans.\n\n### `int64_t lft_left_span_2(int64_t index, int64_t depth);`\n\nAs above but with pre computed depth.\n\n### `int64_t lft_right_span(int64_t index);`\n\nReturns the right spanning index in the tree `index` spans.\n\n### `int64_t lft_right_span_2(int64_t index, int64_t depth);`\n\nAs above but with pre computed depth.\n\n### `lft_iterator* lft_iterator_create(int64_t index);`\n\nCreate an iterator starting at `index`.\n\nThe `lft_iterator*` is dynamically allocated so you need to call `free()` when you're done using it.\n\n### `void lft_iterator_seek(lft_iterator* it, int64_t index);`\n\nMove the iterator to `index`.\n\n### `int64_t lft_iterator_is_left(lft_iterator* it);`\n\nReturns `1` if the iterator is at a left sibling, otherwise `0`.\n\n### `int64_t lft_iterator_is_right(lft_iterator* it);`\n\nReturns `1` if the iterator is at a right sibling, otherwise `0`.\n\n### `int64_t lft_iterator_prev(lft_iterator* it);`\n\nMove the iterator to the previous item in the tree. Returns current `index` if `offset` is `0`.\n\n### `int64_t lft_iterator_next(lft_iterator* it);`\n\nMove the iterator to the next item in the tree.\n\n### `int64_t lft_iterator_sibling(lft_iterator* it);`\n\nMove the iterator to the current sibling index.\n\n### `int64_t lft_iterator_parent(lft_iterator* it);`\n\nMove the iterator to the current parent index.\n\n### `int64_t lft_iterator_left_span(lft_iterator* it);`\n\nMove the iterator to the current left span index.\n\n### `int64_t lft_iterator_right_span(lft_iterator* it);`\n\nMove the iterator to the current right span index.\n\n### `int64_t lft_iterator_left_child(lft_iterator* it);`\n\nMove the iterator to the current left child index.\n\n### `int64_t lft_iterator_right_child(lft_iterator* it);`\n\nMove the iterator to the current right child index.\n\n## Also see\n\n- [mafintosh/flat-tree]: Original node module\n- [datrs/flat-tree]: A port of the node module to rust\n- [bcomnes/flattree]: A port of the node module to Go\n\n## License\n\nMIT\n\n[mafintosh/flat-tree]: https://github.com/mafintosh/flat-tree\n[datrs/flat-tree]: https://github.com/datrs/flat-tree\n[bcomnes/flattree]: https://github.com/bcomnes/flattree\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fralphtheninja%2Flib-flat-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fralphtheninja%2Flib-flat-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fralphtheninja%2Flib-flat-tree/lists"}