interval_set 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e161c0a76439ab2e80de1567dfd7a4b4613a7340
4
- data.tar.gz: 83fcb9323b1b21792bb8db45aaf2b1d202117055
3
+ metadata.gz: c2ef851831406ab98e7b1e6f61f7a1d17dba05d0
4
+ data.tar.gz: 968ef3f0967f7ebef2e1966feb7b60cbfb97ad2f
5
5
  SHA512:
6
- metadata.gz: 46f4169b72e0a1ce24cffedf7fe56f3fd058ecff04d4db92660ad77e94816844d63b044cf21e363a7abf73ffc0765d64df3cadd2dc0e45a90566fed54de0b0a0
7
- data.tar.gz: c99c4d21c9bdd2a03b23d5cc7e904dd6222a3884e38142bf90789abaa0e64a5910ff62dc3e7a5fc5083cc029f8f4d0ceb2bee6b285e6a9d8c2dbfd1efc7ef055
6
+ metadata.gz: d369094a12515dba67e051057c1ec9f09242b9c935e8224a8c5af836937555e815eecd6001793108a6bc19bbd20f6e637b894789c30b3089f4da4c401231d31a
7
+ data.tar.gz: 138af7c1155d6c9572b9fd299f84604d288d1238df417356149a9a87819305957b92c7084aa82a058a4a421d91dda61b135a4c8ba902c6b96fb74d88b5ee8edd
data/.travis.yml CHANGED
@@ -1,5 +1,12 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0
7
+ - 2.1
8
+ - 2.2
9
+ - 2.3
4
10
  - 2.4.1
11
+ - ruby-head
5
12
  before_install: gem install bundler -v 1.16.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- interval_set (0.1.0)
4
+ interval_set (0.1.1)
5
5
  treemap-fork (~> 1.0, >= 1.0.4.2)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # IntervalSet
2
2
 
3
+ [![Build Status](https://travis-ci.org/rjasper/ruby-interval_set.svg?branch=master)](https://travis-ci.org/rjasper/ruby-interval_set)
4
+
3
5
  IntervalSet implements a set of sorted non-overlapping ranges. A range's start is always interpreted as inclusive while the end is exclusive.
4
6
 
5
7
  ## Installation
@@ -27,89 +29,89 @@ http://www.rubydoc.info/gems/interval_set
27
29
  Create a interval set:
28
30
 
29
31
  ```ruby
30
- IntervalSet.new # -> []
31
- IntervalSet[] # -> []
32
- IntervalSet[0...1] # -> [0...1]
33
- IntervalSet[0...1, 2...3] # -> [0...1, 2...3]
34
- IntervalSet[0...1, 1...2] # -> [0...2]
32
+ IntervalSet.new # -> []
33
+ IntervalSet[] # -> []
34
+ IntervalSet[0...1] # -> [0...1]
35
+ IntervalSet[0...1, 2...3] # -> [0...1, 2...3]
36
+ IntervalSet[0...1, 1...2] # -> [0...2]
35
37
 
36
38
  array = [0...1, 2...3]
37
- IntervalSet[*array] # -> [0...1, 2...3]
39
+ IntervalSet[*array] # -> [0...1, 2...3]
38
40
  ```
39
41
 
40
42
  Add a range:
41
43
 
42
44
  ```ruby
43
- IntervalSet.new << (0...1) # -> [0...1]
44
- IntervalSet.new.add(0...1) # -> [0...1]
45
-
46
- i = IntervalSet.new # -> []
47
- i << (0...1) # -> [0...1]
48
- i << (2...3) # -> [0...1, 2...3]
49
- i << (1...2) # -> [0...3]
50
- i << (-1...4) # -> [-1...4]
45
+ IntervalSet.new << (0...1) # -> [0...1]
46
+ IntervalSet.new.add(0...1) # -> [0...1]
47
+
48
+ i = IntervalSet.new # -> []
49
+ i << (0...1) # -> [0...1]
50
+ i << (2...3) # -> [0...1, 2...3]
51
+ i << (1...2) # -> [0...3]
52
+ i << (-1...4) # -> [-1...4]
51
53
  ```
52
54
 
53
55
  Remove a range:
54
56
 
55
57
  ```ruby
56
- i = IntervalSet[0...10] # -> [0...10]
57
- i >> (2...8) # -> [0...2, 8...10]
58
- i.remove(0...2) # -> [8...10]
58
+ i = IntervalSet[0...10] # -> [0...10]
59
+ i >> (2...8) # -> [0...2, 8...10]
60
+ i.remove(0...2) # -> [8...10]
59
61
  ```
60
62
 
61
63
  Get bounds:
62
64
 
63
65
  ```ruby
64
- i = IntervalSet[0...1, 2...3] # -> [0...1, 2...3]
65
- i.min # -> 0
66
- i.max # -> 3
67
- i.bounds # -> 0...3
66
+ i = IntervalSet[0...1, 2...3] # -> [0...1, 2...3]
67
+ i.min # -> 0
68
+ i.max # -> 3
69
+ i.bounds # -> 0...3
68
70
  ```
69
71
 
70
72
  Check empty:
71
73
 
72
74
  ```ruby
73
- IntervalSet[].empty? # -> true
75
+ IntervalSet[].empty? # -> true
74
76
 
75
- i = IntervalSet[0...1] # -> [0...1]
76
- i.empty? # -> false
77
- i >> (0...1) # -> []
78
- i.empty? # -> true
77
+ i = IntervalSet[0...1] # -> [0...1]
78
+ i.empty? # -> false
79
+ i >> (0...1) # -> []
80
+ i.empty? # -> true
79
81
  ```
80
82
 
81
83
  Count ranges:
82
84
 
83
85
  ```ruby
84
- i = IntervalSet[] # -> []
85
- i.count # -> 0
86
- i << (0...1) # -> [0...1]
87
- i.count # -> 1
88
- i << (2...3) # -> [0...1, 2...3]
89
- i.count # -> 2
90
- i << (1...2) # -> [0...3]
91
- i.count # -> 1
86
+ i = IntervalSet[] # -> []
87
+ i.count # -> 0
88
+ i << (0...1) # -> [0...1]
89
+ i.count # -> 1
90
+ i << (2...3) # -> [0...1, 2...3]
91
+ i.count # -> 2
92
+ i << (1...2) # -> [0...3]
93
+ i.count # -> 1
92
94
  ```
93
95
 
94
96
  Check inclusion:
95
97
 
96
98
  ```ruby
97
- i = IntervalSet[0...1] # -> [0...1]
99
+ i = IntervalSet[0...1] # -> [0...1]
98
100
 
99
- i.include?(0) # -> true
100
- i.include?(0.5) # -> true
101
- i.include?(1) # -> false ; a range's end is exclusive
101
+ i.include?(0) # -> true
102
+ i.include?(0.5) # -> true
103
+ i.include?(1) # -> false ; a range's end is exclusive
102
104
  ```
103
105
 
104
106
  Check intersection:
105
107
 
106
108
  ```ruby
107
- i = IntervalSet[0...1] # -> [0...1]
109
+ i = IntervalSet[0...1] # -> [0...1]
108
110
 
109
111
  # Ranges only need a single common element with the interval set
110
- i.intersect?(0...1) # -> true
111
- i.intersect?(0...2) # -> true
112
- i.intersect?(1...2) # -> false ; the start of a range is inclusive but the end exclusive
112
+ i.intersect?(0...1) # -> true
113
+ i.intersect?(0...2) # -> true
114
+ i.intersect?(1...2) # -> false ; the start of a range is inclusive but the end exclusive
113
115
 
114
116
  # The same applies for interval sets
115
117
  i.intersect?(IntervalSet[0...1]) # -> true
@@ -188,7 +190,7 @@ end
188
190
  Shift by a given amount:
189
191
 
190
192
  ```ruby
191
- IntervalSet[0...1].shift(1) # -> [1...2]
193
+ IntervalSet[0...1].shift(1) # -> [1...2]
192
194
  ```
193
195
 
194
196
  Note that `shift(0)` will not be optimized since IntervalSet does not assume numbers as element type.
@@ -199,7 +201,7 @@ Buffer left and right:
199
201
  IntervalSet[1...2].buffer(1, 2) # -> [0...4]
200
202
 
201
203
  # Negative values will shrink the ranges:
202
- IntervalSet[0...4].buffer(-1, -2) # -> [1...2]
204
+ IntervalSet[0...4].buffer(-1, -2) # -> [1...2]
203
205
  IntervalSet[1...2].buffer(-0.5, -0.5) # -> []
204
206
  ```
205
207
 
@@ -220,22 +222,22 @@ IntervalSet[0...1, 10...12] * IntervalSet[-2...1, 1...2] # -> [-2...3, 8...14]
220
222
  Copy another interval set:
221
223
 
222
224
  ```ruby
223
- a = IntervalSet[0...1] # -> [0...1]
224
- b = IntervalSet[2...3] # -> [2...3]
225
+ a = IntervalSet[0...1] # -> [0...1]
226
+ b = IntervalSet[2...3] # -> [2...3]
225
227
 
226
228
  a.copy(b)
227
229
 
228
- a # -> [2...3]
229
- b # -> [2...3]
230
+ a # -> [2...3]
231
+ b # -> [2...3]
230
232
  ```
231
233
 
232
234
  Clone another interval set:
233
235
 
234
236
  ```ruby
235
- a = IntervalSet[0...1] # -> [0...1]
236
- b = a.clone # -> [0...1]
237
+ a = IntervalSet[0...1] # -> [0...1]
238
+ b = a.clone # -> [0...1]
237
239
  b << (2...3)
238
- b # -> [0...1, 2...3]
240
+ b # -> [0...1, 2...3]
239
241
  ```
240
242
 
241
243
  Use other types:
@@ -245,10 +247,10 @@ a = Date.parse('2000-01-01')
245
247
  b = Date.parse('2000-01-02')
246
248
  c = Date.parse('2000-01-03')
247
249
 
248
- i = IntervalSet[a...b] # -> [2000-01-01...2000-01-02]
250
+ i = IntervalSet[a...b] # -> [2000-01-01...2000-01-02]
249
251
 
250
- i << (b...c) # -> [2000-01-01...2000-01-03]
251
- i.shift!(1) # -> [2000-01-02...2000-01-04]
252
+ i << (b...c) # -> [2000-01-01...2000-01-03]
253
+ i.shift!(1) # -> [2000-01-02...2000-01-04]
252
254
  ```
253
255
 
254
256
 
data/interval_set.gemspec CHANGED
@@ -13,6 +13,8 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = 'https://github.com/rjasper/ruby-interval_set'
14
14
  spec.license = 'MIT'
15
15
 
16
+ spec.required_ruby_version = '>= 1.9.2'
17
+
16
18
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
19
  f.match(%r{^(test|spec|features)/})
18
20
  end
@@ -1,3 +1,3 @@
1
1
  class IntervalSet
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/lib/interval_set.rb CHANGED
@@ -1,4 +1,4 @@
1
- require_relative 'interval_set/version'
1
+ require 'interval_set/version'
2
2
  require 'treemap-fork'
3
3
 
4
4
  # IntervalSet implements a set of sorted non-overlapping ranges.
@@ -7,13 +7,13 @@ class IntervalSet
7
7
  include Enumerable
8
8
 
9
9
  # Builds a new IntervalSet from the supplied ranges. Overlapping ranges will be merged.
10
- # IntervalSet[] # -> []
11
- # IntervalSet[0...1] # -> [0...1]
12
- # IntervalSet[0...1, 2...3] # -> [0...1, 2...3]
13
- # IntervalSet[0...1, 1...2] # -> [0...2]
10
+ # IntervalSet[] # -> []
11
+ # IntervalSet[0...1] # -> [0...1]
12
+ # IntervalSet[0...1, 2...3] # -> [0...1, 2...3]
13
+ # IntervalSet[0...1, 1...2] # -> [0...2]
14
14
  #
15
15
  # array = [0...1, 2...3]
16
- # IntervalSet[*array] # -> [0...1, 2...3]
16
+ # IntervalSet[*array] # -> [0...1, 2...3]
17
17
  #
18
18
  # @param ranges [Range[]] a list of ranges to be added to the new IntervalSet
19
19
  # @return [IntervalSet] a new IntervalSet containing the supplied ranges.
@@ -107,7 +107,7 @@ class IntervalSet
107
107
 
108
108
  # Returns +true+ if this IntervalSet contains the given element.
109
109
  #
110
- # i = IntervalSet[0...1] # -> [0...1]
110
+ # i = IntervalSet[0...1] # -> [0...1]
111
111
  #
112
112
  # i.include?(0) # -> true
113
113
  # i.include?(0.5) # -> true
@@ -239,7 +239,7 @@ class IntervalSet
239
239
  # Returns +true+ if the given object has any common elements with
240
240
  # this IntervalSet.
241
241
  #
242
- # i = IntervalSet[0...1] # -> [0...1]
242
+ # i = IntervalSet[0...1] # -> [0...1]
243
243
  #
244
244
  # # Ranges only need a single common element with the interval set
245
245
  # i.intersect?(0...1) # -> true
@@ -265,7 +265,7 @@ class IntervalSet
265
265
 
266
266
  # Counts the number of ranges contained by this IntervalSet.
267
267
  #
268
- # i = IntervalSet[] # -> []
268
+ # i = IntervalSet[] # -> []
269
269
  # i.count # -> 0
270
270
  # i << (0...1) # -> [0...1]
271
271
  # i.count # -> 1
@@ -282,10 +282,10 @@ class IntervalSet
282
282
  # Adds the other object's elements to this IntervalSet.
283
283
  # The result is stored in this IntervalSet.
284
284
  #
285
- # IntervalSet.new.add(0...1) # -> [0...1]
286
- # IntervalSet.new << (0...1) # -> [0...1]
285
+ # IntervalSet.new.add(0...1) # -> [0...1]
286
+ # IntervalSet.new << (0...1) # -> [0...1]
287
287
  #
288
- # i = IntervalSet.new # -> []
288
+ # i = IntervalSet.new # -> []
289
289
  # i << (0...1) # -> [0...1]
290
290
  # i << (2...3) # -> [0...1, 2...3]
291
291
  # i << (1...2) # -> [0...3]
@@ -310,7 +310,7 @@ class IntervalSet
310
310
  # Removes the other object's elements from this IntervalSet.
311
311
  # The result is stored in this IntervalSet.
312
312
  #
313
- # i = IntervalSet[0...10] # -> [0...10]
313
+ # i = IntervalSet[0...10] # -> [0...10]
314
314
  # i.remove(0...2) # -> [8...10]
315
315
  # i >> (2...8) # -> [0...2, 8...10]
316
316
  #
@@ -334,7 +334,7 @@ class IntervalSet
334
334
  # The result is stored in this IntervalSet.
335
335
  #
336
336
  # i = IntervalSet[0...2, 3...5].intersect(1...5) # -> [1...2, 3...5]
337
- # i # -> [1...2, 3...5]
337
+ # i # -> [1...2, 3...5]
338
338
  #
339
339
  # @param other [Range, IntervalSet] the other object.
340
340
  # @return [IntervalSet] self.
@@ -460,7 +460,7 @@ class IntervalSet
460
460
  # any pair of elements from both sets. A ∗ B = { a + b | a ∈ A ∧ b ∈ B }
461
461
  #
462
462
  # # Convolve with a range (effectively buffers the set)
463
- # IntervalSet[0...4].convolve!(-1...2) # -> [-1...6]
463
+ # IntervalSet[0...4].convolve!(-1...2) # -> [-1...6]
464
464
  #
465
465
  # # Convolving with empty or reversed ranges result in an empty set.
466
466
  # IntervalSet[0...4].convolve!(0...0) # -> []
@@ -489,11 +489,11 @@ class IntervalSet
489
489
  # any pair of elements from both sets. A ∗ B = { a + b | a ∈ A ∧ b ∈ B }
490
490
  #
491
491
  # # Convolve with a range (effectively buffers the set)
492
- # IntervalSet[0...4] * (-1...2) # -> [-1...6]
492
+ # IntervalSet[0...4] * (-1...2) # -> [-1...6]
493
493
  #
494
494
  # # Convolving with empty or reversed ranges result in an empty set.
495
- # IntervalSet[0...4] * (0...0) # -> []
496
- # IntervalSet[0...4] * (1...0) # -> []
495
+ # IntervalSet[0...4] * (0...0) # -> []
496
+ # IntervalSet[0...4] * (1...0) # -> []
497
497
  #
498
498
  # # Convolve with a interval set
499
499
  # IntervalSet[0...1, 10...12] * IntervalSet[-2...1, 1...2] # -> [-2...3, 8...14]
@@ -509,7 +509,7 @@ class IntervalSet
509
509
  # Shifts this IntervalSet by the given amount.
510
510
  # The result is stored in this IntervalSet.
511
511
  #
512
- # IntervalSet[0...1].shift(1) # -> [1...2]
512
+ # IntervalSet[0...1].shift(1) # -> [1...2]
513
513
  #
514
514
  # Note that +shift(0)+ will not be optimized since IntervalSet does
515
515
  # not assume numbers as element type.
@@ -528,7 +528,7 @@ class IntervalSet
528
528
  # Shifts this IntervalSet by the given amount.
529
529
  # The result is stored in a new IntervalSet.
530
530
  #
531
- # IntervalSet[0...1].shift!(1) # -> [1...2]
531
+ # IntervalSet[0...1].shift!(1) # -> [1...2]
532
532
  #
533
533
  # Note that +shift!(0)+ will not be optimized since IntervalSet does
534
534
  # not assume numbers as element type.
@@ -567,11 +567,11 @@ class IntervalSet
567
567
  # Buffers this IntervalSet by adding a left and right margin to each range.
568
568
  # The result is stored in a new IntervalSet.
569
569
  #
570
- # IntervalSet[1...2].buffer(1, 2) # -> [0...4]
570
+ # IntervalSet[1...2].buffer(1, 2) # -> [0...4]
571
571
  #
572
572
  # # negative values will shrink the ranges
573
- # IntervalSet[0...4].buffer(-1, -2) # -> [1...2]
574
- # IntervalSet[1...2].buffer(-0.5, -0.5) # -> []
573
+ # IntervalSet[0...4].buffer(-1, -2) # -> [1...2]
574
+ # IntervalSet[1...2].buffer(-0.5, -0.5) # -> []
575
575
  #
576
576
  # @param left [Object] margin added to the left side of each range.
577
577
  # @param right [Object] margin added to the right side of each range.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interval_set
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rico Jasper
@@ -105,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - ">="
107
107
  - !ruby/object:Gem::Version
108
- version: '0'
108
+ version: 1.9.2
109
109
  required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  requirements:
111
111
  - - ">="