Git Product home page Git Product logo

scheme-rbtrees's Introduction

What is this?

Red-black tree (http://en.wikipedia.org/wiki/Red-black_tree) implmentation for R6RS. The implementation is based on "Introduction to Algorithms" by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein.

Using Red-black tree

Put rbtree.ss to your LOADPATH.

(import (rnrs) (rbtree))
(let ([rb (make-rbtree string=? string<?)])
  (rbtree-get rb "abc" 'not-found) ;; => 'not-found
  (rbtree-set! rb "abc" 'val1)
  (rbtree-get rb "abc") ;; => 'val1
  (rbtree-delete! rb "abc")
  (rbtree-get rb "abc" 'not-found)) ;; => 'not-found

API

  • (make-rbtree key=? key<?)
    • Creates and returns an rbtree. The arguments key=? and key<? are both procedures that take two arguments, which are the keys. The key=? procedure should return #t if two arguments are equivalent, or #f otherwise. The key<? procedure should return #t if the first argument is strictly less than the second argument, or #f otherwise.
  • (rbtree? obj)
    • Returns #t if obj is rbtree, otherwise #f.
  • (rbtree-set! rbtree key value)
    • Inserts an entry with a key and corresponding value into rbtree. If there already exists an entry with a key which is equivalent (under key=?), the entry is modified to have value.
  • (rbtree-delete! rbtree key)
    • Deletes an entry with key from rbtree if such an entry exists, and returns #t otherwise #f.
  • (rbtree-get rbtree key . fallback)
    • Returns value associated with key. If key is not found and fallback is specified, returns fallback, otherwise raise error.
  • (rbtree-size rbtree)
    • Returns number of elementes.
  • (rbtree-contains? rbtree key)
    • Returns #t if rbtree has value associated with key, otherwise #f.
  • (rbtree-keys rb)
    • Returns keys in ascending order of the keys.

Author

Copyright (c) 2010 Higepon(Taro Minowa) [email protected]

License

New BSD License

scheme-rbtrees's People

Contributors

higepon avatar

Watchers

 avatar  avatar

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.