Code Monkey home page Code Monkey logo

pfds's Introduction

Purely Functional Data Structures in Scheme -*- org -*-

About

pfds is a set of purely functional data structures written in R6RS Scheme. It has been tested with Racket, Guile 2, Vicare Scheme and IronScheme. Right now it contains

  • queues
  • deques
  • bbtrees
  • sets
  • dlists
  • priority search queues (psqs)
  • finger trees
  • sequences
  • heaps
  • hamts

with more to come, time permitting.

Installation

Just clone it somewhere on your $GUILE_LOAD_PATH and you’re done. Alternatively, a pkg-list.scm file is provided for use with the dorodango package manager.If you want to run the tests file, you will need trc-testing from the wak project.

Documentation

Documentation is provided at the top of the respective files. The queues and deques are based on the paper “Simple and Efficient Purely Functional Queues and Deques” by Chris Okasaki. The bbtrees and sets are based on the paper “Implementing Sets Efficiently in a Functional Language” by Stephen Adams.

Dlists are a well known trick in the functional programming community, going back to at least “A Novel Representation of Lists and its application to the Function “Reverse”” by John Hughes in 1984, although he does not give them this name. The trick is likely even older than that (he points to a paper by Bird), though I have not the knowledge to confirm this.

The implementation of priority search queues is described in “A Simple Implementation Technique for Priority Search Queues” by Ralf Hinze.

The heaps use a height-biased leftist tree implementation.

Finger trees are described in Finger trees: a simple general-purpose data structure by Ross Paterson and Ralf Hinze.

Hash Array Map Tries are described in the paper Ideal Hash Trees by Phil Bagwell.

Thanks

Thanks to Llewellyn Pritchard for testing this on IronScheme, to Marco Maggi for testing on Vicare Scheme, and to Andy Wingo for pointing out priority search queues to me, and prodding me into implementing them.

pfds's People

Contributors

ijp 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pfds's Issues

Exception in hamt-ref: Key is not in the hamt with irritant 13982459685072098939

Using chez scheme 9.5 and the following program:

(call-with-values (lambda () (let loop ((keys '())
                                        (hamt (make-hamt values equal?))
                                        (count 0))
                               (if (equal? count 10)
                                   (values keys hamt)
                                   (let ((value (random (expt 2 64))))
                                     (loop (cons value keys) (hamt-set hamt value #t) (+ 1 count))))))
  (lambda (keys hamt)
    (let loop ((keys keys))
      (unless (null? keys)
        (hamt-ref hamt (car keys))
        (loop (cdr keys))))))

Dead link in Readme

Hi Ian,
Your readme file gives a link to the wak module for unit-testing, however the link is broken and I'm unable to find the package elsewhere. I'm trying to test pfds on Chez.
Cheers!

bbtrees weight constant too high?

Hi! I just took a superficial look at the bbtrees implementation, because I was looking for the simple binary trees implementation and thought maybe that bb stands for "balanced binary". Anyway, I ended up reading about "trees of bounded balance" a.k.a. "weight balanced trees" on Wikipedia. There is states, that the balancing factor alpha should be much lower than 4:

[…] but not all values of α are appropriate; Nievergelt and Reingold proved that [… formula as picture …] is a necessary condition for the balancing algorithm to work. Later work showed a lower bound of 2⁄11 for α […] -- https://en.wikipedia.org/wiki/Weight-balanced_tree

So I wonder, if that weight in the code is used differently than the alpha in the wiki article, or whether it is a bad idea to set weight to 4.

It works with Vicare Scheme

I have verified (in my forked project) that pfds works fine with Vicare Scheme as is, without source modifications.

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.