Coder Social home page Coder Social logo

palatable / shoki Goto Github PK

View Code? Open in Web Editor NEW
38.0 8.0 11.0 657 KB

Purely functional data structures in Java

Home Page: https://palatable.github.io/shoki/

License: MIT License

Java 100.00%
purely-functional-data-structures persistent-data-structure immutable java hamt hashmap okasaki data-structures hash-array-mapped-trie immutable-datastructures

shoki's People

Contributors

7h3kk1d avatar jnape avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shoki's Issues

Memoizable, computable sizes / hash codes

Computing the size and the hash code adds significant constant overhead for methods like StrictStack#cons, whereas if the size and hash code were computations that could be memoized, they would be amortized O(1) and have a negligible time cost on these hot path operations.

StrictStack / StrictQueue sizeInfo time/space complexity

Currently both StrictStack and StrictQueue use an amortized O(1) time cost and O(1) space cost for their sizes. If StrictStack could gain an O(1) time/space complexity, and if StrictQueue delegated to StrictStack, it would achieve the same complexity. This should be doable with a single additional wrapper node in StrictStack that was carried the size along with the spine.

Heaps

min/max heaps seem like a reasonable next addition. Okasaki's binomial heap should translate nicely.

Shoki smart constructors support element type widening

Since shoki data structures are immutable, this should type-check:

interface Animal {}
class Dog implements Animal {}
class Cat implements Animal {}

StrictStack<Animal> animals = Shoki.strictStack(StrictStack.<Dog>strictStack());

...and perform no additional allocations.

Safe, array-backed RandomAccess Sequence

An array-backed immutable sequence would natively support random access Natural -> Maybe a and would be very fast indeed, provided it could be made safe such that the array was fully encapsulated by the data type. This would mean that no public construction patterns should allow wrapping of an array: arrays should be fully existentialized behind a series of exported minimal interactions. As an example:

public static Vector<A> create(Consumer<Consumer<A>> withAdd) {
    // ...
}

This interface would receive a Consumer that would itself receive a Consumer representing an add invocation, so a valid argument might do something like:

Vector<Integer> ints = create(add -> {
    add.accept(1);
    add.accept(2);
    add.accept(3);
});

Each add would result in the internal array being updated, and after withAdd was finished, some flag would be flipped to specify the array is no longer candidate for update, so if someone did something accidental and caustic, like leaked add into an atomic reference, add could not be used after initialization to violate the immutable properties of the Vector.

This data type would likely be eventually supplanted by a BAMT, so it may or may not be worth adding in the short term.

LazyList

LazyLists, lists with lazy, memoized tail's, are generally useful and specifically useful as the backbone for RTDs.

SortedCollection slices

SortedCollections should offer slice methods that rely on poset inequalities (e.g. java.util.NavigableMap#headMap/tailMap)

Shoki optics

Maybe as a separate library, but they're needed

sizes can still overflow

StrictStack#sizeInfo, for example, calls abs(size(this)); size returns long. This has to use an adder that auto-widens the numeric type; probably BigInteger to be safe.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.