Git Product home page Git Product logo

psds's Introduction

Prefix-Sum Data Structures

Given an integer array A[0..n), the prefix-sum problem asks for a data structure built from A that supports for any 0 โ‰ค i < n:

  • sum(i) = A[0] + ... + A[i];
  • update(i, x) which sets A[i] to A[i] + x.
  • access(i) = A[i].

The library implements the following solutions to solve the problem.

  • binary Segment-Tree (top-down and bottom-up)
  • b-ary Segment-Tree (b > 2)
  • Fenwick-Tree
  • b-ary Fenwick-Tree
  • blocked Fenwick-Tree with blocks of b keys
  • truncated Fenwick-Tree with blocks of leaves of b keys

For a description and anlysis of all these data structures, see the paper Practical Trade-Offs for the Prefix-Sum Problem (SPE 2020).

Please, cite the paper if you use this library.

Compiling the code

The code is tested on Linux with gcc 7.4 and 9.2.1; on Mac 10.14 with clang 10.0.0 and 11.0.0. To build the code, CMake is required.

Clone the repository with

git clone --recursive https://github.com/jermp/psds.git

If you have cloned the repository without --recursive, you will need to perform the following commands before compiling:

git submodule init
git submodule update

To compile the code for a release environment (see file CMakeLists.txt for the used compilation flags), it is sufficient to do the following:

mkdir build
cd build
cmake ..
make -j

By default, SIMD AVX instructions are enabled (flag -DDISABLE_AVX=Off). If you want to disable them (although your compiler has proper support), you can compile with

cmake .. -DDISABLE_AVX=On
make -j

For the best of performance, we recommend compiling with (default configuration):

cmake .. -DCMAKE_BUILD_TYPE=Release -DUSE_SANITIZERS=Off -DDISABLE_AVX=Off
make -j

For a testing environment, use the following instead:

mkdir debug_build
cd debug_build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DUSE_SANITIZERS=On
make -j

Benchmarks

To benchmark the running time of sum and update for the disired data structure, use the program src/perf. Running the program without arguments will show what arguments are required. (See also the file src/perf.cpp for a list of available data structure types.)

Below we show some examples.

  • The command

      ./perf ft sum
    

will benchmark the speed of sum queries for the Fenwick Tree data structure (ft), by varying the size of the input array from 250 to 1,000,000,000.

  • The command

      ./perf sts_256 update -i 40
    

will benchmark the speed of updates for the SIMD Segment Tree with branching factor 256 (sts_256) for an array of size floor((1.25893)^40) = 2,511,886.

Unit tests

The unit tests are written using doctest.

After compilation, it is advised to run the unit tests with:

make test

psds's People

Contributors

jermp 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

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

clayne

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.