Language: English | Chinese

dart_interval

Build Status

This library provides data structure and operations for intervals in Dart.

Installation

Depend on it

Run this command:

With Dart:

dart pub add dart_interval

or add this to your project's pubspec.yml:

dependencies:
  dart_interval: ^0.1.1

Feature

  • Interval - The interval data structure.
  • IntervalSet - The interval merging.
  • Interval & Interval - The interval intersection calculation
  • Interval | Interval - The interval union calculation

Examples

Usage

Create a Interval:

import 'package:dart_interval/dart_interval.dart';

final v1 = Interval.between(1, 3, lowerClosed: false, upperClosed: false);

Merge the intervals:

final v1 = Interval.between(1, 3);
final v2 = Interval.between(2, 5);
final v3 = Interval.between(7, 9);
final set = IntervalSet([v1, v2, v3]);
print(set);
// output: [1, 5],[7, 9]

Interval intersection calculation:

print(v1 & v2);
// output: [2, 3]

Interval union calculation:

print(v1 | v2);
// output: [1, 5]

or

print(IntervalSet([v1, v2]));
// output: [1, 5]

Libraries

dart_interval