diff --git a/FlatTree.html b/FlatTree.html new file mode 100644 index 0000000..7191dc2 --- /dev/null +++ b/FlatTree.html @@ -0,0 +1,582 @@ + + + + + + + + + + + + + + + + FlatTree - flat_tree 0.1.2 + + + + + + + + +
+

+ + module FlatTree + +

+ + + + + + + + + + + +

+ + + + Extended Modules +

+ + + + + + + + + +

+ + + + Defined in: +

+ + + + flat_tree.cr + + +
+ + + + iterator.cr + + +
+ + + + + + + + + + +

+ + + + Instance Method Summary +

+ + + + + + +
+ +
+ + + + + + +

+ + + + Instance Method Detail +

+ +
+
+ + def children(i : UInt64, d : UInt64? = self.depth(i)) : Array(UInt64)? + + # +
+ +
+ +

Returns an array [left_child, right_child] with the indexes of this elements children. +If this element does not have any children it returns null

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def count(i : UInt64, d : UInt64? = self.depth(i)) + + # +
+ +
+ +

Returns how many nodes (including parent nodes) a tree contains

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def depth(i : UInt64?) : UInt64 + + # +
+ +
+ +

Returns the depth of an element

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def full_roots(i : UInt64, nodes : Array(UInt64) = [] of UInt64) + + # +
+ +
+ +

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.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def index(d : UInt64, o : UInt64) : UInt64 + + # +
+ +
+ +

Returns an array index for the tree element at the given depth and offset

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def iterator(i : UInt64 = 0_u64) + + # +
+ +
+ +

Create a stateful tree iterator starting at a given index. The iterator exposes the following methods.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def left_child(i : UInt64?, d : UInt64? = self.depth(i)) : UInt64? + + # +
+ +
+ +

Returns only the left child of a node.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def left_span(i : UInt64, d : UInt64? = self.depth(i)) + + # +
+ +
+ +

Returns the left spanning in index in the tree index spans.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def offset(i : UInt64, d : UInt64? = self.depth(i)) : UInt64 + + # +
+ +
+ +

Returns the relative offset of an element

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def parent(i : UInt64, d : UInt64? = self.depth(i)) : UInt64 + + # +
+ +
+ +

Returns the index of the parent element in tree

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def right_child(i : UInt64?, d : UInt64? = self.depth(i)) : UInt64? + + # +
+ +
+ +

Returns only the right child of a node.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def right_span(i : UInt64, d : UInt64? = self.depth(i)) + + # +
+ +
+ +

Returns the right spanning in index in the tree index spans.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def sibling(i : UInt64, d : UInt64? = self.depth(i)) + + # +
+ +
+ +

Returns the index of this elements sibling

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def spans(i : UInt64, d : UInt64? = self.depth(i)) + + # +
+ +
+ +

Returns the range (inclusive) the tree root at index spans. +For example FlatTree.spans(3) would return [0, 6] (see the usage example).

+
+ +
+
+ + [View source] + +
+
+ + + + + +
+ + + diff --git a/FlatTree/Iterator.html b/FlatTree/Iterator.html new file mode 100644 index 0000000..32f020b --- /dev/null +++ b/FlatTree/Iterator.html @@ -0,0 +1,748 @@ + + + + + + + + + + + + + + + + FlatTree::Iterator - flat_tree 0.1.2 + + + + + + + + +
+

+ + class FlatTree::Iterator + +

+ + + + + + + + + + + + + + + + + + + + +

+ + + + Defined in: +

+ + + + iterator.cr + + +
+ + + + + + +

+ + + + Constructors +

+ + + + + + +

+ + + + Instance Method Summary +

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + +

+ + + + Constructor Detail +

+ +
+
+ + def self.new(index = 0_u64, offset = 0_u64, factor = 0_u64) + + # +
+ +
+
+ + [View source] + +
+
+ + + + + + +

+ + + + Instance Method Detail +

+ +
+
+ + def contains(i : UInt64) + + # +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def factor : UInt64 + + # +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def factor=(factor : UInt64) + + # +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def full_root(i : UInt64) + + # +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def index : UInt64 + + # +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def index=(index : UInt64) + + # +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def is_left + + # +
+ +
+ +

Is the iterator at a left sibling?

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def is_right + + # +
+ +
+ +

Is the iterator at a right sibling?

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def left_child + + # +
+ +
+ +

Move the iterator to the current left child index.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def left_span + + # +
+ +
+ +

Move the iterator to the current left span index.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def next + + # +
+ +
+ +

Move the iterator the next item in the tree.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def next_tree + + # +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def offset : UInt64 + + # +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def offset=(offset : UInt64) + + # +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def parent + + # +
+ +
+ +

Move the iterator to the current parent index

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def prev + + # +
+ +
+ +

Move the iterator the prev item in the tree.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def prev_tree + + # +
+ +
+
+ + [View source] + +
+
+ +
+
+ + def right_child + + # +
+ +
+ +

Move the iterator to the current right child index.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def right_span + + # +
+ +
+ +

Move the iterator to the current right span index.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def seek(i : UInt64) + + # +
+ +
+ +

Move the iterator the this specific tree index.

+
+ +
+
+ + [View source] + +
+
+ +
+
+ + def sibling + + # +
+ +
+ +

Move the iterator to the current sibling

+
+ +
+
+ + [View source] + +
+
+ + + + + +
+ + + diff --git a/css/style.css b/css/style.css new file mode 100644 index 0000000..20bb084 --- /dev/null +++ b/css/style.css @@ -0,0 +1,726 @@ +html, body { + background: #FFFFFF; + position: relative; + margin: 0; + padding: 0; + width: 100%; + height: 100%; + overflow: hidden; +} + +body { + font-family: "Avenir", "Tahoma", "Lucida Sans", "Lucida Grande", Verdana, Arial, sans-serif; + color: #333; + line-height: 1.5; +} + +a { + color: #263F6C; +} + +a:visited { + color: #112750; +} + +h1, h2, h3, h4, h5, h6 { + margin: 35px 0 25px; + color: #444444; +} + +h1.type-name { + color: #47266E; + margin: 20px 0 30px; + background-color: #F8F8F8; + padding: 10px 12px; + border: 1px solid #EBEBEB; + border-radius: 2px; +} + +h2 { + border-bottom: 1px solid #E6E6E6; + padding-bottom: 5px; +} + +body { + display: flex; +} + +.sidebar, .main-content { + overflow: auto; +} + +.sidebar { + width: 30em; + color: #F8F4FD; + background-color: #2E1052; + padding: 0 0 30px; + box-shadow: inset -3px 0 4px rgba(0,0,0,.35); + line-height: 1.2; + z-index: 0; +} + +.sidebar .search-box { + padding: 13px 9px; +} + +.sidebar input { + display: block; + box-sizing: border-box; + margin: 0; + padding: 5px; + font: inherit; + font-family: inherit; + line-height: 1.2; + width: 100%; + border: 0; + outline: 0; + border-radius: 2px; + box-shadow: 0px 3px 5px rgba(0,0,0,.25); + transition: box-shadow .12s; +} + +.sidebar input:focus { + box-shadow: 0px 5px 6px rgba(0,0,0,.5); +} + +.sidebar input::-webkit-input-placeholder { /* Chrome/Opera/Safari */ + color: #C8C8C8; + font-size: 14px; + text-indent: 2px; +} + +.sidebar input::-moz-placeholder { /* Firefox 19+ */ + color: #C8C8C8; + font-size: 14px; + text-indent: 2px; +} + +.sidebar input:-ms-input-placeholder { /* IE 10+ */ + color: #C8C8C8; + font-size: 14px; + text-indent: 2px; +} + +.sidebar input:-moz-placeholder { /* Firefox 18- */ + color: #C8C8C8; + font-size: 14px; + text-indent: 2px; +} + +.project-summary { + padding: 9px 15px 30px 30px; +} + +.project-name { + font-size: 1.4rem; + margin: 0; + color: #f4f4f4; + font-weight: 600; +} + +.project-version { + margin-top: 5px; + display: inline-block; + position: relative; +} + +.project-version > form::after { + position: absolute; + right: 0; + top: 0; + content: "\25BC"; + font-size: .6em; + line-height: 1.2rem; + z-index: -1; +} + +.project-versions-nav { + cursor: pointer; + margin: 0; + padding: 0 .9em 0 0; + border: none; + -moz-appearance: none; + -webkit-appearance: none; + appearance: none; + background-color: transparent; + color: inherit; + font-family: inherit; + font-size: inherit; + line-height: inherit; +} +.project-versions-nav:focus { + outline: none; +} + +.project-versions-nav > option { + color: initial; +} + +.sidebar ul { + margin: 0; + padding: 0; + list-style: none outside; +} + +.sidebar li { + display: block; + position: relative; +} + +.types-list li.hide { + display: none; +} + +.sidebar a { + text-decoration: none; + color: inherit; + transition: color .14s; +} +.types-list a { + display: block; + padding: 5px 15px 5px 30px; +} + +.types-list { + display: block; +} + +.sidebar a:focus { + outline: 1px solid #D1B7F1; +} + +.types-list a { + padding: 5px 15px 5px 30px; +} + +.sidebar .current > a, +.sidebar a:hover { + color: #866BA6; +} + +.types-list li ul { + overflow: hidden; + height: 0; + max-height: 0; + transition: 1s ease-in-out; +} + +.types-list li.parent { + padding-left: 30px; +} + +.types-list li.parent::before { + box-sizing: border-box; + content: "▼"; + display: block; + width: 30px; + height: 30px; + position: absolute; + top: 0; + left: 0; + text-align: center; + color: white; + font-size: 8px; + line-height: 30px; + transform: rotateZ(-90deg); + cursor: pointer; + transition: .2s linear; +} + + +.types-list li.parent > a { + padding-left: 0; +} + +.types-list li.parent.open::before { + transform: rotateZ(0); +} + +.types-list li.open > ul { + height: auto; + max-height: 1000em; +} + +.main-content { + padding: 0 30px 30px 30px; + width: 100%; +} + +.kind { + font-size: 60%; + color: #866BA6; +} + +.superclass-hierarchy { + margin: -15px 0 30px 0; + padding: 0; + list-style: none outside; + font-size: 80%; +} + +.superclass-hierarchy .superclass { + display: inline-block; + margin: 0 7px 0 0; + padding: 0; +} + +.superclass-hierarchy .superclass + .superclass::before { + content: "<"; + margin-right: 7px; +} + +.other-types-list li { + display: inline-block; +} + +.other-types-list, +.list-summary { + margin: 0 0 30px 0; + padding: 0; + list-style: none outside; +} + +.entry-const { + font-family: Menlo, Monaco, Consolas, 'Courier New', Courier, monospace; +} + +.entry-const code { + white-space: pre-wrap; +} + +.entry-summary { + padding-bottom: 4px; +} + +.superclass-hierarchy .superclass a, +.other-type a, +.entry-summary .signature { + padding: 4px 8px; + margin-bottom: 4px; + display: inline-block; + background-color: #f8f8f8; + color: #47266E; + border: 1px solid #f0f0f0; + text-decoration: none; + border-radius: 3px; + font-family: Menlo, Monaco, Consolas, 'Courier New', Courier, monospace; + transition: background .15s, border-color .15s; +} + +.superclass-hierarchy .superclass a:hover, +.other-type a:hover, +.entry-summary .signature:hover { + background: #D5CAE3; + border-color: #624288; +} + +.entry-summary .summary { + padding-left: 32px; +} + +.entry-summary .summary p { + margin: 12px 0 16px; +} + +.entry-summary a { + text-decoration: none; +} + +.entry-detail { + padding: 30px 0; +} + +.entry-detail .signature { + position: relative; + padding: 5px 15px; + margin-bottom: 10px; + display: block; + border-radius: 5px; + background-color: #f8f8f8; + color: #47266E; + border: 1px solid #f0f0f0; + font-family: Menlo, Monaco, Consolas, 'Courier New', Courier, monospace; + transition: .2s ease-in-out; +} + +.entry-detail:target .signature { + background-color: #D5CAE3; + border: 1px solid #624288; +} + +.entry-detail .signature .method-permalink { + position: absolute; + top: 0; + left: -35px; + padding: 5px 15px; + text-decoration: none; + font-weight: bold; + color: #624288; + opacity: .4; + transition: opacity .2s; +} + +.entry-detail .signature .method-permalink:hover { + opacity: 1; +} + +.entry-detail:target .signature .method-permalink { + opacity: 1; +} + +.methods-inherited { + padding-right: 10%; + line-height: 1.5em; +} + +.methods-inherited h3 { + margin-bottom: 4px; +} + +.methods-inherited a { + display: inline-block; + text-decoration: none; + color: #47266E; +} + +.methods-inherited a:hover { + text-decoration: underline; + color: #6C518B; +} + +.methods-inherited .tooltip>span { + background: #D5CAE3; + padding: 4px 8px; + border-radius: 3px; + margin: -4px -8px; +} + +.methods-inherited .tooltip * { + color: #47266E; +} + +pre { + padding: 10px 20px; + margin-top: 4px; + border-radius: 3px; + line-height: 1.45; + overflow: auto; + color: #333; + background: #fdfdfd; + font-size: 14px; + border: 1px solid #eee; +} + +code { + font-family: Menlo, Monaco, Consolas, 'Courier New', Courier, monospace; +} + +:not(pre) > code { + background-color: rgba(40,35,30,0.05); + padding: 0.2em 0.4em; + font-size: 85%; + border-radius: 3px; +} + +span.flag { + padding: 2px 4px 1px; + border-radius: 3px; + margin-right: 3px; + font-size: 11px; + border: 1px solid transparent; +} + +span.flag.orange { + background-color: #EE8737; + color: #FCEBDD; + border-color: #EB7317; +} + +span.flag.yellow { + background-color: #E4B91C; + color: #FCF8E8; + border-color: #B69115; +} + +span.flag.green { + background-color: #469C14; + color: #E2F9D3; + border-color: #34700E; +} + +span.flag.red { + background-color: #BF1919; + color: #F9ECEC; + border-color: #822C2C; +} + +span.flag.purple { + background-color: #2E1052; + color: #ECE1F9; + border-color: #1F0B37; +} + +span.flag.lime { + background-color: #a3ff00; + color: #222222; + border-color: #00ff1e; +} + +.tooltip>span { + position: absolute; + opacity: 0; + display: none; + pointer-events: none; +} + +.tooltip:hover>span { + display: inline-block; + opacity: 1; +} + +.c { + color: #969896; +} + +.n { + color: #0086b3; +} + +.t { + color: #0086b3; +} + +.s { + color: #183691; +} + +.i { + color: #7f5030; +} + +.k { + color: #a71d5d; +} + +.o { + color: #a71d5d; +} + +.m { + color: #795da3; +} + +.hidden { + display: none; +} +.search-results { + font-size: 90%; + line-height: 1.3; +} + +.search-results mark { + color: inherit; + background: transparent; + font-weight: bold; +} +.search-result { + padding: 5px 8px 5px 5px; + cursor: pointer; + border-left: 5px solid transparent; + transform: translateX(-3px); + transition: all .2s, background-color 0s, border .02s; + min-height: 3.2em; +} +.search-result.current { + border-left-color: #ddd; + background-color: rgba(200,200,200,0.4); + transform: translateX(0); + transition: all .2s, background-color .5s, border 0s; +} +.search-result.current:hover, +.search-result.current:focus { + border-left-color: #866BA6; +} +.search-result:not(.current):nth-child(2n) { + background-color: rgba(255,255,255,.06); +} +.search-result__title { + font-size: 105%; + word-break: break-all; + line-height: 1.1; + padding: 3px 0; +} +.search-result__title strong { + font-weight: normal; +} +.search-results .search-result__title > a { + padding: 0; + display: block; +} +.search-result__title > a > .args { + color: #dddddd; + font-weight: 300; + transition: inherit; + font-size: 88%; + line-height: 1.2; + letter-spacing: -.02em; +} +.search-result__title > a > .args * { + color: inherit; +} + +.search-result a, +.search-result a:hover { + color: inherit; +} +.search-result:not(.current):hover .search-result__title > a, +.search-result:not(.current):focus .search-result__title > a, +.search-result__title > a:focus { + color: #866BA6; +} +.search-result:not(.current):hover .args, +.search-result:not(.current):focus .args { + color: #6a5a7d; +} + +.search-result__type { + color: #e8e8e8; + font-weight: 300; +} +.search-result__doc { + color: #bbbbbb; + font-size: 90%; +} +.search-result__doc p { + margin: 0; + text-overflow: ellipsis; + display: -webkit-box; + -webkit-box-orient: vertical; + -webkit-line-clamp: 2; + overflow: hidden; + line-height: 1.2em; + max-height: 2.4em; +} + +.js-modal-visible .modal-background { + display: flex; +} +.main-content { + position: relative; +} +.modal-background { + position: absolute; + display: none; + height: 100%; + width: 100%; + background: rgba(120,120,120,.4); + z-index: 100; + align-items: center; + justify-content: center; +} +.usage-modal { + max-width: 90%; + background: #fff; + border: 2px solid #ccc; + border-radius: 9px; + padding: 5px 15px 20px; + min-width: 50%; + color: #555; + position: relative; + transform: scale(.5); + transition: transform 200ms; +} +.js-modal-visible .usage-modal { + transform: scale(1); +} +.usage-modal > .close-button { + position: absolute; + right: 15px; + top: 8px; + color: #aaa; + font-size: 27px; + cursor: pointer; +} +.usage-modal > .close-button:hover { + text-shadow: 2px 2px 2px #ccc; + color: #999; +} +.modal-title { + margin: 0; + text-align: center; + font-weight: normal; + color: #666; + border-bottom: 2px solid #ddd; + padding: 10px; +} +.usage-list { + padding: 0; + margin: 13px; +} +.usage-list > li { + padding: 5px 2px; + overflow: auto; + padding-left: 100px; + min-width: 12em; +} +.usage-modal kbd { + background: #eee; + border: 1px solid #ccc; + border-bottom-width: 2px; + border-radius: 3px; + padding: 3px 8px; + font-family: monospace; + margin-right: 2px; + display: inline-block; +} +.usage-key { + float: left; + clear: left; + margin-left: -100px; + margin-right: 12px; +} +.doc-inherited { + font-weight: bold; +} + +.anchor { + float: left; + padding-right: 4px; + margin-left: -20px; +} + +.main-content .anchor .octicon-link { + width: 16px; + height: 16px; +} + +.main-content .anchor:focus { + outline: none +} + +.main-content h1:hover .anchor, +.main-content h2:hover .anchor, +.main-content h3:hover .anchor, +.main-content h4:hover .anchor, +.main-content h5:hover .anchor, +.main-content h6:hover .anchor { + text-decoration: none +} + +.main-content h1 .octicon-link, +.main-content h2 .octicon-link, +.main-content h3 .octicon-link, +.main-content h4 .octicon-link, +.main-content h5 .octicon-link, +.main-content h6 .octicon-link { + visibility: hidden +} + +.main-content h1:hover .anchor .octicon-link, +.main-content h2:hover .anchor .octicon-link, +.main-content h3:hover .anchor .octicon-link, +.main-content h4:hover .anchor .octicon-link, +.main-content h5:hover .anchor .octicon-link, +.main-content h6:hover .anchor .octicon-link { + visibility: visible +} diff --git a/index.html b/index.html new file mode 100644 index 0000000..0ad3a69 --- /dev/null +++ b/index.html @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + flat_tree 0.1.2 + + + + + + + + +
+

+ +flat_tree

+ +

Build Status Docs GitHub release (latest by date)

+ +

Map a binary tree to a vector. Port of mafintosh/flat-tree

+ + + +

+ +Installation

+ +
  1. Add the dependency to your shard.yml:
+ +

`yaml + dependencies:

+ +
 flat_tree:
+   github: dukeraphaelng/flat_tree
+ +

`

+ +
  1. Run shards install
+ +

+ +Usage

+ +

You can represent a binary tree in a simple flat list using the following structure

+ +
      3
+  1       5
+0   2   4   6  ...
+ +

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'
+ +

+ +Contributing

+ +
  1. Fork it (<https://github.com/dukeraphaelng/flat_tree/fork>)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
+ + + +
  1. Push to the branch (git push origin my-new-feature)
  2. Create a new Pull Request
+ +

+ +Contributors

+ + + +

+ +License

+ + +
+ + 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) = [] of UInt64)","args_html":"(i : UInt64, nodes : Array(UInt64) = [] of UInt64)","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":[{"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":106,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L106"},"def":{"name":"spans","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, i]\nend\no = offset(i, d)\nwidth = (2 << d)\n[o * width, ((o + 1_u64) * width) - 2_u64]\n"}}],"macros":[],"types":[{"html_id":"flat_tree/FlatTree/Iterator","path":"FlatTree/Iterator.html","kind":"class","full_name":"FlatTree::Iterator","name":"Iterator","abstract":false,"superclass":{"html_id":"flat_tree/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"flat_tree/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"flat_tree/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"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":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"flat_tree/FlatTree","kind":"module","full_name":"FlatTree","name":"FlatTree"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(index=0_u64,offset=0_u64,factor=0_u64)-class-method","html_id":"new(index=0_u64,offset=0_u64,factor=0_u64)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"index","doc":null,"default_value":"0_u64","external_name":"index","restriction":""},{"name":"offset","doc":null,"default_value":"0_u64","external_name":"offset","restriction":""},{"name":"factor","doc":null,"default_value":"0_u64","external_name":"factor","restriction":""}],"args_string":"(index = 0_u64, offset = 0_u64, factor = 0_u64)","args_html":"(index = 0_u64, offset = 0_u64, factor = 0_u64)","location":{"filename":"src/iterator.cr","line_number":6,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L6"},"def":{"name":"new","args":[{"name":"index","doc":null,"default_value":"0_u64","external_name":"index","restriction":""},{"name":"offset","doc":null,"default_value":"0_u64","external_name":"offset","restriction":""},{"name":"factor","doc":null,"default_value":"0_u64","external_name":"factor","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(index, offset, factor)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"contains(i:UInt64)-instance-method","html_id":"contains(i:UInt64)-instance-method","name":"contains","doc":null,"summary":null,"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":31,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L31"},"def":{"name":"contains","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":"condition = i > @index ? i < (@index + (@factor / 2_u64)) : i < @index\ncondition ? i > (@index - (@factor / 2_u64)) : true\n"}},{"id":"factor:UInt64-instance-method","html_id":"factor:UInt64-instance-method","name":"factor","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : UInt64","args_html":" : UInt64","location":{"filename":"src/iterator.cr","line_number":4,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L4"},"def":{"name":"factor","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"UInt64","visibility":"Public","body":"@factor"}},{"id":"factor=(factor:UInt64)-instance-method","html_id":"factor=(factor:UInt64)-instance-method","name":"factor=","doc":null,"summary":null,"abstract":false,"args":[{"name":"factor","doc":null,"default_value":"","external_name":"factor","restriction":"UInt64"}],"args_string":"(factor : UInt64)","args_html":"(factor : UInt64)","location":{"filename":"src/iterator.cr","line_number":4,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L4"},"def":{"name":"factor=","args":[{"name":"factor","doc":null,"default_value":"","external_name":"factor","restriction":"UInt64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@factor = factor"}},{"id":"full_root(i:UInt64)-instance-method","html_id":"full_root(i:UInt64)-instance-method","name":"full_root","doc":null,"summary":null,"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":123,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L123"},"def":{"name":"full_root","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":"if i <= @index || (@index & 1_u64) > 0_u64\n return false\nend\nwhile i > ((@index + @factor) + (@factor / 2_u64))\n @index = @index + (@factor / 2_u64).to_u64\n @factor = @factor * 2_u64\n @offset = (@offset / 2_u64).to_u64\nend\ntrue\n"}},{"id":"index:UInt64-instance-method","html_id":"index:UInt64-instance-method","name":"index","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : UInt64","args_html":" : UInt64","location":{"filename":"src/iterator.cr","line_number":2,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L2"},"def":{"name":"index","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"UInt64","visibility":"Public","body":"@index"}},{"id":"index=(index:UInt64)-instance-method","html_id":"index=(index:UInt64)-instance-method","name":"index=","doc":null,"summary":null,"abstract":false,"args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"UInt64"}],"args_string":"(index : UInt64)","args_html":"(index : UInt64)","location":{"filename":"src/iterator.cr","line_number":2,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L2"},"def":{"name":"index=","args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"UInt64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@index = index"}},{"id":"is_left-instance-method","html_id":"is_left-instance-method","name":"is_left","doc":"Is the iterator at a left sibling?","summary":"

Is the iterator at a left sibling?

","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 diff --git a/js/doc.js b/js/doc.js new file mode 100644 index 0000000..eb03302 --- /dev/null +++ b/js/doc.js @@ -0,0 +1,1086 @@ +window.CrystalDocs = (window.CrystalDocs || {}); + +CrystalDocs.base_path = (CrystalDocs.base_path || ""); + +CrystalDocs.searchIndex = (CrystalDocs.searchIndex || false); +CrystalDocs.MAX_RESULTS_DISPLAY = 140; + +CrystalDocs.runQuery = function(query) { + function searchType(type, query, results) { + var matches = []; + var matchedFields = []; + var name = type.full_name; + var i = name.lastIndexOf("::"); + if (i > 0) { + name = name.substring(i + 2); + } + var nameMatches = query.matches(name); + if (nameMatches){ + matches = matches.concat(nameMatches); + matchedFields.push("name"); + } + + var namespaceMatches = query.matchesNamespace(type.full_name); + if(namespaceMatches){ + matches = matches.concat(namespaceMatches); + matchedFields.push("name"); + } + + var docMatches = query.matches(type.doc); + if(docMatches){ + matches = matches.concat(docMatches); + matchedFields.push("doc"); + } + if (matches.length > 0) { + results.push({ + id: type.id, + result_type: "type", + kind: type.kind, + name: name, + full_name: type.full_name, + href: type.path, + summary: type.summary, + matched_fields: matchedFields, + matched_terms: matches + }); + } + + type.instance_methods.forEach(function(method) { + searchMethod(method, type, "instance_method", query, results); + }) + type.class_methods.forEach(function(method) { + searchMethod(method, type, "class_method", query, results); + }) + type.constructors.forEach(function(constructor) { + searchMethod(constructor, type, "constructor", query, results); + }) + type.macros.forEach(function(macro) { + searchMethod(macro, type, "macro", query, results); + }) + type.constants.forEach(function(constant){ + searchConstant(constant, type, query, results); + }); + + type.types.forEach(function(subtype){ + searchType(subtype, query, results); + }); + }; + + function searchMethod(method, type, kind, query, results) { + var matches = []; + var matchedFields = []; + var nameMatches = query.matchesMethod(method.name, kind, type); + if (nameMatches){ + matches = matches.concat(nameMatches); + matchedFields.push("name"); + } + + method.args.forEach(function(arg){ + var argMatches = query.matches(arg.external_name); + if (argMatches) { + matches = matches.concat(argMatches); + matchedFields.push("args"); + } + }); + + var docMatches = query.matches(type.doc); + if(docMatches){ + matches = matches.concat(docMatches); + matchedFields.push("doc"); + } + + if (matches.length > 0) { + var typeMatches = query.matches(type.full_name); + if (typeMatches) { + matchedFields.push("type"); + matches = matches.concat(typeMatches); + } + results.push({ + id: method.id, + type: type.full_name, + result_type: kind, + name: method.name, + full_name: type.full_name + "#" + method.name, + args_string: method.args_string, + summary: method.summary, + href: type.path + "#" + method.id, + matched_fields: matchedFields, + matched_terms: matches + }); + } + } + + function searchConstant(constant, type, query, results) { + var matches = []; + var matchedFields = []; + var nameMatches = query.matches(constant.name); + if (nameMatches){ + matches = matches.concat(nameMatches); + matchedFields.push("name"); + } + var docMatches = query.matches(constant.doc); + if(docMatches){ + matches = matches.concat(docMatches); + matchedFields.push("doc"); + } + if (matches.length > 0) { + var typeMatches = query.matches(type.full_name); + if (typeMatches) { + matchedFields.push("type"); + matches = matches.concat(typeMatches); + } + results.push({ + id: constant.id, + type: type.full_name, + result_type: "constant", + name: constant.name, + full_name: type.full_name + "#" + constant.name, + value: constant.value, + summary: constant.summary, + href: type.path + "#" + constant.id, + matched_fields: matchedFields, + matched_terms: matches + }); + } + } + + var results = []; + searchType(CrystalDocs.searchIndex.program, query, results); + return results; +}; + +CrystalDocs.rankResults = function(results, query) { + function uniqueArray(ar) { + var j = {}; + + ar.forEach(function(v) { + j[v + "::" + typeof v] = v; + }); + + return Object.keys(j).map(function(v) { + return j[v]; + }); + } + + results = results.sort(function(a, b) { + var matchedTermsDiff = uniqueArray(b.matched_terms).length - uniqueArray(a.matched_terms).length; + var aHasDocs = b.matched_fields.includes("doc"); + var bHasDocs = b.matched_fields.includes("doc"); + + var aOnlyDocs = aHasDocs && a.matched_fields.length == 1; + var bOnlyDocs = bHasDocs && b.matched_fields.length == 1; + + if (a.result_type == "type" && b.result_type != "type" && !aOnlyDocs) { + if(CrystalDocs.DEBUG) { console.log("a is type b not"); } + return -1; + } else if (b.result_type == "type" && a.result_type != "type" && !bOnlyDocs) { + if(CrystalDocs.DEBUG) { console.log("b is type, a not"); } + return 1; + } + if (a.matched_fields.includes("name")) { + if (b.matched_fields.includes("name")) { + var a_name = (CrystalDocs.prefixForType(a.result_type) || "") + ((a.result_type == "type") ? a.full_name : a.name); + var b_name = (CrystalDocs.prefixForType(b.result_type) || "") + ((b.result_type == "type") ? b.full_name : b.name); + a_name = a_name.toLowerCase(); + b_name = b_name.toLowerCase(); + for(var i = 0; i < query.normalizedTerms.length; i++) { + var term = query.terms[i].replace(/^::?|::?$/, ""); + var a_orig_index = a_name.indexOf(term); + var b_orig_index = b_name.indexOf(term); + if(CrystalDocs.DEBUG) { console.log("term: " + term + " a: " + a_name + " b: " + b_name); } + if(CrystalDocs.DEBUG) { console.log(a_orig_index, b_orig_index, a_orig_index - b_orig_index); } + if (a_orig_index >= 0) { + if (b_orig_index >= 0) { + if(CrystalDocs.DEBUG) { console.log("both have exact match", a_orig_index > b_orig_index ? -1 : 1); } + if(a_orig_index != b_orig_index) { + if(CrystalDocs.DEBUG) { console.log("both have exact match at different positions", a_orig_index > b_orig_index ? 1 : -1); } + return a_orig_index > b_orig_index ? 1 : -1; + } + } else { + if(CrystalDocs.DEBUG) { console.log("a has exact match, b not"); } + return -1; + } + } else if (b_orig_index >= 0) { + if(CrystalDocs.DEBUG) { console.log("b has exact match, a not"); } + return 1; + } + } + } else { + if(CrystalDocs.DEBUG) { console.log("a has match in name, b not"); } + return -1; + } + } else if ( + !a.matched_fields.includes("name") && + b.matched_fields.includes("name") + ) { + return 1; + } + + if (matchedTermsDiff != 0 || (aHasDocs != bHasDocs)) { + if(CrystalDocs.DEBUG) { console.log("matchedTermsDiff: " + matchedTermsDiff, aHasDocs, bHasDocs); } + return matchedTermsDiff; + } + + var matchedFieldsDiff = b.matched_fields.length - a.matched_fields.length; + if (matchedFieldsDiff != 0) { + if(CrystalDocs.DEBUG) { console.log("matched to different number of fields: " + matchedFieldsDiff); } + return matchedFieldsDiff > 0 ? 1 : -1; + } + + var nameCompare = a.name.localeCompare(b.name); + if(nameCompare != 0){ + if(CrystalDocs.DEBUG) { console.log("nameCompare resulted in: " + a.name + "<=>" + b.name + ": " + nameCompare); } + return nameCompare > 0 ? 1 : -1; + } + + if(a.matched_fields.includes("args") && b.matched_fields.includes("args")) { + for(var i = 0; i < query.terms.length; i++) { + var term = query.terms[i]; + var aIndex = a.args_string.indexOf(term); + var bIndex = b.args_string.indexOf(term); + if(CrystalDocs.DEBUG) { console.log("index of " + term + " in args_string: " + aIndex + " - " + bIndex); } + if(aIndex >= 0){ + if(bIndex >= 0){ + if(aIndex != bIndex){ + return aIndex > bIndex ? 1 : -1; + } + }else{ + return -1; + } + }else if(bIndex >= 0) { + return 1; + } + } + } + + return 0; + }); + + if (results.length > 1) { + // if we have more than two search terms, only include results with the most matches + var bestMatchedTerms = uniqueArray(results[0].matched_terms).length; + + results = results.filter(function(result) { + return uniqueArray(result.matched_terms).length + 1 >= bestMatchedTerms; + }); + } + return results; +}; + +CrystalDocs.prefixForType = function(type) { + switch (type) { + case "instance_method": + return "#"; + + case "class_method": + case "macro": + case "constructor": + return "."; + + default: + return false; + } +}; + +CrystalDocs.displaySearchResults = function(results, query) { + function sanitize(html){ + return html.replace(/<(?!\/?code)[^>]+>/g, ""); + } + + // limit results + if (results.length > CrystalDocs.MAX_RESULTS_DISPLAY) { + results = results.slice(0, CrystalDocs.MAX_RESULTS_DISPLAY); + } + + var $frag = document.createDocumentFragment(); + var $resultsElem = document.querySelector(".search-list"); + $resultsElem.innerHTML = ""; + + results.forEach(function(result, i) { + var url = CrystalDocs.base_path + result.href; + var type = false; + + var title = query.highlight(result.result_type == "type" ? result.full_name : result.name); + + var prefix = CrystalDocs.prefixForType(result.result_type); + if (prefix) { + title = "" + prefix + "" + title; + } + + title = "" + title + ""; + + if (result.args_string) { + title += + "" + query.highlight(result.args_string) + ""; + } + + $elem = document.createElement("li"); + $elem.className = "search-result search-result--" + result.result_type; + $elem.dataset.href = url; + $elem.setAttribute("title", result.full_name + " docs page"); + + var $title = document.createElement("div"); + $title.setAttribute("class", "search-result__title"); + var $titleLink = document.createElement("a"); + $titleLink.setAttribute("href", url); + + $titleLink.innerHTML = title; + $title.appendChild($titleLink); + $elem.appendChild($title); + $elem.addEventListener("click", function() { + $titleLink.click(); + }); + + if (result.result_type !== "type") { + var $type = document.createElement("div"); + $type.setAttribute("class", "search-result__type"); + $type.innerHTML = query.highlight(result.type); + $elem.appendChild($type); + } + + if(result.summary){ + var $doc = document.createElement("div"); + $doc.setAttribute("class", "search-result__doc"); + $doc.innerHTML = query.highlight(sanitize(result.summary)); + $elem.appendChild($doc); + } + + $elem.appendChild(document.createComment(JSON.stringify(result))); + $frag.appendChild($elem); + }); + + $resultsElem.appendChild($frag); + + CrystalDocs.toggleResultsList(true); +}; + +CrystalDocs.toggleResultsList = function(visible) { + if (visible) { + document.querySelector(".types-list").classList.add("hidden"); + document.querySelector(".search-results").classList.remove("hidden"); + } else { + document.querySelector(".types-list").classList.remove("hidden"); + document.querySelector(".search-results").classList.add("hidden"); + } +}; + +CrystalDocs.Query = function(string) { + this.original = string; + this.terms = string.split(/\s+/).filter(function(word) { + return CrystalDocs.Query.stripModifiers(word).length > 0; + }); + + var normalized = this.terms.map(CrystalDocs.Query.normalizeTerm); + this.normalizedTerms = normalized; + + function runMatcher(field, matcher) { + if (!field) { + return false; + } + var normalizedValue = CrystalDocs.Query.normalizeTerm(field); + + var matches = []; + normalized.forEach(function(term) { + if (matcher(normalizedValue, term)) { + matches.push(term); + } + }); + return matches.length > 0 ? matches : false; + } + + this.matches = function(field) { + return runMatcher(field, function(normalized, term) { + if (term[0] == "#" || term[0] == ".") { + return false; + } + return normalized.indexOf(term) >= 0; + }); + }; + + function namespaceMatcher(normalized, term){ + var i = term.indexOf(":"); + if(i >= 0){ + term = term.replace(/^::?|::?$/, ""); + var index = normalized.indexOf(term); + if((index == 0) || (index > 0 && normalized[index-1] == ":")){ + return true; + } + } + return false; + } + this.matchesMethod = function(name, kind, type) { + return runMatcher(name, function(normalized, term) { + var i = term.indexOf("#"); + if(i >= 0){ + if (kind != "instance_method") { + return false; + } + }else{ + i = term.indexOf("."); + if(i >= 0){ + if (kind != "class_method" && kind != "macro" && kind != "constructor") { + return false; + } + }else{ + //neither # nor . + if(term.indexOf(":") && namespaceMatcher(normalized, term)){ + return true; + } + } + } + + var methodName = term; + if(i >= 0){ + var termType = term.substring(0, i); + methodName = term.substring(i+1); + + if(termType != "") { + if(CrystalDocs.Query.normalizeTerm(type.full_name).indexOf(termType) < 0){ + return false; + } + } + } + return normalized.indexOf(methodName) >= 0; + }); + }; + + this.matchesNamespace = function(namespace){ + return runMatcher(namespace, namespaceMatcher); + }; + + this.highlight = function(string) { + if (typeof string == "undefined") { + return ""; + } + function escapeRegExp(s) { + return s.replace(/[.*+?\^${}()|\[\]\\]/g, "\\$&").replace(/^[#\.:]+/, ""); + } + return string.replace( + new RegExp("(" + this.normalizedTerms.map(escapeRegExp).join("|") + ")", "gi"), + "$1" + ); + }; +}; +CrystalDocs.Query.normalizeTerm = function(term) { + return term.toLowerCase(); +}; +CrystalDocs.Query.stripModifiers = function(term) { + switch (term[0]) { + case "#": + case ".": + case ":": + return term.substr(1); + + default: + return term; + } +} + +CrystalDocs.search = function(string) { + if(!CrystalDocs.searchIndex) { + console.log("CrystalDocs search index not initialized, delaying search"); + + document.addEventListener("CrystalDocs:loaded", function listener(){ + document.removeEventListener("CrystalDocs:loaded", listener); + CrystalDocs.search(string); + }); + return; + } + + document.dispatchEvent(new Event("CrystalDocs:searchStarted")); + + var query = new CrystalDocs.Query(string); + var results = CrystalDocs.runQuery(query); + results = CrystalDocs.rankResults(results, query); + CrystalDocs.displaySearchResults(results, query); + + document.dispatchEvent(new Event("CrystalDocs:searchPerformed")); +}; + +CrystalDocs.initializeIndex = function(data) { + CrystalDocs.searchIndex = data; + + document.dispatchEvent(new Event("CrystalDocs:loaded")); +}; + +CrystalDocs.loadIndex = function() { + function loadJSON(file, callback) { + var xobj = new XMLHttpRequest(); + xobj.overrideMimeType("application/json"); + xobj.open("GET", file, true); + xobj.onreadystatechange = function() { + if (xobj.readyState == 4 && xobj.status == "200") { + callback(xobj.responseText); + } + }; + xobj.send(null); + } + + function loadScript(file) { + script = document.createElement("script"); + script.src = file; + document.body.appendChild(script); + } + + function parseJSON(json) { + CrystalDocs.initializeIndex(JSON.parse(json)); + } + + for(var i = 0; i < document.scripts.length; i++){ + var script = document.scripts[i]; + if (script.src && script.src.indexOf("js/doc.js") >= 0) { + if (script.src.indexOf("file://") == 0) { + // We need to support JSONP files for the search to work on local file system. + var jsonPath = script.src.replace("js/doc.js", "search-index.js"); + loadScript(jsonPath); + return; + } else { + var jsonPath = script.src.replace("js/doc.js", "index.json"); + loadJSON(jsonPath, parseJSON); + return; + } + } + } + console.error("Could not find location of js/doc.js"); +}; + +// Callback for jsonp +function crystal_doc_search_index_callback(data) { + CrystalDocs.initializeIndex(data); +} + +Navigator = function(sidebar, searchInput, list, leaveSearchScope){ + this.list = list; + var self = this; + + var performingSearch = false; + + document.addEventListener('CrystalDocs:searchStarted', function(){ + performingSearch = true; + }); + document.addEventListener('CrystalDocs:searchDebounceStarted', function(){ + performingSearch = true; + }); + document.addEventListener('CrystalDocs:searchPerformed', function(){ + performingSearch = false; + }); + document.addEventListener('CrystalDocs:searchDebounceStopped', function(event){ + performingSearch = false; + }); + + function delayWhileSearching(callback) { + if(performingSearch){ + document.addEventListener('CrystalDocs:searchPerformed', function listener(){ + document.removeEventListener('CrystalDocs:searchPerformed', listener); + + // add some delay to let search results display kick in + setTimeout(callback, 100); + }); + }else{ + callback(); + } + } + + function clearMoveTimeout() { + clearTimeout(self.moveTimeout); + self.moveTimeout = null; + } + + function startMoveTimeout(upwards){ + /*if(self.moveTimeout) { + clearMoveTimeout(); + } + + var go = function() { + if (!self.moveTimeout) return; + self.move(upwards); + self.moveTimout = setTimeout(go, 600); + }; + self.moveTimeout = setTimeout(go, 800);*/ + } + + function scrollCenter(element) { + var rect = element.getBoundingClientRect(); + var middle = sidebar.clientHeight / 2; + sidebar.scrollTop += rect.top + rect.height / 2 - middle; + } + + var move = this.move = function(upwards){ + if(!this.current){ + this.highlightFirst(); + return true; + } + var next = upwards ? this.current.previousElementSibling : this.current.nextElementSibling; + if(next && next.classList) { + this.highlight(next); + scrollCenter(next); + return true; + } + return false; + }; + + this.moveRight = function(){ + }; + this.moveLeft = function(){ + }; + + this.highlight = function(elem) { + if(!elem){ + return; + } + this.removeHighlight(); + + this.current = elem; + this.current.classList.add("current"); + }; + + this.highlightFirst = function(){ + this.highlight(this.list.querySelector('li:first-child')); + }; + + this.removeHighlight = function() { + if(this.current){ + this.current.classList.remove("current"); + } + this.current = null; + } + + this.openSelectedResult = function() { + if(this.current) { + this.current.click(); + } + } + + this.focus = function() { + searchInput.focus(); + searchInput.select(); + this.highlightFirst(); + } + + function handleKeyUp(event) { + switch(event.key) { + case "ArrowUp": + case "ArrowDown": + case "i": + case "j": + case "k": + case "l": + case "c": + case "h": + case "t": + case "n": + event.stopPropagation(); + clearMoveTimeout(); + } + } + + function handleKeyDown(event) { + switch(event.key) { + case "Enter": + event.stopPropagation(); + event.preventDefault(); + leaveSearchScope(); + self.openSelectedResult(); + break; + case "Escape": + event.stopPropagation(); + event.preventDefault(); + leaveSearchScope(); + break; + case "j": + case "c": + case "ArrowUp": + if(event.ctrlKey || event.key == "ArrowUp") { + event.stopPropagation(); + self.move(true); + startMoveTimeout(true); + } + break; + case "k": + case "h": + case "ArrowDown": + if(event.ctrlKey || event.key == "ArrowDown") { + event.stopPropagation(); + self.move(false); + startMoveTimeout(false); + } + break; + case "k": + case "t": + case "ArrowLeft": + if(event.ctrlKey || event.key == "ArrowLeft") { + event.stopPropagation(); + self.moveLeft(); + } + break; + case "l": + case "n": + case "ArrowRight": + if(event.ctrlKey || event.key == "ArrowRight") { + event.stopPropagation(); + self.moveRight(); + } + break; + } + } + + function handleInputKeyUp(event) { + switch(event.key) { + case "ArrowUp": + case "ArrowDown": + event.stopPropagation(); + event.preventDefault(); + clearMoveTimeout(); + } + } + + function handleInputKeyDown(event) { + switch(event.key) { + case "Enter": + event.stopPropagation(); + event.preventDefault(); + delayWhileSearching(function(){ + self.openSelectedResult(); + leaveSearchScope(); + }); + break; + case "Escape": + event.stopPropagation(); + event.preventDefault(); + // remove focus from search input + leaveSearchScope(); + sidebar.focus(); + break; + case "ArrowUp": + event.stopPropagation(); + event.preventDefault(); + self.move(true); + startMoveTimeout(true); + break; + + case "ArrowDown": + event.stopPropagation(); + event.preventDefault(); + self.move(false); + startMoveTimeout(false); + break; + } + } + + sidebar.tabIndex = 100; // set tabIndex to enable keylistener + sidebar.addEventListener('keyup', function(event) { + handleKeyUp(event); + }); + sidebar.addEventListener('keydown', function(event) { + handleKeyDown(event); + }); + searchInput.addEventListener('keydown', function(event) { + handleInputKeyDown(event); + }); + searchInput.addEventListener('keyup', function(event) { + handleInputKeyUp(event); + }); + this.move(); +}; + +CrystalDocs.initializeVersions = function () { + function loadJSON(file, callback) { + var xobj = new XMLHttpRequest(); + xobj.overrideMimeType("application/json"); + xobj.open("GET", file, true); + xobj.onreadystatechange = function() { + if (xobj.readyState == 4 && xobj.status == "200") { + callback(xobj.responseText); + } + }; + xobj.send(null); + } + + function parseJSON(json) { + CrystalDocs.loadConfig(JSON.parse(json)); + } + + $elem = document.querySelector("html > head > meta[name=\"crystal_docs.json_config_url\"]") + if ($elem == undefined) { + return + } + jsonURL = $elem.getAttribute("content") + if (jsonURL && jsonURL != "") { + loadJSON(jsonURL, parseJSON); + } +} + +CrystalDocs.loadConfig = function (config) { + var projectVersions = config["versions"] + var currentVersion = document.querySelector("html > head > meta[name=\"crystal_docs.project_version\"]").getAttribute("content") + + var currentVersionInList = projectVersions.find(function (element) { + return element.name == currentVersion + }) + + if (!currentVersionInList) { + projectVersions.unshift({ name: currentVersion, url: '#' }) + } + + $version = document.querySelector(".project-summary > .project-version") + $version.innerHTML = "" + + $select = document.createElement("select") + $select.classList.add("project-versions-nav") + $select.addEventListener("change", function () { + window.location.href = this.value + }) + projectVersions.forEach(function (version) { + $item = document.createElement("option") + $item.setAttribute("value", version.url) + $item.append(document.createTextNode(version.name)) + + if (version.name == currentVersion) { + $item.setAttribute("selected", true) + $item.setAttribute("disabled", true) + } + $select.append($item) + }); + $form = document.createElement("form") + $form.setAttribute("autocomplete", "off") + $form.append($select) + $version.append($form) +} + +document.addEventListener("DOMContentLoaded", function () { + CrystalDocs.initializeVersions() +}) + +var UsageModal = function(title, content) { + var $body = document.body; + var self = this; + var $modalBackground = document.createElement("div"); + $modalBackground.classList.add("modal-background"); + var $usageModal = document.createElement("div"); + $usageModal.classList.add("usage-modal"); + $modalBackground.appendChild($usageModal); + var $title = document.createElement("h3"); + $title.classList.add("modal-title"); + $title.innerHTML = title + $usageModal.appendChild($title); + var $closeButton = document.createElement("span"); + $closeButton.classList.add("close-button"); + $closeButton.setAttribute("title", "Close modal"); + $closeButton.innerText = '×'; + $usageModal.appendChild($closeButton); + $usageModal.insertAdjacentHTML("beforeend", content); + + $modalBackground.addEventListener('click', function(event) { + var element = event.target || event.srcElement; + + if(element == $modalBackground) { + self.hide(); + } + }); + $closeButton.addEventListener('click', function(event) { + self.hide(); + }); + + $body.insertAdjacentElement('beforeend', $modalBackground); + + this.show = function(){ + $body.classList.add("js-modal-visible"); + }; + this.hide = function(){ + $body.classList.remove("js-modal-visible"); + }; + this.isVisible = function(){ + return $body.classList.contains("js-modal-visible"); + } +} + + +document.addEventListener('DOMContentLoaded', function() { + var sessionStorage; + try { + sessionStorage = window.sessionStorage; + } catch (e) { } + if(!sessionStorage) { + sessionStorage = { + setItem: function() {}, + getItem: function() {}, + removeItem: function() {} + }; + } + + var repositoryName = document.querySelector('[name=repository-name]').getAttribute('content'); + var typesList = document.querySelector('.types-list'); + var searchInput = document.querySelector('.search-input'); + var parents = document.querySelectorAll('.types-list li.parent'); + + var scrollSidebarToOpenType = function(){ + var openTypes = typesList.querySelectorAll('.current'); + if (openTypes.length > 0) { + var lastOpenType = openTypes[openTypes.length - 1]; + lastOpenType.scrollIntoView(); + } + } + + scrollSidebarToOpenType(); + + var setPersistentSearchQuery = function(value){ + sessionStorage.setItem(repositoryName + '::search-input:value', value); + } + + for(var i = 0; i < parents.length; i++) { + var _parent = parents[i]; + _parent.addEventListener('click', function(e) { + e.stopPropagation(); + + if(e.target.tagName.toLowerCase() == 'li') { + if(e.target.className.match(/open/)) { + sessionStorage.removeItem(e.target.getAttribute('data-id')); + e.target.className = e.target.className.replace(/ +open/g, ''); + } else { + sessionStorage.setItem(e.target.getAttribute('data-id'), '1'); + if(e.target.className.indexOf('open') == -1) { + e.target.className += ' open'; + } + } + } + }); + + if(sessionStorage.getItem(_parent.getAttribute('data-id')) == '1') { + _parent.className += ' open'; + } + } + + var leaveSearchScope = function(){ + CrystalDocs.toggleResultsList(false); + window.focus(); + } + + var navigator = new Navigator(document.querySelector('.types-list'), searchInput, document.querySelector(".search-results"), leaveSearchScope); + + CrystalDocs.loadIndex(); + var searchTimeout; + var lastSearchText = false; + var performSearch = function() { + document.dispatchEvent(new Event("CrystalDocs:searchDebounceStarted")); + + clearTimeout(searchTimeout); + searchTimeout = setTimeout(function() { + var text = searchInput.value; + + if(text == "") { + CrystalDocs.toggleResultsList(false); + }else if(text == lastSearchText){ + document.dispatchEvent(new Event("CrystalDocs:searchDebounceStopped")); + }else{ + CrystalDocs.search(text); + navigator.highlightFirst(); + searchInput.focus(); + } + lastSearchText = text; + setPersistentSearchQuery(text); + }, 200); + }; + + if(location.hash.length > 3 && location.hash.substring(0,3) == "#q="){ + // allows directly linking a search query which is then executed on the client + // this comes handy for establishing a custom browser search engine with https://crystal-lang.org/api/#q=%s as a search URL + // TODO: Add OpenSearch description + var searchQuery = location.hash.substring(3); + history.pushState({searchQuery: searchQuery}, "Search for " + searchQuery, location.href.replace(/#q=.*/, "")); + searchInput.value = searchQuery; + document.addEventListener('CrystalDocs:loaded', performSearch); + } + + if (searchInput.value.length == 0) { + var searchText = sessionStorage.getItem(repositoryName + '::search-input:value'); + if(searchText){ + searchInput.value = searchText; + } + } + searchInput.addEventListener('keyup', performSearch); + searchInput.addEventListener('input', performSearch); + + var usageModal = new UsageModal('Keyboard Shortcuts', '' + + '' + ); + + 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) = [] of UInt64)","args_html":"(i : UInt64, nodes : Array(UInt64) = [] of UInt64)","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":[{"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":106,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/flat_tree.cr#L106"},"def":{"name":"spans","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, i]\nend\no = offset(i, d)\nwidth = (2 << d)\n[o * width, ((o + 1_u64) * width) - 2_u64]\n"}}],"macros":[],"types":[{"html_id":"flat_tree/FlatTree/Iterator","path":"FlatTree/Iterator.html","kind":"class","full_name":"FlatTree::Iterator","name":"Iterator","abstract":false,"superclass":{"html_id":"flat_tree/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"flat_tree/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"flat_tree/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"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":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"flat_tree/FlatTree","kind":"module","full_name":"FlatTree","name":"FlatTree"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(index=0_u64,offset=0_u64,factor=0_u64)-class-method","html_id":"new(index=0_u64,offset=0_u64,factor=0_u64)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"index","doc":null,"default_value":"0_u64","external_name":"index","restriction":""},{"name":"offset","doc":null,"default_value":"0_u64","external_name":"offset","restriction":""},{"name":"factor","doc":null,"default_value":"0_u64","external_name":"factor","restriction":""}],"args_string":"(index = 0_u64, offset = 0_u64, factor = 0_u64)","args_html":"(index = 0_u64, offset = 0_u64, factor = 0_u64)","location":{"filename":"src/iterator.cr","line_number":6,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L6"},"def":{"name":"new","args":[{"name":"index","doc":null,"default_value":"0_u64","external_name":"index","restriction":""},{"name":"offset","doc":null,"default_value":"0_u64","external_name":"offset","restriction":""},{"name":"factor","doc":null,"default_value":"0_u64","external_name":"factor","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(index, offset, factor)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"contains(i:UInt64)-instance-method","html_id":"contains(i:UInt64)-instance-method","name":"contains","doc":null,"summary":null,"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":31,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L31"},"def":{"name":"contains","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":"condition = i > @index ? i < (@index + (@factor / 2_u64)) : i < @index\ncondition ? i > (@index - (@factor / 2_u64)) : true\n"}},{"id":"factor:UInt64-instance-method","html_id":"factor:UInt64-instance-method","name":"factor","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : UInt64","args_html":" : UInt64","location":{"filename":"src/iterator.cr","line_number":4,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L4"},"def":{"name":"factor","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"UInt64","visibility":"Public","body":"@factor"}},{"id":"factor=(factor:UInt64)-instance-method","html_id":"factor=(factor:UInt64)-instance-method","name":"factor=","doc":null,"summary":null,"abstract":false,"args":[{"name":"factor","doc":null,"default_value":"","external_name":"factor","restriction":"UInt64"}],"args_string":"(factor : UInt64)","args_html":"(factor : UInt64)","location":{"filename":"src/iterator.cr","line_number":4,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L4"},"def":{"name":"factor=","args":[{"name":"factor","doc":null,"default_value":"","external_name":"factor","restriction":"UInt64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@factor = factor"}},{"id":"full_root(i:UInt64)-instance-method","html_id":"full_root(i:UInt64)-instance-method","name":"full_root","doc":null,"summary":null,"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":123,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L123"},"def":{"name":"full_root","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":"if i <= @index || (@index & 1_u64) > 0_u64\n return false\nend\nwhile i > ((@index + @factor) + (@factor / 2_u64))\n @index = @index + (@factor / 2_u64).to_u64\n @factor = @factor * 2_u64\n @offset = (@offset / 2_u64).to_u64\nend\ntrue\n"}},{"id":"index:UInt64-instance-method","html_id":"index:UInt64-instance-method","name":"index","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : UInt64","args_html":" : UInt64","location":{"filename":"src/iterator.cr","line_number":2,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L2"},"def":{"name":"index","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"UInt64","visibility":"Public","body":"@index"}},{"id":"index=(index:UInt64)-instance-method","html_id":"index=(index:UInt64)-instance-method","name":"index=","doc":null,"summary":null,"abstract":false,"args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"UInt64"}],"args_string":"(index : UInt64)","args_html":"(index : UInt64)","location":{"filename":"src/iterator.cr","line_number":2,"url":"https://github.com/dukeraphaelng/flat_tree/blob/v0.1.2/src/iterator.cr#L2"},"def":{"name":"index=","args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"UInt64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@index = index"}},{"id":"is_left-instance-method","html_id":"is_left-instance-method","name":"is_left","doc":"Is the iterator at a left sibling?","summary":"

Is the iterator at a left sibling?

","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