MyNixOS website logo
Description

Randomized Binary Search Trees.

This package contains an implementation of a Randomized Binary Search Tree.

Randomized Binary Search Trees are guaranteed to be Random BST irrespective of the number of insert / delete operations. This guarantees logarithmic time operations (with a constant factor) in the worst case.

rbst: efficient randomized binary search trees

Hackage GitHub CI Build Status MIT license

Efficient implementation of the Randomized Binary Search Trees data structure.

When to use this package?

Randomized Binary Search Trees are useful when you cannot make assumptions on the input distribution but you still need fast (logarithmic time complexity) insert/lookup/delete/at/union/etc. operations. It is guaranteed efficient self-balancing. Below you can find the table of time complexity for all operations (where n is the size of the tree):

OperationTime complexityDescription
sizeO(1)Count elements in the tree
lookupO(log n)Access by key
insertO(log n)Insert an element with the given key
deleteO(log n)Delete the element associated to the given key
takeO(log n)Take first i-th elements
dropO(log n)Drop first i-th elements
atO(log n)Access by index
removeO(log n)Remove the i-th element
unionO(m + n)Union of two trees
intersectionO(m + n)Intersection of two trees
subtractionO(m + n)Subtraction of two trees
differenceO(m + n)Symmetric difference of two trees

Usage example

>>> :set -XOverlodadeLists
>>> import GHC.Exts
>>> import RBST

-- Manually created
>>> let tree =  insert 'a' 1
              $ insert 'b' 2
              $ insert 'c' 3
              $ insert 'd' 4
              $ insert 'e' 5
              $ empty

-- Using 'OverloadedLists'
>>> let tree = (fromList $ zip ['a'..'e'] [1..5]) :: RBST Char Int
>>> RBST.prettyPrint tree
         ('b',2) [5]
                 ╱╲
                ╱  ╲
               ╱    ╲
              ╱      ╲
             ╱        ╲
            ╱          ╲
           ╱            ╲
          ╱              ╲
         ╱                ╲
('a',1) [1]       ('d',4) [3]
                       ╱╲
                      ╱  ╲
                     ╱    ╲
                    ╱      ╲
                   ╱        ╲
                  ╱          ╲
            ('c',3) [1] ('e',5) [1]

-- Queries
>>> size tree
5
>>> lookup 'd'
Just 4
>>> lookup 'a' $ insert 'a' 7 tree
Just 7
>>> lookup 'd' (delete 'd' tree)
Nothing

How to use it

In order to start using rbst in your project, you will need to set it up with the two easy steps:

  1. Add the dependency in your project's .cabal file:

     build-depends: base ^>= 4.14
                  , rbst ^>= 0.0.0.0
    
  2. In the module where you wish to use rbst, add the (qualified) import:

    import qualified RBST
    

Stack

  1. If rbst is not available on your current Stackage resolver yet, you can still use it by adding the following in the extra-deps section of your stack.yaml file:

    extra-deps:
      - rbst-0.0.0.0
    
  2. Then you can add it as a dependency in your package.yaml file as usual:

    library:
      dependencies:
        - rbst
    

Acknowledgement

To the authors C. Martinez and S. Roura.

To D. Kovanikov and his project implicit treap.

Icons designed by Freepik from www.flaticon.com.

Metadata

Version

0.0.0.1

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows