#range #merge #overlap #rangeset

merged_range2

rangeset that can merge overlapping ranges (fork of merged_range)

1 stable release

new 1.0.0 Jan 15, 2025

#651 in Algorithms

46 downloads per month

Apache-2.0

30KB
672 lines

Note: this crate is a fork of the original merged_range crate, which is not maintained anymore. More details in the issue #1.

merged_range2

A crate that can merge overlapping ranges.

Apache licensed crates.io docs.rs CI

Overview

merged_range2 is used to query whether the given range is contained in the existing range. If it is contained, return true, otherwise return false. It uses a sorted vector to store ranges, it can merge the new range with the existing ranges.

Insert and query time complexity is both O(logn).

Example

Add the dependency to Cargo.toml

[dependencies]
merged_range2 = "1.0.0"

Then use it in your code

use merged_range2::MergedRange;

let mut mr = MergedRange::new();
mr.insert_range(&(1..10));
mr.insert_range(&(5..20));

assert_eq!(mr.contains_range(&(3..15)), true);
assert_eq!(mr.contains_range(&(10..21)), false);

License

This project is licensed under the Apache license.

Dependencies

~32KB