Code Monkey home page Code Monkey logo

strudel's Introduction

strudel

GitHub Actions Discord Twitter
Crate API API trunk

Insertion-ordered hash table suitable for embedding via FFI.

Status: Work in progress.

Strudel was conceived as a drop-in replacement for st_hash, a hash map implemented in C originally written by Peter Moore @ UCB and used in Ruby's implementation of the Hash core class.

This crate is an exercise in implementing an insertion-ordered hash map in Rust that cannot use the built-in Hasher infrastructure. The implementation uses Ruby's Hash backend and Python's dict as prior art.

This crate exports two types:

  • StHashMap is a hash map built on top of the high performance HashMap and Vec in Rust std. It is designed to implement the st_hash C API and be FFI-friendly. This map supports in-place updates of hash keys. No mutable iterators are provided.
  • StHashSet is a set that wraps an StHashMap like HashSet does in std.

The api and capi modules in strudel build on top of StHashMap to implement a compatible C API to st_hash. This API includes support for iterating over a mutable map and in-place updates of (key, value) pairs. These features distinguish it from the HashMap in Rust std.

Usage

Add this to your Cargo.toml:

[dependencies]
strudel = "1.0"

Building Ruby with Strudel

Strudel exports most of the symbols implemented by st.c in MRI 2.6.3. The included patch and some configure arguments can build the bootstrapping phase of MRI 2.6.3 with Strudel as the hash backend.

To build miniruby with Strudel, run:

./build.sh

build.sh requires autoconf 2.69. On macOS with Homebrew, this can be done with:

brew install [email protected]
PATH="/usr/local/opt/[email protected]/bin:$PATH" ./build.sh

The resulting Ruby is in ./build/ruby-strudel-build-root/miniruby. miniruby can run simple scripts involving Hash, for example:

$ ./build/ruby-strudel-build-root/miniruby -e 'h = {}' -e '1000.times { |i| h[i] = i }' -e 'puts h.length'
1000

miniruby successfully executes the benchmarks in benches.

NOTE: Strudel cannot build a full Ruby due to bugs in the implementation of the st_hash API.

License

strudel is licensed under the MIT License (c) Ryan Lopopolo.

This repository includes a vendored copy of st.h and st.c from Ruby 2.6.3, which is licensed under the Ruby license or BSD 2-clause license. See vendor/README.md for more details. These sources are not distributed on crates.io.

The st_hash implementation in Ruby includes the following notice:

/* This is a public domain general purpose hash table package
   originally written by Peter Moore @ UCB.

   The hash table data strutures were redesigned and the package was
   rewritten by Vladimir Makarov <[email protected]>.  */

strudel's People

Contributors

artichoke-ci avatar dependabot-preview[bot] avatar dependabot[bot] avatar lopopolo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

strudel's Issues

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.