{"id":16126769,"url":"https://github.com/mikolalysenko/inorder-tree-layout","last_synced_at":"2025-03-18T13:31:39.816Z","repository":{"id":7973360,"uuid":"9374616","full_name":"mikolalysenko/inorder-tree-layout","owner":"mikolalysenko","description":"Index calculations for balanced binary search trees in in-order layout","archived":false,"fork":false,"pushed_at":"2014-04-28T23:49:27.000Z","size":176,"stargazers_count":10,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T10:01:10.925Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/mikolalysenko.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}},"created_at":"2013-04-11T16:12:31.000Z","updated_at":"2025-02-06T04:43:59.000Z","dependencies_parsed_at":"2022-09-04T21:01:49.808Z","dependency_job_id":null,"html_url":"https://github.com/mikolalysenko/inorder-tree-layout","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikolalysenko%2Finorder-tree-layout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikolalysenko%2Finorder-tree-layout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikolalysenko%2Finorder-tree-layout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikolalysenko%2Finorder-tree-layout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikolalysenko","download_url":"https://codeload.github.com/mikolalysenko/inorder-tree-layout/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814902,"owners_count":20352038,"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-09T21:40:18.796Z","updated_at":"2025-03-18T13:31:39.559Z","avatar_url":"https://github.com/mikolalysenko.png","language":"JavaScript","readme":"inorder-tree-layout\n===================\nOperations on nodes for balanced binary trees stored in in-order layout.  These are useful if you are building data structures, like binary search trees, implicitly (ie not storing pointers to subtrees).\n\n## Install\n\n    npm install inorder-tree-layout\n    \n## Example\n\nSuppose we have a tree with 10 elements, packed in level order.  Then the inorder labelling of this tree looks like the following picture:\n\n```\nThe tree:\n\n          6\n        /   \\\n       3     8\n      / \\   / \\\n     1   5 7   9\n    / \\  |\n   0   2 4\n\n```\n\nNow given this tree, here is how we can compute some queries using this library:\n\n```javascript\nvar layout = require(\"inorder-tree-layout\")\n\nconsole.log(layout.left(10, 3))     //Prints:  1\n\nconsole.log(layout.parent(10, 7))   //Prints:  8\n\nconsole.log(layout.height(10, 9))   //Prints:  0\n\n```\n\n## API\n\n```javascript\nvar layout = require(\"inorder-tree-layout\")\n```\n\n**Conventions:**\n\n* `n` is always the size of the tree\n* `x` is the index of a node in the tree\n\n### `layout.root(n)`\nReturns the index of the root of a tree of size n.\n\n### `layout.begin(n)`\nReturns the index of the first node of the tree\n\n### `layout.end(n)`\nReturns the index of the last node in the tree\n\n### `layout.height(n, x)`\nReturns the height of node `x` in a tree of size `n`\n\n### `layout.prev(n, x)`\nReturns the predecessor of `x` in an in-order traversal\n\n### `layout.next(n, x)`\nReturns the successor of `x` in an in-order traversal\n\n### `layout.parent(n, x)`\nReturns the parent of `x` in a tree of size `n`\n\n### `layout.left(n, x)`\nReturns the left child of `x`\n\n### `layout.right(n, x)`\nReturns the right child of `x`\n\n### `layout.leaf(n, x)`\nReturns true if `x` is a leaf node.\n\n### `layout.lo(n, x)`\nReturns the left most ancestor of `x` in the tree\n\n### `layout.hi(n, x)`\nReturns the right most ancestor of `x` in the tree\n\n# Credits\n(c) 2013 Mikola Lysenko. MIT License\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikolalysenko%2Finorder-tree-layout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikolalysenko%2Finorder-tree-layout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikolalysenko%2Finorder-tree-layout/lists"}