multi_range 2.1.1 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -2
- data/CHANGELOG.md +52 -44
- data/README.md +3 -3
- data/gemfiles/Gemfile +1 -1
- data/lib/multi_range/version.rb +1 -1
- data/lib/multi_range.rb +27 -13
- data/multi_range.gemspec +0 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d67638eab33c3a377488c4fb32c0e33f8385eab6d743d3f37f7476f20f94b97
|
4
|
+
data.tar.gz: 198971530fc824d45690f92b4c45013a8bd58ddb204e9a84a2971bdda20ed1fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 752b8eff047ed5b7dded92afbdf612fc0e2f63b119fba141421d07e2983d8fd9aa79914cb60e890414362d6e84497b2737145dc18166299f772a74e74ffb231d
|
7
|
+
data.tar.gz: 48e47778eaf9066be35983239fdf073e011010ba2555d1a2b4a48d4c507db7e9d419a64503f469a54e16363be61e5e300977f364d02c91f12d56ad3028ef315f
|
data/.github/workflows/ruby.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,44 +1,52 @@
|
|
1
|
-
## Change Log
|
2
|
-
|
3
|
-
### [v2.
|
4
|
-
- [#
|
5
|
-
- [#
|
6
|
-
- [#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
- [#
|
13
|
-
|
14
|
-
|
15
|
-
- [#
|
16
|
-
|
17
|
-
### [
|
18
|
-
- [#
|
19
|
-
- [#
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
- [#
|
27
|
-
- [#
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
- [#
|
36
|
-
- [#
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
- [#
|
41
|
-
|
42
|
-
### v0.0.
|
43
|
-
- [#
|
44
|
-
- [#
|
1
|
+
## Change Log
|
2
|
+
|
3
|
+
### [v2.2.0](https://github.com/khiav223577/multi_range/compare/v1.3.2...v2.2.0) 2023/10/21
|
4
|
+
- [#34](https://github.com/khiav223577/multi_range/pull/34) Fix: wrong empty range check which causes some differences to be dropped (@khiav223577)
|
5
|
+
- [#33](https://github.com/khiav223577/multi_range/pull/33) Fix: result should not be empty when intersection with inclusive range with one element (@khiav223577)
|
6
|
+
- [#32](https://github.com/khiav223577/multi_range/pull/32) Drop the support of ruby 2.2 (@khiav223577)
|
7
|
+
|
8
|
+
### [v2.1.1](https://github.com/khiav223577/multi_range/compare/v2.1.0...v2.1.1) 2021/08/07
|
9
|
+
- [#26](https://github.com/khiav223577/multi_range/pull/26) Fix: unexpected float value when sample an one-element range (@khiav223577)
|
10
|
+
|
11
|
+
### [v2.1.0](https://github.com/khiav223577/multi_range/compare/v2.0.0...v2.1.0) 2021/03/17
|
12
|
+
- [#24](https://github.com/khiav223577/multi_range/pull/24) Avoid empty sub ranges (@GerritSe)
|
13
|
+
- [#25](https://github.com/khiav223577/multi_range/pull/25) Do not publish code coverage for PRs from forks (@khiav223577)
|
14
|
+
- [#22](https://github.com/khiav223577/multi_range/pull/22) Migrating from Travis CI to GitHub Actions (@khiav223577)
|
15
|
+
- [#21](https://github.com/khiav223577/multi_range/pull/21) Fix: test files should not be included in coverage (@khiav223577)
|
16
|
+
|
17
|
+
### [v2.0.0](https://github.com/khiav223577/multi_range/compare/v1.3.0...v2.0.0) 2020/11/19
|
18
|
+
- [#19](https://github.com/khiav223577/multi_range/pull/19) Implement intersection (@chrisnankervis)
|
19
|
+
- [#20](https://github.com/khiav223577/multi_range/pull/20) Drop support for Ruby 1.8 and 1.9 (@khiav223577)
|
20
|
+
- [#17](https://github.com/khiav223577/multi_range/pull/17) Refactoring - increase MAINTAINABILITY (@khiav223577)
|
21
|
+
|
22
|
+
### [v1.3.0](https://github.com/khiav223577/multi_range/compare/v1.2.0...v1.3.0) 2020/10/20
|
23
|
+
- [#16](https://github.com/khiav223577/multi_range/pull/16) Implement contain_overlaps? method (@khiav223577)
|
24
|
+
|
25
|
+
### [v1.2.0](https://github.com/khiav223577/multi_range/compare/v1.1.0...v1.2.0) 2020/10/16
|
26
|
+
- [#15](https://github.com/khiav223577/multi_range/pull/15) Add test cases to test union float ranges (@khiav223577)
|
27
|
+
- [#14](https://github.com/khiav223577/multi_range/pull/14) Support float ranges (@khiav223577)
|
28
|
+
|
29
|
+
### [v1.1.0](https://github.com/khiav223577/multi_range/compare/v1.0.0...v1.1.0) 2020/10/15
|
30
|
+
- [#13](https://github.com/khiav223577/multi_range/pull/13) Rename flatten => merge_overlaps (@khiav223577)
|
31
|
+
|
32
|
+
### [v1.0.0](https://github.com/khiav223577/multi_range/compare/v0.0.4...v1.0.0) 2020/10/15
|
33
|
+
- [#12](https://github.com/khiav223577/multi_range/pull/12) Implement #overlaps? (@khiav223577)
|
34
|
+
- [#11](https://github.com/khiav223577/multi_range/pull/11) Support difference other multi_range object (@khiav223577)
|
35
|
+
- [#10](https://github.com/khiav223577/multi_range/pull/10) Add frozen_string_literal (@khiav223577)
|
36
|
+
- [#9](https://github.com/khiav223577/multi_range/pull/9) Implement range union (@khiav223577)
|
37
|
+
- [#8](https://github.com/khiav223577/multi_range/pull/8) Support initializing a MultiRange object with unsorted ranges (@khiav223577)
|
38
|
+
|
39
|
+
### [v0.0.4](https://github.com/khiav223577/multi_range/compare/v0.0.3...v0.0.4) 2020/03/26
|
40
|
+
- [#7](https://github.com/khiav223577/multi_range/pull/7) Add flatten method (@khiav223577)
|
41
|
+
|
42
|
+
### [v0.0.3](https://github.com/khiav223577/multi_range/compare/v0.0.2...v0.0.3) 2020/03/02
|
43
|
+
- [#6](https://github.com/khiav223577/multi_range/pull/6) freeze internal ranges variable (@khiav223577)
|
44
|
+
- [#5](https://github.com/khiav223577/multi_range/pull/5) Add min, max, to_a method (@khiav223577)
|
45
|
+
|
46
|
+
### [v0.0.2](https://github.com/khiav223577/multi_range/compare/v0.0.1...v0.0.2) 2020/03/02
|
47
|
+
- [#4](https://github.com/khiav223577/multi_range/pull/4) Add each, map, index_with methods (@khiav223577)
|
48
|
+
- [#3](https://github.com/khiav223577/multi_range/pull/3) Support passing integer as range (@khiav223577)
|
49
|
+
|
50
|
+
### v0.0.1 2020/03/01
|
51
|
+
- [#2](https://github.com/khiav223577/multi_range/pull/2) Support Ruby 1.8.7 (@khiav223577)
|
52
|
+
- [#1](https://github.com/khiav223577/multi_range/pull/1) Implement MultiRange (@khiav223577)
|
data/README.md
CHANGED
@@ -8,9 +8,9 @@
|
|
8
8
|
|
9
9
|
## Supports
|
10
10
|
|
11
|
-
- Ruby 2.
|
12
|
-
|
13
|
-
For Ruby
|
11
|
+
- Ruby 2.3 ~ 2.7
|
12
|
+
- For Ruby 1.8.x and 1.9.x, please use multi_range < v2.0.0
|
13
|
+
- For Ruby 2.0 ~ 2.2, please use multi_range < v2.2.0
|
14
14
|
|
15
15
|
## Installation
|
16
16
|
|
data/gemfiles/Gemfile
CHANGED
data/lib/multi_range/version.rb
CHANGED
data/lib/multi_range.rb
CHANGED
@@ -62,7 +62,9 @@ class MultiRange
|
|
62
62
|
other_ranges = MultiRange.new(other).merge_overlaps.ranges
|
63
63
|
tree = IntervalTree::Tree.new(other_ranges)
|
64
64
|
intersected_ranges = merge_overlaps.ranges.flat_map do |range|
|
65
|
-
|
65
|
+
# A workaround for the issue: https://github.com/greensync/interval-tree/issues/17
|
66
|
+
query = (range.first == range.last) ? range.first : range
|
67
|
+
matching_ranges_converted_to_exclusive = tree.search(query) || []
|
66
68
|
|
67
69
|
# The interval tree converts interval endings to exclusive, so we need to restore the original
|
68
70
|
matching_ranges = matching_ranges_converted_to_exclusive.map do |matching_range_converted_to_exclusive|
|
@@ -205,14 +207,14 @@ class MultiRange
|
|
205
207
|
sub_range2_begin = if other.exclude_end?
|
206
208
|
other.end
|
207
209
|
else
|
208
|
-
other.end
|
210
|
+
other.end.is_a?(Float) ? other.end.next_float : other.end + 1
|
209
211
|
end
|
210
212
|
|
211
213
|
sub_range2 = range.exclude_end? ? sub_range2_begin...range.end : sub_range2_begin..range.end
|
212
214
|
|
213
215
|
sub_ranges = []
|
214
|
-
sub_ranges << sub_range1 if
|
215
|
-
sub_ranges << sub_range2 if
|
216
|
+
sub_ranges << sub_range1 if not empty_range?(sub_range1)
|
217
|
+
sub_ranges << sub_range2 if not empty_range?(sub_range2)
|
216
218
|
return sub_ranges
|
217
219
|
end
|
218
220
|
|
@@ -223,14 +225,26 @@ class MultiRange
|
|
223
225
|
return true
|
224
226
|
end
|
225
227
|
|
226
|
-
def intersect_two_ranges(
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
end
|
228
|
+
def intersect_two_ranges(range1, range2)
|
229
|
+
start_range = range_with_larger_start(range1, range2)
|
230
|
+
end_range = range_with_smaller_end(range1, range2)
|
231
|
+
return start_range.begin...end_range.end if end_range.exclude_end?
|
232
|
+
return start_range.begin..end_range.end
|
233
|
+
end
|
234
|
+
|
235
|
+
def empty_range?(range)
|
236
|
+
range.begin > range.end || (range.begin == range.end && range.exclude_end?)
|
237
|
+
end
|
238
|
+
|
239
|
+
def range_with_larger_start(range1, range2)
|
240
|
+
return range1 if range1.begin > range2.begin
|
241
|
+
return range2
|
242
|
+
end
|
243
|
+
|
244
|
+
def range_with_smaller_end(range1, range2)
|
245
|
+
return range1 if range1.end < range2.end
|
246
|
+
return range2 if range1.end > range2.end
|
247
|
+
return range1 if range1.exclude_end?
|
248
|
+
return range2
|
235
249
|
end
|
236
250
|
end
|
data/multi_range.gemspec
CHANGED
@@ -39,7 +39,6 @@ Gem::Specification.new do |spec|
|
|
39
39
|
spec.add_development_dependency 'bundler', '>= 1.17', '< 3.x'
|
40
40
|
spec.add_development_dependency 'rake', '>= 10.5.0'
|
41
41
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
42
|
-
spec.add_development_dependency 'minitest-color', '~> 0.0.2'
|
43
42
|
spec.add_development_dependency 'backports', '~> 3.15.0'
|
44
43
|
|
45
44
|
spec.add_dependency 'roulette-wheel-selection', '~> 1.1.1'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_range
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- khiav reoy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,20 +58,6 @@ dependencies:
|
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '5.0'
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: minitest-color
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - "~>"
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: 0.0.2
|
68
|
-
type: :development
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - "~>"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: 0.0.2
|
75
61
|
- !ruby/object:Gem::Dependency
|
76
62
|
name: backports
|
77
63
|
requirement: !ruby/object:Gem::Requirement
|