Giter Site home page Giter Site logo

coalesced_intervals's Introduction

coalesced_intervals: maintain maximally coalesced 1D intervals

sample usage diagram

extern crate coalesced_intervals;

fn main() {
    let mut ivals = coalesced_intervals::CoalescedIntervals::new();

    // Add `[0, 1)` and `[2, 3)` (there's a hole in the middle).
    ivals.add(0, 1);
    ivals.add(2, 3);
    assert_eq!(ivals.to_vec(), [(0, 1), (2, 3)]);

    // By adding `[1, 2)` we end up with a coalesced segment `[0, 3)`.
    ivals.add(1, 2);
    assert_eq!(ivals.to_vec(), [(0, 3)]);

    // We can see that the coalesced interval has partial overlap
    // with other related intervals.
    assert!(ivals.contains_partial(-1, 1));
    assert!(ivals.contains_partial(1, 2));
    assert!(ivals.contains_partial(2, 4));

    // We can ask for the interval containing some target value.
    assert_eq!(ivals.get_interval_containing(1), Some((0, 3)));
    assert_eq!(ivals.get_interval_containing(4), None);

    // We can ask for the interval that starts at-or-after some value.
    assert_eq!(ivals.get_first_start_from(-1), Some((0, 3)));
    assert_eq!(ivals.get_first_start_from(0), Some((0, 3)));
    assert_eq!(ivals.get_first_start_from(1), None);
}

coalesced_intervals's People

Contributors

cdleary avatar

Stargazers

Kevin Laeufer avatar

Watchers

 avatar Kevin Laeufer 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.