2.0.12-beta • Published 7 years ago

lib-rrbit v2.0.12-beta

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

lib-rrbit

styled with prettier is a set core operations and helpers for use on Vectors(i.e Arrays) implementing a Relaxed-Radix-Balance technique from the 2015 paper

this library adopts a Bring-Your-Own base factory(class) to easily allow seamless integrations across multiple environments.

If your looking for a immutable collection implementation, considering looking at our sister project instead: rrbit-js

About

lib-rrbit aims to ease your transition to immutable collections, by letting you decide the API for you needs, while handling all the bit-fiddling and dark magic of persistence algorithms behind the scenes. A typical well rounded List class can be quickly put together in less than 300 LOC, while adding around 10k(unminified) to your project.

Want your List's to return Optionals or Maybes instead of nulls? try it!

Need a List API that mimic's your your platform's (e.g. Java's ArrayList or Elm's Array), knock it out in an afternoon!

This project hope to bring more options to JS that help make it easy to focus on business logic and worry less about shared mutable state

Advantages

Every data structure has advantages and disadvantages depending on the use case. RRB data structures offer several unique advantages:

  • immutable every operations returns a new Vector
  • structural sharing Vectors safely share internal data, minimizing memory usage. Great for historical use cases(e.g. undo/redo stacks)
  • efficient prepend AND appends Vectors apply changes to an internal local cache or "focus" before merging them into the trie. instead of using a "tail" or "head", we use a movable "focus"

Great for queues

  • fast splitting slicing operations only require a trimming of indexes, no array copy required!
  • fast concat appending operations can often be completed with only and index update, requiring extremely little to no array copying

Operations

rrbit only provides a few operations to perform on Vectors efficiently. All other collection operations can be build from these:

  1. append - adds a single element
  2. update - updates a single
  3. take - keep first n elements, deleting everything after
  4. drop - delete first n elements, keeping the rest
  5. nth - get the element at given position
  6. appendAll - join two RRB Vectors together efficiently

Performance

RRB Vectors are able to keep up with or outperform their mutable Array counterparts on almost all operations save append. With a suitable Builder class or helper to convert from your favorite collection type, even this limitation can be mitigated

comparisons with other frameworks
frameworkops per sectype
native push 1k immutable with es6 spread335.75 op/spush/append
immutable-js append 1k1815.33 op/spush/append
mori vector append 1k4395.11 op/spush/append
rrbit 1k3407.20 op/spush/append
rrbit 1k (Occulance enabled)8012.65 op/spush/append
rrbit 1k (Builder mode)19410.27 op/spush/append
rrbit 1k (Cassowry: Occulance enabled)22929.65 op/spush/append
rrbit 1k (Cassowry: Builder mode)69948.84 op/spush/append
native mutating push 1k(max possible)203927.41 op/spush/append
--------------------------------------------------------------------------
mori iteration speed18052.66 op/sfor of loop
immutable-js iteration speed18811.21 op/sfor of loop
rrbit iteration speed33367.63 op/sfor of loop
native array iteration speed17023.14 op/sfor of loop
native forEach speed79403.02 op/sforEach
rrbit reduce63164.88 op/sreduce
lodash v4 forEach73609.82 op/sforEach
native for loop1203400.09 op/sfor
rrbit cassowry reduce speed1751116.63 op/sreduce
--------------------------------------------------------------------------
native push 1k immutable with es6 spread352.55 op/sunshift/prepend
immutable-js unshift 1k947.95 op/sunshift/prepend
mori prepend 1k2598.45 op/sunshift/prepend
native mutating unshift 1k8237.15 op/sunshift/prepend
rrbit (Cassowry: prepend) 1k17420.03 op/sunshift/prepend
--------------------------------------------------------------------------
native slice half28064.72 op/stake/slice
rrbit take1361882.81 op/stake/slice
immutable-js take half2100578.67 op/stake/slice
mori take half2396771.15 op/stake/slice
rrbit (Cassowry) take3260573.92 op/stake/slice
2.0.12-beta

7 years ago

2.0.11-beta

7 years ago

2.0.10-beta

7 years ago

2.0.9-beta

7 years ago

2.0.8-beta

7 years ago

2.0.7-beta

7 years ago

2.0.6-beta

7 years ago

2.0.5-beta

7 years ago

2.0.4-beta

7 years ago

2.0.3-beta

7 years ago

2.0.2-beta

7 years ago

2.0.1-beta

7 years ago

2.0.0-beta

7 years ago

1.0.6

7 years ago

1.0.4

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago