Skip to content

Commit 197ac83

Browse files
committed
Update to Dart 3 and bump to 0.4.0
1 parent d368e63 commit 197ac83

File tree

10 files changed

+65
-58
lines changed

10 files changed

+65
-58
lines changed

.github/workflows/analyze.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
name: analyze
22

33
on:
4+
workflow_dispatch:
45
push:
5-
branches: [ master ]
6+
branches: [ main ]
67
pull_request:
7-
branches: [ master ]
8+
branches: [ main ]
89

910
jobs:
1011
package-analysis:
1112
runs-on: ubuntu-latest
1213
steps:
1314
- name: Git checkout
14-
uses: actions/checkout@v2
15+
uses: actions/checkout@v4.1.1
1516
- name: Analyze package
1617
uses: axel-op/dart-package-analyzer@stable
1718
with:

.github/workflows/build.yml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
name: build
22

33
on:
4+
workflow_dispatch:
45
push:
5-
branches: [ master ]
6+
branches: [ main ]
67
pull_request:
7-
branches: [ master ]
8-
8+
branches: [ main ]
99
jobs:
1010
build:
1111
runs-on: ubuntu-latest
1212
container:
13-
image: google/dart:latest
13+
image: dart:stable
1414
steps:
1515
- name: Git checkout
16-
uses: actions/checkout@v2
16+
uses: actions/checkout@v4.1.1
1717
- name: Install dependencies
18-
run: pub get
19-
- name: Run tests
20-
run: pub run test
21-
- name: Measure coverage
22-
run: pub run test_cov
18+
run: dart pub get
19+
- name: Install coverage tool
20+
run: dart pub global activate coverage
21+
- name: Run tests with coverage
22+
run: dart pub global run coverage:test_with_coverage
2323
- name: Upload coverage
24-
uses: codecov/codecov-action@v1.0.6
24+
uses: codecov/codecov-action@v3
25+
env:
26+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2527
with:
2628
token: ${{secrets.CODECOV_TOKEN}}
2729
file: coverage/lcov.info

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
.pub/
3131
build/
3232
pubspec.lock
33-
.test_coverage.dart
34-
lcov.info
35-
coverage_badge.svg
33+
coverage/
3634

3735
# Android related
3836
**/android/**/gradle-wrapper.jar

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## [0.4.1] - 2023-11-20
2+
3+
* Update pipeline, actions, and test coverage. (@slightfoot)
4+
5+
## [0.4.0] - 2023-11-20
6+
7+
* Migrated to Dart 3 (@slightfoot)
8+
19
## [0.3.0] - 2021-04-22
210

311
* Migrated to null-safety (thanks @scarnett!)

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
[![Flutter Community: interval_tree](https://fluttercommunity.dev/_github/header/interval_tree)](https://github.com/fluttercommunity/community)
2+
13
# Interval Tree for Dart
24

35
[![pub](https://img.shields.io/pub/v/interval_tree.svg)](https://pub.dev/packages/interval_tree)
46
[![license: MIT](https://img.shields.io/badge/license-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5-
![build](https://github.com/jpnurmi/interval_tree/workflows/build/badge.svg)
6-
[![codecov](https://codecov.io/gh/jpnurmi/interval_tree/branch/main/graph/badge.svg)](https://codecov.io/gh/jpnurmi/interval_tree)
7+
[![build](https://github.com/fluttercommunity/interval_tree/actions/workflows/build.yml/badge.svg)](https://github.com/fluttercommunity/interval_tree/actions/workflows/build.yml)
8+
[![codecov](https://codecov.io/gh/fluttercommunity/interval_tree/branch/main/graph/badge.svg)](https://codecov.io/gh/fluttercommunity/interval_tree)
79

810
A [Dart][1] implementation of an [interval tree][2], with support for
911
calculating unions, intersections, and differences between individual

analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:lints/recommended.yaml

lib/interval_tree.dart

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ import 'package:quiver/collection.dart';
8484
/// final interval = ivt.Interval(1, 2);
8585
///
8686
@immutable
87-
class Interval extends Comparable<Interval> {
87+
class Interval implements Comparable<Interval> {
8888
/// Creates an interval between [start] and [end] points.
8989
Interval(dynamic start, dynamic end)
9090
: _start = _min(start, end),
@@ -101,10 +101,6 @@ class Interval extends Comparable<Interval> {
101101
/// Returns the end point of this interval.
102102
dynamic get end => _end;
103103

104-
/// Returns the length of this interval.
105-
@deprecated
106-
dynamic get length => _end - _start;
107-
108104
/// Returns `true` if this interval contains the [other] interval.
109105
bool contains(Interval other) => other.start >= start && other.end <= end;
110106

@@ -247,7 +243,9 @@ class Interval extends Comparable<Interval> {
247243
String toString() => '[$start, $end]';
248244

249245
static int _cmp(dynamic a, dynamic b) => Comparable.compare(a, b);
246+
250247
static dynamic _min(dynamic a, dynamic b) => _cmp(a, b) < 0 ? a : b;
248+
251249
static dynamic _max(dynamic a, dynamic b) => _cmp(a, b) > 0 ? a : b;
252250

253251
final dynamic _start;
@@ -327,13 +325,15 @@ class IntervalTree with IterableMixin<Interval> {
327325
factory IntervalTree.of(Iterable<Interval?> intervals) =>
328326
IntervalTree()..addAll(intervals);
329327

328+
final _tree = AvlTreeSet<Interval>(comparator: Comparable.compare);
329+
330330
/// Adds an [interval] into this tree.
331-
void add(dynamic? interval) {
332-
Interval? iv = _asInterval(interval);
331+
void add(dynamic interval) {
332+
var iv = _asInterval(interval);
333333
if (iv == null) return;
334334

335335
bool joined = false;
336-
BidirectionalIterator<Interval?> it = _tree.fromIterator(iv);
336+
var it = _tree.fromIterator(iv);
337337
while (it.movePrevious()) {
338338
final union = _tryJoin(it.current, iv);
339339
if (union == null) break;
@@ -365,7 +365,7 @@ class IntervalTree with IterableMixin<Interval> {
365365
void remove(dynamic interval) {
366366
final iv = _asInterval(interval);
367367

368-
BidirectionalIterator<Interval> it = _tree.fromIterator(iv!);
368+
var it = _tree.fromIterator(iv!);
369369
while (it.movePrevious()) {
370370
final current = it.current;
371371
if (!_trySplit(it.current, iv)) break;
@@ -405,7 +405,7 @@ class IntervalTree with IterableMixin<Interval> {
405405
final result = IntervalTree();
406406
if (isEmpty || other.isEmpty) result;
407407
for (final iv in other) {
408-
BidirectionalIterator<Interval> it = _tree.fromIterator(iv);
408+
var it = _tree.fromIterator(iv);
409409
while (it.movePrevious() && iv.intersects(it.current)) {
410410
result.add(iv.intersection(it.current));
411411
}
@@ -418,15 +418,15 @@ class IntervalTree with IterableMixin<Interval> {
418418
}
419419

420420
@override
421-
bool contains(dynamic interval) {
422-
final iv = _asInterval(interval);
423-
BidirectionalIterator<Interval?> it = _tree.fromIterator(iv!);
424-
while (it.movePrevious() && iv.intersects(it.current!)) {
425-
if (it.current!.contains(iv)) return true;
421+
bool contains(Object? element) {
422+
final iv = _asInterval(element);
423+
var it = _tree.fromIterator(iv!);
424+
while (it.movePrevious() && iv.intersects(it.current)) {
425+
if (it.current.contains(iv)) return true;
426426
}
427427
it = _tree.fromIterator(iv, inclusive: false);
428-
while (it.moveNext() && it.current!.intersects(iv)) {
429-
if (it.current!.contains(iv)) return true;
428+
while (it.moveNext() && it.current.intersects(iv)) {
429+
if (it.current.contains(iv)) return true;
430430
}
431431
return false;
432432
}
@@ -457,13 +457,13 @@ class IntervalTree with IterableMixin<Interval> {
457457

458458
/// Returns a bidirectional iterator that allows iterating the intervals.
459459
@override
460-
BidirectionalIterator<Interval> get iterator => _tree.iterator;
460+
TreeIterator<Interval> get iterator => _tree.iterator;
461461

462462
/// Returns a string representation of the tree.
463463
@override
464-
String toString() => 'IntervalTree' + super.toString();
464+
String toString() => 'IntervalTree${super.toString()}';
465465

466-
Interval? _asInterval(dynamic? interval) {
466+
Interval? _asInterval(dynamic interval) {
467467
if (interval is Iterable) {
468468
if (interval.length != 2 || interval.first is Iterable) {
469469
throw ArgumentError('$interval is not an interval');
@@ -490,7 +490,4 @@ class IntervalTree with IterableMixin<Interval> {
490490
_tree.addAll([...?a.difference(b)]);
491491
return true;
492492
}
493-
494-
final AvlTreeSet<Interval> _tree =
495-
AvlTreeSet<Interval>(comparator: Comparable.compare);
496493
}

pubspec.yaml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
name: interval_tree
2-
version: 0.3.0
2+
version: 0.4.1
3+
maintainer: Simon Lightfoot (@slightfoot)
34
description: >-
45
A non-overlapping interval tree with support for calculating unions,
56
intersections, and differences between individual intervals and entire
67
trees.
7-
homepage: https://github.com/jpnurmi/interval_tree
8-
repository: https://github.com/jpnurmi/interval_tree
9-
issue_tracker: https://github.com/jpnurmi/interval_tree/issues
8+
homepage: https://github.com/fluttercommunity/interval_tree
9+
repository: https://github.com/fluttercommunity/interval_tree
10+
issue_tracker: https://github.com/fluttercommunity/interval_tree/issues
1011

1112
environment:
12-
sdk: '>=2.12.0 <3.0.0'
13+
sdk: '>=3.0.0 <4.0.0'
14+
1315
dependencies:
14-
meta: ^1.1.8
15-
quiver: ^3.0.1
16+
lints: ^3.0.0
17+
meta: ^1.11.0
18+
quiver: ^3.2.1
19+
1620
dev_dependencies:
17-
test: ^1.14.2
18-
test_cov: ^1.0.1
21+
test: ^1.24.3

test/interval_test.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ void main() {
3939
expect(Interval(1, -10).end, 1);
4040
});
4141

42-
test('length', () {
43-
expect(Interval(0, 0).length, 0);
44-
expect(Interval(-1, 1).length, 2);
45-
expect(Interval(1, 10).length, 9);
46-
expect(Interval(1, -10).length, 11);
47-
});
48-
4942
test('copy', () {
5043
final interval = Interval(0, 10);
5144
final copy = Interval.copy(interval);

test/interval_tree_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: collection_methods_unrelated_type
2+
13
/*
24
* Copyright (c) 2020 J-P Nurmi <jpnurmi@gmail.com>
35
*

0 commit comments

Comments
 (0)