All Projects โ†’ functional-data-structure โ†’ finger-tree

functional-data-structure / finger-tree

Licence: AGPL-3.0 License
๐ŸŒต Finger tree data structure for JavaScript

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to finger-tree

js-data-structures
๐ŸŒฟ Data structures for JavaScript
Stars: โœญ 56 (+180%)
Mutual labels:  computer-science, immutable, functional, agpl
Immutable Tuple
Immutable finite list objects with constant-time equality testing (===) and no memory leaks.
Stars: โœญ 29 (+45%)
Mutual labels:  immutable, functional, persistent
Imtools
Fast and memory-efficient immutable collections and helper data structures
Stars: โœญ 85 (+325%)
Mutual labels:  immutable, persistent, data-structures
Typed Immutable
Immutable and structurally typed data
Stars: โœญ 263 (+1215%)
Mutual labels:  immutable, functional, persistent
Immer
Postmodern immutable and persistent data structures for C++ โ€” value semantics at scale
Stars: โœญ 1,935 (+9575%)
Mutual labels:  immutable, persistent, data-structures
grand central
State-management and action-dispatching for Ruby apps
Stars: โœญ 20 (+0%)
Mutual labels:  immutable, functional
rrbit
An Immutable vectors/lists/arrays library using the Relaxed Radix Balancing(RRB) technique
Stars: โœญ 12 (-40%)
Mutual labels:  immutable, persistent
Algorithms-Java
A collection of common algorithms and data structures implemented in Java.
Stars: โœญ 141 (+605%)
Mutual labels:  computer-science, trees
cs-resources
Curated Computer Science and Programming Resource Guide
Stars: โœญ 42 (+110%)
Mutual labels:  computer-science, data-structures
Fucking Algorithm
ๅˆท็ฎ—ๆณ•ๅ…จ้ ๅฅ—่ทฏ๏ผŒ่ฎคๅ‡† labuladong ๅฐฑๅคŸไบ†๏ผEnglish version supported! Crack LeetCode, not only how, but also why.
Stars: โœญ 99,705 (+498425%)
Mutual labels:  computer-science, data-structures
babl
JSON templating on steroids
Stars: โœญ 29 (+45%)
Mutual labels:  immutable, functional
coding-interview-guide
A systematic coding interview guide
Stars: โœญ 76 (+280%)
Mutual labels:  computer-science, data-structures
transmute
kind of like lodash but works with Immutable
Stars: โœญ 35 (+75%)
Mutual labels:  immutable, functional
Coding Interview University
A complete computer science study plan to become a software engineer.
Stars: โœญ 204,859 (+1024195%)
Mutual labels:  computer-science, data-structures
Javascript Algorithms
๐Ÿ“ Algorithms and data structures implemented in JavaScript with explanations and links to further readings
Stars: โœญ 133,406 (+666930%)
Mutual labels:  computer-science, data-structures
peds
Type safe persistent/immutable data structures for Go
Stars: โœญ 57 (+185%)
Mutual labels:  immutable, functional
fastener
Functional Zipper for manipulating JSON
Stars: โœญ 54 (+170%)
Mutual labels:  immutable, functional
treecko
A collection of functional and immutable helpers for working with tree data structures.
Stars: โœญ 31 (+55%)
Mutual labels:  immutable, functional
rrbit-js
No description or website provided.
Stars: โœญ 11 (-45%)
Mutual labels:  immutable, persistent
Java-Questions-and-Solutions
This repository aims to solve and create new problems from different spheres of coding. A path to help students to get access to solutions and discuss their doubts.
Stars: โœญ 34 (+70%)
Mutual labels:  data-structures, trees

๐ŸŒต @functional-data-structure/finger-tree

Finger trees for JavaScript. See docs. Parent is @functional-data-structure/persistent.

data FingerTree x = Empty
                  | Single x
                  | Deep ( Digit x ) ( FingerTree ( Node x ) ) ( Digit x )

License Version Tests Dependencies Dev dependencies GitHub issues Downloads

Code issues Code maintainability Code coverage (cov) Code technical debt Documentation Package size

๐Ÿ‘ฉโ€๐Ÿซ API reference

The data structure is fully persistent: All methods are pure functions that do not modify their object.

The parent project shows how specialized persistent data structures can be build on top of those methods.

๐ŸŒต Definition of a Tree

data Tree x = Empty
            | Single x
            | Deep ( Digit x ) ( Tree ( Node x ) ) ( Digit x )

๐Ÿ“ Definition of a Measure

Measure = (
  plus = ( x , x ) -> m
  measure = x -> m
  zero = ( ) => m
)

Example of a Measure

The following measure will compute the size of each subtree.

const counter = {
  plus : ( x , y ) => x + y ,
  measure : x => 1 ,
  zero : ( ) => 0 ,
} ;

See also @functional-abstraction/measure for more examples of measures and see @functional-data-structure/persistent for examples of data structures that can be build on top of this abstraction.

๐Ÿ“ฆ How to import

โš ๏ธ The code requires regeneratorRuntime to be defined, for instance by importing regenerator-runtime/runtime.

First, require the polyfill at the entry point of your application:

require( 'regenerator-runtime/runtime' ) ;
// or
import 'regenerator-runtime/runtime.js' ;

Then require what you need from the exported object, for instance the two main API functions from and empty:

const { from , empty } = require( '@functional-data-structure/finger-tree' ) ;
// or
import { from , empty } from '@functional-data-structure/finger-tree' ;

๐Ÿ‘ถ How to create a Tree

empty(Measure) -> Tree

Create an empty tree from a measure object.

let tree = empty( counter ) ;

from(Measure, Iterable) -> Tree

Create a tree from a measure object and an iterable.

let tree = from( counter , 'abc' ) ;

โ“ Predicates

Tree#measure() -> m

Returns the measure of the tree.

if ( tree.measure() > 1 ) ...

Tree#isEmpty() -> Boolean

Returns true if the tree is empty, false otherwise.

return tree.isEmpty() ? 'empty' : 'not empty' ;

๐Ÿง‚ Add values

Tree#push(x) -> Tree

Returns a new tree with an additional value as the new right-most value.

tree = tree.push('k');

Tree#cons(x) -> Tree

Returns a new tree with an additional value as the new left-most value.

tree = tree.cons('g');

Tree#append(Iterable) -> Tree

Equivalent to applying push to each value of the iterable in order.

tree.append( 'www' ) ;

Tree#prepend(Iterable) -> Tree

Equivalent to applying cons to each value of the iterable in reverse order.

tree.prepend( 'xyz' ) ;

๐Ÿ• Slice

Tree#head() -> x

Returns the left-most value in the tree.

let head = tree.head() ; // 'a'

Tree#last() -> x

Returns the right-most value in the tree.

let last = tree.last() ; // 'b'

Tree#init() -> Tree

Returns a new tree without the right-most value.

while ( ! tree.isEmpty() ) tree = tree.init() ;

Tree#tail() -> Tree

Returns a new tree without the left-most value.

while ( ! tree.isEmpty() ) tree = tree.tail() ;

๐ŸŒ— Merge

Tree#concat(Tree) -> Tree

Returns the concatenation of two trees.

tree = tree.concat( tree );

๐Ÿ’” Split

The following methods allow you to efficiently split a tree at the value where the measure crosses a given threshold.

Tree#splitTree(Function, m) -> [ Tree , x , Tree ]

Split the tree into a left tree, a middle value, and a right tree according to a predicate on the measure of the tree increased by a constant measure m. The predicate must be monotone, false then true, on prefixes of the values in left-to-right order. The middle value x is the value for which the predicate switches from false to true.

let [ left , middle , right ] = tree.splitTree( measure => measure > 1 , 1 ) ;

Tree#split(Function) -> [ Tree , Tree ]

Split the tree into a left tree and a right tree according to a predicate on the measure of the tree. The predicate must be monotone, false then true, on prefixes of the values in left-to-right order. The left-most value of the right tree is the value for which the predicate switches from false to true.

let [ left , right ] = tree.split( measure => measure > 2 ) ;

Tree#takeUntil(Function) -> Tree

Returns the left tree of Tree#split.

let left = tree.takeUntil( measure => measure > 2 ) ;

Tree#dropUntil(Function) -> Tree

Returns the right tree of Tree#split.

let right = tree.dropUntil( measure => measure > 2 ) ;

๐Ÿ›ธ Visit

Tree[Symbol.iterator]() -> Iterable

Returns an iterator on the values of the tree in left-to-right order.

for ( const x of tree ) console.log( x ) ;

Tree#reversed() -> Iterable

Returns an iterator on the values of the tree in right-to-left order.

for ( const x of tree.reversed() ) console.log( x ) ;

๐Ÿ“œ References

๐Ÿ”— Links

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].