npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@datkt/flattree

v0.2.1

Published

Kotlin port of @mafintosh's flat-tree functions to map a binary tree to a list.

Downloads

5

Readme

datkt.flattree

Port of @mafintosh's flat-tree functions to map a binary tree to a list.

Installation

The datkt.flattree package an be installed with NPM.

$ npm install @datkt/flattree

Prerequisites

  • Kotlin/Native and the konanc command line program.
  • @datkt/konanc-config

Usage

## Compile a program in 'main.kt' and link flattree libraries found in `node_modules/`
$ konanc main.kt $(konanc-config -clr @datkt/flattree) -o main.kexe
$ ./main.kexe

where main.kt might be

import datkt.flattree.*

fun main(args: Array<String>) {
  val tree = Tree()
  tree.parent(0L, null) // 1L
  tree.parent(2L, null) // 1L
  tree.parent(1L, null) // 3L
}

API

index = ftIndex(depth: Long, offset: Long): Long

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

parentIndex = tree.parent(index: Long, depth: Long?): Long

Returns the index of the parent element in tree

siblingIndex = tree.sibling(index: Long, depth: Long?): Long

Returns the index of this elements sibling

children = tree.children(index: Long, depth: Long?): Array<Long>

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

range = tree.spans(index: Long, depth: Long?): Array<Long>

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

index = tree.leftSpan(index: Long, depth: Long?): Long

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

index = tree.rightSpan(index: Long, depth: Long?): Long

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

count = tree. count(index: Long, depth: Long?): Long

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

depth = ftDepth(index: Long): Long

Returns the depth of an element

offset = ftOffset(index: Long, depth: Long?): Long

Returns the relative offset of an element

roots = tree.fullRoots(index: Long, result: Array<Long>?): Array<Long>

Returns a list of all the full roots (subtrees where all nodes have either 2 or 0 children) < index. For example fullRoots(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.

index = iterator.next(): Long

Move the iterator the next item in the tree.

index = iterator.prev(): Long

Move the iterator the prev item in the tree.

iterator.seek(index: Long)

Move the iterator the this specific tree index.

index = iterator.parent(): Long

Move the iterator to the current parent index

index = iterator.leftChild(): Long

Move the iterator to the current left child index.

index = iterator.rightChild(): Long

Move the iterator to the current right child index.

index = iterator.leftSpan(): Long

Move the iterator to the current left span index.

index = iterator.rightSpan(): Long

Move the iterator to the current right span index.

bool = iterator.isLeft(): Boolean

Is the iterator at a left sibling?

bool = iterator.isRight(): Boolean

Is the iterator at a right sibling?

index = iterator.sibling(): Long

Move the iterator to the current sibling

See Also

  • https://github.com/mafintosh/flat-tree

License

MIT