Returns a list of all the full roots (subtrees where all nodes have either 2 or 0 children) < index.
+For example full_roots(8) returns [3] since the subtree rooted at 3 spans 0 -> 6 and the tree rooted
+at 7 has a child located at 9 which is >= 8.
You can represent a binary tree in a simple flat list using the following structure
+
+
3
+ 15
+0246 ...
+
+
This module exposes a series of functions to help you build and maintain this data structure
+
+
require "flat_tree"
+
+list = [] of String
+
+i = FlatTree.index(0_u64, 0_u64) # get array index for depth: 0, offset: 0
+j = FlatTree.index(1_u64, 0_u64) # get array index for depth: 1, offset: 0
+
+# use these indexes to store some data
+
+list[i] = 'a'
+list[j] = 'b'
+list[FlatTree.parent(i)] = 'parent of a and b'
+
+
diff --git a/index.json b/index.json
new file mode 100644
index 0000000..89a3fb5
--- /dev/null
+++ b/index.json
@@ -0,0 +1 @@
+{"repository_name":"flat_tree","body":"# flat_tree\n\n[![Build Status](https://travis-ci.com/dukeraphaelng/flat_tree.svg?branch=master)](https://travis-ci.com/dukeraphaelng/flat_tree) [![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://dukeraphaelng.github.io/flat_tree/) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/dukeraphaelng/flat_tree)](https://img.shields.io/github/v/release/dukeraphaelng/flat_tree?style=flat-square)\n\nMap a binary tree to a vector. Port of [mafintosh/flat-tree](https://github.com/mafintosh/flat-tree)\n\n- [Documentation](https://dukeraphaelng.github.io/flat_tree/)\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n ```yaml\n dependencies:\n flat_tree:\n github: dukeraphaelng/flat_tree\n ```\n\n2. Run `shards install`\n\n## Usage\n\nYou can represent a binary tree in a simple flat list using the following structure\n\n```\n 3\n 1 5\n0 2 4 6 ...\n```\n\nThis module exposes a series of functions to help you build and maintain this data structure\n\n```crystal\nrequire \"flat_tree\"\n\nlist = [] of String\n\ni = FlatTree.index(0_u64, 0_u64) # get array index for depth: 0, offset: 0\nj = FlatTree.index(1_u64, 0_u64) # get array index for depth: 1, offset: 0\n\n# use these indexes to store some data\n\nlist[i] = 'a'\nlist[j] = 'b'\nlist[FlatTree.parent(i)] = 'parent of a and b'\n```\n\n## Contributing\n\n1. Fork it ()\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n - This repository follows [Conventional Commits](http://conventionalcommits.org)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [Duke Nguyen](https://github.com/dukeraphaelng) - creator and maintainer\n\n## License\n\n- [MIT](LICENSE)","program":{"html_id":"flat_tree/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"flat_tree","program":true,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"flat_tree/FlatTree","path":"FlatTree.html","kind":"module","full_name":"FlatTree","name":"FlatTree","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/flat_tree.cr","line_number":13,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L13"},{"filename":"src/iterator.cr","line_number":1,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L1"}],"repository_name":"flat_tree","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[{"html_id":"flat_tree/FlatTree","kind":"module","full_name":"FlatTree","name":"FlatTree"}],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[{"id":"children(i:UInt64,d:UInt64?=self.depth(i)):Array(UInt64)?-instance-method","html_id":"children(i:UInt64,d:UInt64?=self.depth(i)):Array(UInt64)?-instance-method","name":"children","doc":"Returns an array [left_child, right_child] with the indexes of this elements children.\nIf this element does not have any children it returns null","summary":"
Returns an array [left_child, right_child] with the indexes of this elements children.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64, d : UInt64? = self.depth(i)) : Array(UInt64)?","args_html":"(i : UInt64, d : UInt64? = self.depth(i)) : Array(UInt64)?","location":{"filename":"src/flat_tree.cr","line_number":76,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L76"},"def":{"name":"children","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Array(UInt64) | Nil","visibility":"Public","body":"if i.even?\n return nil\nend\no = (self.offset(i, d)) * 2_u64\n[index(d - 1_u64, o), index(d - 1_u64, o + 1_u64)]\n"}},{"id":"count(i:UInt64,d:UInt64?=self.depth(i))-instance-method","html_id":"count(i:UInt64,d:UInt64?=self.depth(i))-instance-method","name":"count","doc":"Returns how many nodes (including parent nodes) a tree contains","summary":"
Returns how many nodes (including parent nodes) a tree contains
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64, d : UInt64? = self.depth(i))","args_html":"(i : UInt64, d : UInt64? = self.depth(i))","location":{"filename":"src/flat_tree.cr","line_number":100,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L100"},"def":{"name":"count","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(2 << d) - 1_u64"}},{"id":"depth(i:UInt64?):UInt64-instance-method","html_id":"depth(i:UInt64?):UInt64-instance-method","name":"depth","doc":"Returns the depth of an element","summary":"
Returns the depth of an element
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64?) : UInt64","args_html":"(i : UInt64?) : UInt64","location":{"filename":"src/flat_tree.cr","line_number":41,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L41"},"def":{"name":"depth","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"UInt64","visibility":"Public","body":"if i.nil?\n return 0_u64\nend\n(~(BigInt.new(i))).trailing_zeros_count.to_u64\n"}},{"id":"full_roots(i:UInt64,nodes:Array(UInt64)=[]ofUInt64)-instance-method","html_id":"full_roots(i:UInt64,nodes:Array(UInt64)=[]ofUInt64)-instance-method","name":"full_roots","doc":"Returns a list of all the full roots (subtrees where all nodes have either 2 or 0 children) < index.\nFor example full_roots(8) returns [3] since the subtree rooted at 3 spans 0 -> 6 and the tree rooted\nat 7 has a child located at 9 which is >= 8.","summary":"
Returns a list of all the full roots (subtrees where all nodes have either 2 or 0 children) < index.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"nodes","doc":null,"default_value":"[] of UInt64","external_name":"nodes","restriction":"Array(UInt64)"}],"args_string":"(i : UInt64, nodes : Array(UInt64) = []ofUInt64)","args_html":"(i : UInt64, nodes : Array(UInt64) = []ofUInt64)","location":{"filename":"src/flat_tree.cr","line_number":19,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L19"},"def":{"name":"full_roots","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"nodes","doc":null,"default_value":"[] of UInt64","external_name":"nodes","restriction":"Array(UInt64)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if i.even?\nelse\n raise(ArgumentError.new(\"You can only look up roots for depth 0 blocks, got index #{i}\"))\nend\ntmp = i >> 1\no = 0_u64\nfactor = 1_u64\nwhile tmp != 0_u64\n while (factor * 2_u64) <= tmp\n factor = factor * 2_u64\n end\n nodes.push((o + factor) - 1_u64)\n o = o + (2_u64 * factor)\n tmp = tmp - factor\n factor = 1_u64\nend\nnodes\n"}},{"id":"index(d:UInt64,o:UInt64):UInt64-instance-method","html_id":"index(d:UInt64,o:UInt64):UInt64-instance-method","name":"index","doc":"Returns an array index for the tree element at the given depth and offset","summary":"
Returns an array index for the tree element at the given depth and offset
","abstract":false,"args":[{"name":"d","doc":null,"default_value":"","external_name":"d","restriction":"UInt64"},{"name":"o","doc":null,"default_value":"","external_name":"o","restriction":"UInt64"}],"args_string":"(d : UInt64, o : UInt64) : UInt64","args_html":"(d : UInt64, o : UInt64) : UInt64","location":{"filename":"src/flat_tree.cr","line_number":115,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L115"},"def":{"name":"index","args":[{"name":"d","doc":null,"default_value":"","external_name":"d","restriction":"UInt64"},{"name":"o","doc":null,"default_value":"","external_name":"o","restriction":"UInt64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"UInt64","visibility":"Public","body":"(((1_u64 + (2_u64 * o)) * (two_pow(d))) - 1_u64).to_u64"}},{"id":"iterator(i:UInt64=0_u64)-instance-method","html_id":"iterator(i:UInt64=0_u64)-instance-method","name":"iterator","doc":"Create a stateful tree iterator starting at a given index. The iterator exposes the following methods.","summary":"
Create a stateful tree iterator starting at a given index.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"0_u64","external_name":"i","restriction":"UInt64"}],"args_string":"(i : UInt64 = 0_u64)","args_html":"(i : UInt64 = 0_u64)","location":{"filename":"src/flat_tree.cr","line_number":126,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L126"},"def":{"name":"iterator","args":[{"name":"i","doc":null,"default_value":"0_u64","external_name":"i","restriction":"UInt64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Iterator.new(i)"}},{"id":"left_child(i:UInt64?,d:UInt64?=self.depth(i)):UInt64?-instance-method","html_id":"left_child(i:UInt64?,d:UInt64?=self.depth(i)):UInt64?-instance-method","name":"left_child","doc":"Returns only the left child of a node.","summary":"
Returns only the left child of a node.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64 | Nil"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64?, d : UInt64? = self.depth(i)) : UInt64?","args_html":"(i : UInt64?, d : UInt64? = self.depth(i)) : UInt64?","location":{"filename":"src/flat_tree.cr","line_number":57,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L57"},"def":{"name":"left_child","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64 | Nil"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"UInt64 | Nil","visibility":"Public","body":"if i.nil? || (i.as(UInt64)).even?\n return nil\nend\ni = i.as(UInt64)\nif d == 0\n return i\nend\nself.index(d - 1_u64, (self.offset(i, d)) << 1)\n"}},{"id":"left_span(i:UInt64,d:UInt64?=self.depth(i))-instance-method","html_id":"left_span(i:UInt64,d:UInt64?=self.depth(i))-instance-method","name":"left_span","doc":"Returns the left spanning in index in the tree index spans.","summary":"
Returns the left spanning in index in the tree index spans.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64, d : UInt64? = self.depth(i))","args_html":"(i : UInt64, d : UInt64? = self.depth(i))","location":{"filename":"src/flat_tree.cr","line_number":88,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L88"},"def":{"name":"left_span","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if i == 0\n return i\nend\n(offset(i, d)) * (2_u64 << d)\n"}},{"id":"offset(i:UInt64,d:UInt64?=self.depth(i)):UInt64-instance-method","html_id":"offset(i:UInt64,d:UInt64?=self.depth(i)):UInt64-instance-method","name":"offset","doc":"Returns the relative offset of an element","summary":"
Returns the relative offset of an element
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64, d : UInt64? = self.depth(i)) : UInt64","args_html":"(i : UInt64, d : UInt64? = self.depth(i)) : UInt64","location":{"filename":"src/flat_tree.cr","line_number":120,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L120"},"def":{"name":"offset","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"UInt64","visibility":"Public","body":"if i.even?\n return (i / 2_u64).to_u64\nend\ni >> (d + 1)\n"}},{"id":"parent(i:UInt64,d:UInt64?=self.depth(i)):UInt64-instance-method","html_id":"parent(i:UInt64,d:UInt64?=self.depth(i)):UInt64-instance-method","name":"parent","doc":"Returns the index of the parent element in tree","summary":"
Returns the index of the parent element in tree
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64, d : UInt64? = self.depth(i)) : UInt64","args_html":"(i : UInt64, d : UInt64? = self.depth(i)) : UInt64","location":{"filename":"src/flat_tree.cr","line_number":52,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L52"},"def":{"name":"parent","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"UInt64","visibility":"Public","body":"self.index(d + 1_u64, (self.offset(i, d)) >> 1_u64)"}},{"id":"right_child(i:UInt64?,d:UInt64?=self.depth(i)):UInt64?-instance-method","html_id":"right_child(i:UInt64?,d:UInt64?=self.depth(i)):UInt64?-instance-method","name":"right_child","doc":"Returns only the right child of a node.","summary":"
Returns only the right child of a node.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64 | Nil"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64?, d : UInt64? = self.depth(i)) : UInt64?","args_html":"(i : UInt64?, d : UInt64? = self.depth(i)) : UInt64?","location":{"filename":"src/flat_tree.cr","line_number":66,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L66"},"def":{"name":"right_child","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64 | Nil"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"UInt64 | Nil","visibility":"Public","body":"if i.nil? || (i.as(UInt64)).even?\n return nil\nend\ni = i.as(UInt64)\nif d == 0_u64\n return i\nend\nself.index(d - 1, (1 + ((self.offset(i, d)) << 1)).to_u64)\n"}},{"id":"right_span(i:UInt64,d:UInt64?=self.depth(i))-instance-method","html_id":"right_span(i:UInt64,d:UInt64?=self.depth(i))-instance-method","name":"right_span","doc":"Returns the right spanning in index in the tree index spans.","summary":"
Returns the right spanning in index in the tree index spans.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64, d : UInt64? = self.depth(i))","args_html":"(i : UInt64, d : UInt64? = self.depth(i))","location":{"filename":"src/flat_tree.cr","line_number":94,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L94"},"def":{"name":"right_span","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if i.even?\n return i\nend\n(((offset(i, d)) + 1_u64) * (2_u64 << d)) - 2_u64\n"}},{"id":"sibling(i:UInt64,d:UInt64?=self.depth(i))-instance-method","html_id":"sibling(i:UInt64,d:UInt64?=self.depth(i))-instance-method","name":"sibling","doc":"Returns the index of this elements sibling","summary":"
Returns the index of this elements sibling
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64, d : UInt64? = self.depth(i))","args_html":"(i : UInt64, d : UInt64? = self.depth(i))","location":{"filename":"src/flat_tree.cr","line_number":47,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L47"},"def":{"name":"sibling","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self.index(d, (self.offset(i, d)) ^ 1)"}},{"id":"spans(i:UInt64,d:UInt64?=self.depth(i))-instance-method","html_id":"spans(i:UInt64,d:UInt64?=self.depth(i))-instance-method","name":"spans","doc":"Returns the range (inclusive) the tree root at index spans.\nFor example FlatTree.spans(3) would return [0, 6] (see the usage example).","summary":"
Returns the range (inclusive) the tree root at index spans.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":22,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L22"},"def":{"name":"is_left","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@offset.even?"}},{"id":"is_right-instance-method","html_id":"is_right-instance-method","name":"is_right","doc":"Is the iterator at a right sibling?","summary":"
Is the iterator at a right sibling?
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":27,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L27"},"def":{"name":"is_right","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@offset.odd?"}},{"id":"left_child-instance-method","html_id":"left_child-instance-method","name":"left_child","doc":"Move the iterator to the current left child index.","summary":"
Move the iterator to the current left child index.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":86,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L86"},"def":{"name":"left_child","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @factor == 2_u64\n return @index\nend\n@factor = (@factor / 2_u64).to_u64\n@index = (@index - (@factor / 2_u64)).to_u64\n@offset = @offset * 2_u64\n@index\n"}},{"id":"left_span-instance-method","html_id":"left_span-instance-method","name":"left_span","doc":"Move the iterator to the current left span index.","summary":"
Move the iterator to the current left span index.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":70,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L70"},"def":{"name":"left_span","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@index = (@index - (@factor / 2_u64).to_u64) + 1_u64\n@offset = (@index / 2_u64).to_u64\n@factor = 2_u64\n@index\n"}},{"id":"next-instance-method","html_id":"next-instance-method","name":"next","doc":"Move the iterator the next item in the tree.","summary":"
Move the iterator the next item in the tree.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":45,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L45"},"def":{"name":"next","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@offset = @offset + 1_u64\n@index = @index + @factor\n@index\n"}},{"id":"next_tree-instance-method","html_id":"next_tree-instance-method","name":"next_tree","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":103,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L103"},"def":{"name":"next_tree","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@index = @index + ((@factor / 2_u64).to_u64 + 1_u64)\n@offset = (@index / 2_u64).to_u64\n@factor = 2_u64\n@index\n"}},{"id":"offset:UInt64-instance-method","html_id":"offset:UInt64-instance-method","name":"offset","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : UInt64","args_html":" : UInt64","location":{"filename":"src/iterator.cr","line_number":3,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L3"},"def":{"name":"offset","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"UInt64","visibility":"Public","body":"@offset"}},{"id":"offset=(offset:UInt64)-instance-method","html_id":"offset=(offset:UInt64)-instance-method","name":"offset=","doc":null,"summary":null,"abstract":false,"args":[{"name":"offset","doc":null,"default_value":"","external_name":"offset","restriction":"UInt64"}],"args_string":"(offset : UInt64)","args_html":"(offset : UInt64)","location":{"filename":"src/iterator.cr","line_number":3,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L3"},"def":{"name":"offset=","args":[{"name":"offset","doc":null,"default_value":"","external_name":"offset","restriction":"UInt64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@offset = offset"}},{"id":"parent-instance-method","html_id":"parent-instance-method","name":"parent","doc":"Move the iterator to the current parent index","summary":"
Move the iterator to the current parent index
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":57,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L57"},"def":{"name":"parent","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @offset.odd?\n @index = @index - (@factor / 2_u64).to_u64\n @offset = ((@offset - 1_u64) / 2_u64).to_u64\nelse\n @index = @index + (@factor / 2_u64).to_u64\n @offset = (@offset / 2_u64).to_u64\nend\n@factor = @factor * 2_u64\n@index\n"}},{"id":"prev-instance-method","html_id":"prev-instance-method","name":"prev","doc":"Move the iterator the prev item in the tree.","summary":"
Move the iterator the prev item in the tree.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":37,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L37"},"def":{"name":"prev","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @offset == 0\n return @index\nend\n@offset = @offset - 1_u64\n@index = @index - @factor\n@index\n"}},{"id":"prev_tree-instance-method","html_id":"prev_tree-instance-method","name":"prev_tree","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":110,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L110"},"def":{"name":"prev_tree","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @offset\n @index = @index - ((@factor / 2_u64).to_u64 - 1_u64)\n @offset = (@index / 2_u64).to_u64\n @factor = 2_u64\nelse\n @index = 0_u64\n @factor = 2_u64\nend\n@index\n"}},{"id":"right_child-instance-method","html_id":"right_child-instance-method","name":"right_child","doc":"Move the iterator to the current right child index.","summary":"
Move the iterator to the current right child index.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":95,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L95"},"def":{"name":"right_child","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @factor == 2_u64\n return @index\nend\n@factor = (@factor / 2_u64).to_u64\n@index = (@index + (@factor / 2_u64)).to_u64\n@offset = (2_u64 * @offset) + 1_u64\n@index\n"}},{"id":"right_span-instance-method","html_id":"right_span-instance-method","name":"right_span","doc":"Move the iterator to the current right span index.","summary":"
Move the iterator to the current right span index.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":78,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L78"},"def":{"name":"right_span","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@index = @index + ((@factor / 2_u64) - 1_u64)\n@offset = (@index / 2_u64).to_u64\n@factor = 2_u64\n@index\n"}},{"id":"seek(i:UInt64)-instance-method","html_id":"seek(i:UInt64)-instance-method","name":"seek","doc":"Move the iterator the this specific tree index.","summary":"
Move the iterator the this specific tree index.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"}],"args_string":"(i : UInt64)","args_html":"(i : UInt64)","location":{"filename":"src/iterator.cr","line_number":12,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L12"},"def":{"name":"seek","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@index = i\n@offset, @factor = if (@index & 1_u64)\n {::FlatTree.offset(i), ::FlatTree.two_pow((::FlatTree.depth(i)) + 1_u64)}\nelse\n {(@index / 2_u64).to_u64, 2_u64}\nend\n"}},{"id":"sibling-instance-method","html_id":"sibling-instance-method","name":"sibling","doc":"Move the iterator to the current sibling","summary":"
'
+ );
+
+ function handleShortkeys(event) {
+ var element = event.target || event.srcElement;
+
+ if(element.tagName == "INPUT" || element.tagName == "TEXTAREA" || element.parentElement.tagName == "TEXTAREA"){
+ return;
+ }
+
+ switch(event.key) {
+ case "?":
+ usageModal.show();
+ break;
+
+ case "Escape":
+ usageModal.hide();
+ break;
+
+ case "s":
+ case "/":
+ if(usageModal.isVisible()) {
+ return;
+ }
+ event.stopPropagation();
+ navigator.focus();
+ performSearch();
+ break;
+ }
+ }
+
+ document.addEventListener('keyup', handleShortkeys);
+
+ var scrollToEntryFromLocationHash = function() {
+ var hash = window.location.hash;
+ if (hash) {
+ var targetAnchor = decodeURI(hash.substr(1));
+ var targetEl = document.getElementById(targetAnchor)
+ if (targetEl) {
+ targetEl.offsetParent.scrollTop = targetEl.offsetTop;
+ }
+ }
+ };
+ window.addEventListener("hashchange", scrollToEntryFromLocationHash, false);
+ scrollToEntryFromLocationHash();
+});
diff --git a/search-index.js b/search-index.js
new file mode 100644
index 0000000..bba5cf5
--- /dev/null
+++ b/search-index.js
@@ -0,0 +1 @@
+crystal_doc_search_index_callback({"repository_name":"flat_tree","body":"# flat_tree\n\n[![Build Status](https://travis-ci.com/dukeraphaelng/flat_tree.svg?branch=master)](https://travis-ci.com/dukeraphaelng/flat_tree) [![Docs](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://dukeraphaelng.github.io/flat_tree/) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/dukeraphaelng/flat_tree)](https://img.shields.io/github/v/release/dukeraphaelng/flat_tree?style=flat-square)\n\nMap a binary tree to a vector. Port of [mafintosh/flat-tree](https://github.com/mafintosh/flat-tree)\n\n- [Documentation](https://dukeraphaelng.github.io/flat_tree/)\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n ```yaml\n dependencies:\n flat_tree:\n github: dukeraphaelng/flat_tree\n ```\n\n2. Run `shards install`\n\n## Usage\n\nYou can represent a binary tree in a simple flat list using the following structure\n\n```\n 3\n 1 5\n0 2 4 6 ...\n```\n\nThis module exposes a series of functions to help you build and maintain this data structure\n\n```crystal\nrequire \"flat_tree\"\n\nlist = [] of String\n\ni = FlatTree.index(0_u64, 0_u64) # get array index for depth: 0, offset: 0\nj = FlatTree.index(1_u64, 0_u64) # get array index for depth: 1, offset: 0\n\n# use these indexes to store some data\n\nlist[i] = 'a'\nlist[j] = 'b'\nlist[FlatTree.parent(i)] = 'parent of a and b'\n```\n\n## Contributing\n\n1. Fork it ()\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n - This repository follows [Conventional Commits](http://conventionalcommits.org)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [Duke Nguyen](https://github.com/dukeraphaelng) - creator and maintainer\n\n## License\n\n- [MIT](LICENSE)","program":{"html_id":"flat_tree/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"flat_tree","program":true,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"flat_tree/FlatTree","path":"FlatTree.html","kind":"module","full_name":"FlatTree","name":"FlatTree","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/flat_tree.cr","line_number":13,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L13"},{"filename":"src/iterator.cr","line_number":1,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L1"}],"repository_name":"flat_tree","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[{"html_id":"flat_tree/FlatTree","kind":"module","full_name":"FlatTree","name":"FlatTree"}],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[{"id":"children(i:UInt64,d:UInt64?=self.depth(i)):Array(UInt64)?-instance-method","html_id":"children(i:UInt64,d:UInt64?=self.depth(i)):Array(UInt64)?-instance-method","name":"children","doc":"Returns an array [left_child, right_child] with the indexes of this elements children.\nIf this element does not have any children it returns null","summary":"
Returns an array [left_child, right_child] with the indexes of this elements children.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64, d : UInt64? = self.depth(i)) : Array(UInt64)?","args_html":"(i : UInt64, d : UInt64? = self.depth(i)) : Array(UInt64)?","location":{"filename":"src/flat_tree.cr","line_number":76,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L76"},"def":{"name":"children","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Array(UInt64) | Nil","visibility":"Public","body":"if i.even?\n return nil\nend\no = (self.offset(i, d)) * 2_u64\n[index(d - 1_u64, o), index(d - 1_u64, o + 1_u64)]\n"}},{"id":"count(i:UInt64,d:UInt64?=self.depth(i))-instance-method","html_id":"count(i:UInt64,d:UInt64?=self.depth(i))-instance-method","name":"count","doc":"Returns how many nodes (including parent nodes) a tree contains","summary":"
Returns how many nodes (including parent nodes) a tree contains
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64, d : UInt64? = self.depth(i))","args_html":"(i : UInt64, d : UInt64? = self.depth(i))","location":{"filename":"src/flat_tree.cr","line_number":100,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L100"},"def":{"name":"count","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(2 << d) - 1_u64"}},{"id":"depth(i:UInt64?):UInt64-instance-method","html_id":"depth(i:UInt64?):UInt64-instance-method","name":"depth","doc":"Returns the depth of an element","summary":"
Returns the depth of an element
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64?) : UInt64","args_html":"(i : UInt64?) : UInt64","location":{"filename":"src/flat_tree.cr","line_number":41,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L41"},"def":{"name":"depth","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"UInt64","visibility":"Public","body":"if i.nil?\n return 0_u64\nend\n(~(BigInt.new(i))).trailing_zeros_count.to_u64\n"}},{"id":"full_roots(i:UInt64,nodes:Array(UInt64)=[]ofUInt64)-instance-method","html_id":"full_roots(i:UInt64,nodes:Array(UInt64)=[]ofUInt64)-instance-method","name":"full_roots","doc":"Returns a list of all the full roots (subtrees where all nodes have either 2 or 0 children) < index.\nFor example full_roots(8) returns [3] since the subtree rooted at 3 spans 0 -> 6 and the tree rooted\nat 7 has a child located at 9 which is >= 8.","summary":"
Returns a list of all the full roots (subtrees where all nodes have either 2 or 0 children) < index.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"nodes","doc":null,"default_value":"[] of UInt64","external_name":"nodes","restriction":"Array(UInt64)"}],"args_string":"(i : UInt64, nodes : Array(UInt64) = []ofUInt64)","args_html":"(i : UInt64, nodes : Array(UInt64) = []ofUInt64)","location":{"filename":"src/flat_tree.cr","line_number":19,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L19"},"def":{"name":"full_roots","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"nodes","doc":null,"default_value":"[] of UInt64","external_name":"nodes","restriction":"Array(UInt64)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if i.even?\nelse\n raise(ArgumentError.new(\"You can only look up roots for depth 0 blocks, got index #{i}\"))\nend\ntmp = i >> 1\no = 0_u64\nfactor = 1_u64\nwhile tmp != 0_u64\n while (factor * 2_u64) <= tmp\n factor = factor * 2_u64\n end\n nodes.push((o + factor) - 1_u64)\n o = o + (2_u64 * factor)\n tmp = tmp - factor\n factor = 1_u64\nend\nnodes\n"}},{"id":"index(d:UInt64,o:UInt64):UInt64-instance-method","html_id":"index(d:UInt64,o:UInt64):UInt64-instance-method","name":"index","doc":"Returns an array index for the tree element at the given depth and offset","summary":"
Returns an array index for the tree element at the given depth and offset
","abstract":false,"args":[{"name":"d","doc":null,"default_value":"","external_name":"d","restriction":"UInt64"},{"name":"o","doc":null,"default_value":"","external_name":"o","restriction":"UInt64"}],"args_string":"(d : UInt64, o : UInt64) : UInt64","args_html":"(d : UInt64, o : UInt64) : UInt64","location":{"filename":"src/flat_tree.cr","line_number":115,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L115"},"def":{"name":"index","args":[{"name":"d","doc":null,"default_value":"","external_name":"d","restriction":"UInt64"},{"name":"o","doc":null,"default_value":"","external_name":"o","restriction":"UInt64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"UInt64","visibility":"Public","body":"(((1_u64 + (2_u64 * o)) * (two_pow(d))) - 1_u64).to_u64"}},{"id":"iterator(i:UInt64=0_u64)-instance-method","html_id":"iterator(i:UInt64=0_u64)-instance-method","name":"iterator","doc":"Create a stateful tree iterator starting at a given index. The iterator exposes the following methods.","summary":"
Create a stateful tree iterator starting at a given index.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"0_u64","external_name":"i","restriction":"UInt64"}],"args_string":"(i : UInt64 = 0_u64)","args_html":"(i : UInt64 = 0_u64)","location":{"filename":"src/flat_tree.cr","line_number":126,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L126"},"def":{"name":"iterator","args":[{"name":"i","doc":null,"default_value":"0_u64","external_name":"i","restriction":"UInt64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Iterator.new(i)"}},{"id":"left_child(i:UInt64?,d:UInt64?=self.depth(i)):UInt64?-instance-method","html_id":"left_child(i:UInt64?,d:UInt64?=self.depth(i)):UInt64?-instance-method","name":"left_child","doc":"Returns only the left child of a node.","summary":"
Returns only the left child of a node.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64 | Nil"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64?, d : UInt64? = self.depth(i)) : UInt64?","args_html":"(i : UInt64?, d : UInt64? = self.depth(i)) : UInt64?","location":{"filename":"src/flat_tree.cr","line_number":57,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L57"},"def":{"name":"left_child","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64 | Nil"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"UInt64 | Nil","visibility":"Public","body":"if i.nil? || (i.as(UInt64)).even?\n return nil\nend\ni = i.as(UInt64)\nif d == 0\n return i\nend\nself.index(d - 1_u64, (self.offset(i, d)) << 1)\n"}},{"id":"left_span(i:UInt64,d:UInt64?=self.depth(i))-instance-method","html_id":"left_span(i:UInt64,d:UInt64?=self.depth(i))-instance-method","name":"left_span","doc":"Returns the left spanning in index in the tree index spans.","summary":"
Returns the left spanning in index in the tree index spans.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64, d : UInt64? = self.depth(i))","args_html":"(i : UInt64, d : UInt64? = self.depth(i))","location":{"filename":"src/flat_tree.cr","line_number":88,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L88"},"def":{"name":"left_span","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if i == 0\n return i\nend\n(offset(i, d)) * (2_u64 << d)\n"}},{"id":"offset(i:UInt64,d:UInt64?=self.depth(i)):UInt64-instance-method","html_id":"offset(i:UInt64,d:UInt64?=self.depth(i)):UInt64-instance-method","name":"offset","doc":"Returns the relative offset of an element","summary":"
Returns the relative offset of an element
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64, d : UInt64? = self.depth(i)) : UInt64","args_html":"(i : UInt64, d : UInt64? = self.depth(i)) : UInt64","location":{"filename":"src/flat_tree.cr","line_number":120,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L120"},"def":{"name":"offset","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"UInt64","visibility":"Public","body":"if i.even?\n return (i / 2_u64).to_u64\nend\ni >> (d + 1)\n"}},{"id":"parent(i:UInt64,d:UInt64?=self.depth(i)):UInt64-instance-method","html_id":"parent(i:UInt64,d:UInt64?=self.depth(i)):UInt64-instance-method","name":"parent","doc":"Returns the index of the parent element in tree","summary":"
Returns the index of the parent element in tree
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64, d : UInt64? = self.depth(i)) : UInt64","args_html":"(i : UInt64, d : UInt64? = self.depth(i)) : UInt64","location":{"filename":"src/flat_tree.cr","line_number":52,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L52"},"def":{"name":"parent","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"UInt64","visibility":"Public","body":"self.index(d + 1_u64, (self.offset(i, d)) >> 1_u64)"}},{"id":"right_child(i:UInt64?,d:UInt64?=self.depth(i)):UInt64?-instance-method","html_id":"right_child(i:UInt64?,d:UInt64?=self.depth(i)):UInt64?-instance-method","name":"right_child","doc":"Returns only the right child of a node.","summary":"
Returns only the right child of a node.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64 | Nil"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64?, d : UInt64? = self.depth(i)) : UInt64?","args_html":"(i : UInt64?, d : UInt64? = self.depth(i)) : UInt64?","location":{"filename":"src/flat_tree.cr","line_number":66,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L66"},"def":{"name":"right_child","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64 | Nil"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"UInt64 | Nil","visibility":"Public","body":"if i.nil? || (i.as(UInt64)).even?\n return nil\nend\ni = i.as(UInt64)\nif d == 0_u64\n return i\nend\nself.index(d - 1, (1 + ((self.offset(i, d)) << 1)).to_u64)\n"}},{"id":"right_span(i:UInt64,d:UInt64?=self.depth(i))-instance-method","html_id":"right_span(i:UInt64,d:UInt64?=self.depth(i))-instance-method","name":"right_span","doc":"Returns the right spanning in index in the tree index spans.","summary":"
Returns the right spanning in index in the tree index spans.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64, d : UInt64? = self.depth(i))","args_html":"(i : UInt64, d : UInt64? = self.depth(i))","location":{"filename":"src/flat_tree.cr","line_number":94,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L94"},"def":{"name":"right_span","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if i.even?\n return i\nend\n(((offset(i, d)) + 1_u64) * (2_u64 << d)) - 2_u64\n"}},{"id":"sibling(i:UInt64,d:UInt64?=self.depth(i))-instance-method","html_id":"sibling(i:UInt64,d:UInt64?=self.depth(i))-instance-method","name":"sibling","doc":"Returns the index of this elements sibling","summary":"
Returns the index of this elements sibling
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"args_string":"(i : UInt64, d : UInt64? = self.depth(i))","args_html":"(i : UInt64, d : UInt64? = self.depth(i))","location":{"filename":"src/flat_tree.cr","line_number":47,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L47"},"def":{"name":"sibling","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"},{"name":"d","doc":null,"default_value":"self.depth(i)","external_name":"d","restriction":"UInt64 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self.index(d, (self.offset(i, d)) ^ 1)"}},{"id":"spans(i:UInt64,d:UInt64?=self.depth(i))-instance-method","html_id":"spans(i:UInt64,d:UInt64?=self.depth(i))-instance-method","name":"spans","doc":"Returns the range (inclusive) the tree root at index spans.\nFor example FlatTree.spans(3) would return [0, 6] (see the usage example).","summary":"
Returns the range (inclusive) the tree root at index spans.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":22,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L22"},"def":{"name":"is_left","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@offset.even?"}},{"id":"is_right-instance-method","html_id":"is_right-instance-method","name":"is_right","doc":"Is the iterator at a right sibling?","summary":"
Is the iterator at a right sibling?
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":27,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L27"},"def":{"name":"is_right","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@offset.odd?"}},{"id":"left_child-instance-method","html_id":"left_child-instance-method","name":"left_child","doc":"Move the iterator to the current left child index.","summary":"
Move the iterator to the current left child index.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":86,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L86"},"def":{"name":"left_child","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @factor == 2_u64\n return @index\nend\n@factor = (@factor / 2_u64).to_u64\n@index = (@index - (@factor / 2_u64)).to_u64\n@offset = @offset * 2_u64\n@index\n"}},{"id":"left_span-instance-method","html_id":"left_span-instance-method","name":"left_span","doc":"Move the iterator to the current left span index.","summary":"
Move the iterator to the current left span index.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":70,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L70"},"def":{"name":"left_span","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@index = (@index - (@factor / 2_u64).to_u64) + 1_u64\n@offset = (@index / 2_u64).to_u64\n@factor = 2_u64\n@index\n"}},{"id":"next-instance-method","html_id":"next-instance-method","name":"next","doc":"Move the iterator the next item in the tree.","summary":"
Move the iterator the next item in the tree.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":45,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L45"},"def":{"name":"next","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@offset = @offset + 1_u64\n@index = @index + @factor\n@index\n"}},{"id":"next_tree-instance-method","html_id":"next_tree-instance-method","name":"next_tree","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":103,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L103"},"def":{"name":"next_tree","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@index = @index + ((@factor / 2_u64).to_u64 + 1_u64)\n@offset = (@index / 2_u64).to_u64\n@factor = 2_u64\n@index\n"}},{"id":"offset:UInt64-instance-method","html_id":"offset:UInt64-instance-method","name":"offset","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : UInt64","args_html":" : UInt64","location":{"filename":"src/iterator.cr","line_number":3,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L3"},"def":{"name":"offset","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"UInt64","visibility":"Public","body":"@offset"}},{"id":"offset=(offset:UInt64)-instance-method","html_id":"offset=(offset:UInt64)-instance-method","name":"offset=","doc":null,"summary":null,"abstract":false,"args":[{"name":"offset","doc":null,"default_value":"","external_name":"offset","restriction":"UInt64"}],"args_string":"(offset : UInt64)","args_html":"(offset : UInt64)","location":{"filename":"src/iterator.cr","line_number":3,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L3"},"def":{"name":"offset=","args":[{"name":"offset","doc":null,"default_value":"","external_name":"offset","restriction":"UInt64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@offset = offset"}},{"id":"parent-instance-method","html_id":"parent-instance-method","name":"parent","doc":"Move the iterator to the current parent index","summary":"
Move the iterator to the current parent index
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":57,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L57"},"def":{"name":"parent","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @offset.odd?\n @index = @index - (@factor / 2_u64).to_u64\n @offset = ((@offset - 1_u64) / 2_u64).to_u64\nelse\n @index = @index + (@factor / 2_u64).to_u64\n @offset = (@offset / 2_u64).to_u64\nend\n@factor = @factor * 2_u64\n@index\n"}},{"id":"prev-instance-method","html_id":"prev-instance-method","name":"prev","doc":"Move the iterator the prev item in the tree.","summary":"
Move the iterator the prev item in the tree.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":37,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L37"},"def":{"name":"prev","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @offset == 0\n return @index\nend\n@offset = @offset - 1_u64\n@index = @index - @factor\n@index\n"}},{"id":"prev_tree-instance-method","html_id":"prev_tree-instance-method","name":"prev_tree","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":110,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L110"},"def":{"name":"prev_tree","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @offset\n @index = @index - ((@factor / 2_u64).to_u64 - 1_u64)\n @offset = (@index / 2_u64).to_u64\n @factor = 2_u64\nelse\n @index = 0_u64\n @factor = 2_u64\nend\n@index\n"}},{"id":"right_child-instance-method","html_id":"right_child-instance-method","name":"right_child","doc":"Move the iterator to the current right child index.","summary":"
Move the iterator to the current right child index.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":95,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L95"},"def":{"name":"right_child","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if @factor == 2_u64\n return @index\nend\n@factor = (@factor / 2_u64).to_u64\n@index = (@index + (@factor / 2_u64)).to_u64\n@offset = (2_u64 * @offset) + 1_u64\n@index\n"}},{"id":"right_span-instance-method","html_id":"right_span-instance-method","name":"right_span","doc":"Move the iterator to the current right span index.","summary":"
Move the iterator to the current right span index.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":78,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L78"},"def":{"name":"right_span","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@index = @index + ((@factor / 2_u64) - 1_u64)\n@offset = (@index / 2_u64).to_u64\n@factor = 2_u64\n@index\n"}},{"id":"seek(i:UInt64)-instance-method","html_id":"seek(i:UInt64)-instance-method","name":"seek","doc":"Move the iterator the this specific tree index.","summary":"
Move the iterator the this specific tree index.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"}],"args_string":"(i : UInt64)","args_html":"(i : UInt64)","location":{"filename":"src/iterator.cr","line_number":12,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L12"},"def":{"name":"seek","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"UInt64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@index = i\n@offset, @factor = if (@index & 1_u64)\n {::FlatTree.offset(i), ::FlatTree.two_pow((::FlatTree.depth(i)) + 1_u64)}\nelse\n {(@index / 2_u64).to_u64, 2_u64}\nend\n"}},{"id":"sibling-instance-method","html_id":"sibling-instance-method","name":"sibling","doc":"Move the iterator to the current sibling","summary":"
Move the iterator to the current sibling
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/iterator.cr","line_number":52,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L52"},"def":{"name":"sibling","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@is_left ? self.next : self.prev"}}],"macros":[],"types":[]}]}]}})
\ No newline at end of file