pub_grub 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 642375a06f7dfaeb135540d21df24c7ce5f88cd531129207fd0fcfbc83959f6d
4
- data.tar.gz: ba4089a2a03066e6d870bf59a8db5f946faf6021b80185f12a19de5909ef0089
3
+ metadata.gz: 312b4d6ab0235f22ead56c025d6ae557043af8f4e4b0ac7bbed1e0a219151a29
4
+ data.tar.gz: 7b9de23d87e9918d4a97b24ded5d1db9573e7693af34b737c2b66b46f93a9e76
5
5
  SHA512:
6
- metadata.gz: 78e1a7ebc65582bcce5665b601d11850183b25eb4634cb3cf1c81057a7e1b8c52ca7e229ada3ca48e368bc5f1152d7572dedaf46d1eda2a0c9738e14174583c4
7
- data.tar.gz: 0053dd74681d77f8936db09ba631b3aed9676f45bb12bd8f9555667ca7f450c2780c469294f9e03922c042f6b42979bc18a644df31bd595bffdaa0e549fc6c1c
6
+ metadata.gz: 2ceeb01137803054fb77b1fba533e21880c49b4ae3e4cbaed52887543137a641f9e4527a86e5840df725e96c9ed021b14f1dcf10233a8608f8eb1f84eb7c4e97
7
+ data.tar.gz: ce803cc3420bef9d78bd4745ad2e3829272dabb2b1083659e4de712f3a8ab1db4a9f990589a9405e251d0ed2f24d4e466fd035bea6d429ee366d05735cc1777c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pub_grub (0.3.1)
4
+ pub_grub (0.3.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -79,27 +79,45 @@ module PubGrub
79
79
  compare_version(version) == 0
80
80
  end
81
81
 
82
- # Returns verisons which are included by this range.
82
+ # Partitions passed versions into [lower, within, higher]
83
83
  #
84
84
  # versions must be sorted
85
- def select_versions(versions)
86
- if min
87
- if include_min?
88
- versions = versions.drop_while { |v| v < min }
85
+ def partition_versions(versions)
86
+ min_index =
87
+ if !min || versions.empty?
88
+ 0
89
+ elsif include_min?
90
+ (0..versions.size).bsearch { |i| versions[i].nil? || versions[i] >= min }
89
91
  else
90
- versions = versions.drop_while { |v| v <= min }
92
+ (0..versions.size).bsearch { |i| versions[i].nil? || versions[i] > min }
91
93
  end
92
- end
93
94
 
94
- if max
95
- if include_max?
96
- versions = versions.take_while { |v| v <= max }
95
+ lower = versions.slice(0, min_index)
96
+ versions = versions.slice(min_index, versions.size)
97
+
98
+ max_index =
99
+ if !max || versions.empty?
100
+ versions.size
101
+ elsif include_max?
102
+ (0..versions.size).bsearch { |i| versions[i].nil? || versions[i] > max }
97
103
  else
98
- versions = versions.take_while { |v| v < max }
104
+ (0..versions.size).bsearch { |i| versions[i].nil? || versions[i] >= max }
99
105
  end
100
- end
101
106
 
102
- versions
107
+ [
108
+ lower,
109
+ versions.slice(0, max_index),
110
+ versions.slice(max_index, versions.size)
111
+ ]
112
+ end
113
+
114
+ # Returns verisons which are included by this range.
115
+ #
116
+ # versions must be sorted
117
+ def select_versions(versions)
118
+ return versions if any?
119
+
120
+ partition_versions(versions)[1]
103
121
  end
104
122
 
105
123
  def compare_version(version)
@@ -52,10 +52,14 @@ module PubGrub
52
52
  !!ranges.bsearch {|r| r.compare_version(version) }
53
53
  end
54
54
 
55
- def select_versions(versions)
56
- ranges.flat_map do |range|
57
- range.select_versions(versions)
55
+ def select_versions(all_versions)
56
+ versions = []
57
+ ranges.inject(all_versions) do |acc, range|
58
+ lower, matching, higher = range.partition_versions(acc)
59
+ versions.concat matching
60
+ higher
58
61
  end
62
+ versions
59
63
  end
60
64
 
61
65
  def intersects?(other)
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "pub_grub"
7
- spec.version = "0.3.1"
7
+ spec.version = "0.3.2"
8
8
  spec.authors = ["John Hawthorn"]
9
9
  spec.email = ["john@hawthorn.email"]
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pub_grub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hawthorn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-02 00:00:00.000000000 Z
11
+ date: 2018-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler