GithubHelp home page GithubHelp logo

segment-tree-erl's Introduction

segment-tree-erl

Implementation of Segment tree data structure in Erlang.

usage

1> c(segment_tree_make).
{ok,segment_tree_make}
2> 
2> segment_tree_make:make().
Recompile: interval
Recompile: segment_tree
Recompile: segment_tree_test
  All 3 tests passed.
ok
3> 
3> Sum = fun(X, null) -> X; (X, Y) -> X+Y end.
#Fun<erl_eval.12.82930912>
4> 
4> ST = segment_tree:new([1,2,3,4,5,6,7,8,9,10], Sum).
{segment_tree,{node,{node,{node,{node,{node,1,null,1,
                                            {interval,1,1}},
                                      {node,2,null,2,{interval,2,2}},
                                      3,
                                      {interval,1,2}},
                                {node,{node,3,null,3,{interval,3,3}},
                                      {node,4,null,4,{interval,4,4}},
                                      7,
                                      {interval,3,4}},
                                10,
                                {interval,1,4}},
                          {node,{node,{node,5,null,5,{interval,5,5}},
                                      {node,6,null,6,{interval,6,6}},
                                      11,
                                      {interval,5,6}},
                                {node,{node,7,null,7,{interval,7,7}},
                                      {node,8,null,8,{interval,8,8}},
                                      15,
                                      {interval,7,8}},
                                26,
                                {interval,5,8}},
                          36,
                          {interval,1,8}},
                    {node,{node,9,null,9,{interval,9,9}},
                          {node,10,null,10,{interval,10,10}},
                          19,
                          {interval,9,10}},
                    55,
                    {interval,1,10}},
              #Fun<erl_eval.12.82930912>}
5> 
5> segment_tree:fetch(interval:new(1,5), ST).
15
6> 
6> segment_tree:fetch(interval:new(1,4), ST).
10
7> 
7> segment_tree:fetch(interval:new(1,6), ST).
21

segment-tree-erl's People

Contributors

lagodiuk avatar

Stargazers

bhuztez avatar

Watchers

James Cloos 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.