Code Monkey home page Code Monkey logo

hamt's Introduction

hamt

GitHub Action Codecov Go Report Card License

For the old any-based API, refer to the main branch.

Immutable and Memory Efficient Maps and Sets in Go.

This package hamt provides immutable collection types of maps (associative arrays) and sets implemented as Hash-Array Mapped Tries (HAMTs). All operations of the collections, such as insert and delete, are immutable and create new ones keeping original ones unmodified.

Hash-Array Mapped Trie (HAMT) is a data structure popular as a map (a.k.a. associative array or dictionary) or set. Its immutable variant is adopted widely by functional programming languages like Scala and Clojure to implement immutable and memory-efficient associative arrays and sets.

Installation

go get github.com/raviqqe/hamt/v2

Documentation

GoDoc

Technical notes

The implementation canonicalizes tree structures of HAMTs by eliminating intermediate nodes during delete operations as described in the CHAMP paper.

References

License

The Unlicense

hamt's People

Contributors

asido avatar dependabot-preview[bot] avatar dependabot[bot] avatar raviqqe avatar zenhack 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  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  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  avatar

hamt's Issues

Imperative methods

Problem

  • We currently use a functional style for all the interfaces of persistent data structures.
    • This is primarily the easiness of writing programs in a functional style.
  • We implicitly use option types and take references of keys and values through pointer references in methods of persistent data structures.
  • It's not optimal for performance.
    • e.g. We can't know if entries are inserted/removed or not at the same time!
    • Go is primarily a system programming language but not a functional programming language!
  • The interface will be inconsistent with methods providing destructive updates, which might be implemented in the future.

Examples

func (m Map[K, V]) Find(k K) *V {
  ...
}

func (m Map[K, V]) Insert(k K, v V) Map[K, V] {
  ...
}

Solution

  • Migrate to imperative interfaces of persistent data structures.
    • An implementation is in #25.

Examples

func (m Map[K, V]) Find(k K) (V, bool) {
  ...
}

func (m Map[K, V]) Insert(k K, v V) (Map[K, V], bool) {
  ...
}

References

  • The original discussion is in #16.
  • im, which is probably the most popular persistent data structure library in Rust adopts imperative interfaces for their implementations.
    • I guess it's because Rust users usually care more about performance than easiness in programming.

Is it thread-safe?

After quickly inspecting the source code it looks like the hamp maps should be thread-safe. Can you confirm this?

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.