augmented_interval_tree 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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/interval_tree.rb +11 -5
  3. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2591f2d25e1de25e701a3115d5eb647334a67a74
4
- data.tar.gz: e224077f0534ff854255a2d3ba840278148ac466
3
+ metadata.gz: c6108f6c850d3ae7ad2709ebd8bb869201b11827
4
+ data.tar.gz: 0ca27ee324f857ba4ef974bdbae76ccd2091dfbf
5
5
  SHA512:
6
- metadata.gz: 88911836bf22f53b32cb414ec7583ac91bb4dee0c4d72e11af929c8873fc4cc49206d18db427e4c7dca29e5c6b7a1c68ce5bfc3843fadc53f0b05163cf695224
7
- data.tar.gz: 02dea2fac6b40520bb156cdc429f936c42b8c919e27cd958cec8e3ca9731c422cc8f18d03c6a95e527e991fa13f09a6660400fdb6aae80312f5044e14e646429
6
+ metadata.gz: d75bd08453781fff027b9ce48552a717c6c97de11fcb3914396f513b7b518bd66d366950390a6e236f04bff10dfec34bb63a084f7c33f6120481abb2ca12ee47
7
+ data.tar.gz: 45450b661acb1ca523c23660bb1076912c3eeb585f69d6905b54c703ece98658175591e4adffa6b67fb1570c691495e727b458d650ea0f66a070ce85f3fbf860
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
3
  # Title:: the IntervalTree module using "augmented tree"
4
- # Author:: Hiroyuki Mishima, Simeon Simeonov, Carlos Alonso
4
+ # Author:: Hiroyuki Mishima, Simeon Simeonov, Carlos Alonso, Sam Davies
5
5
  # Copyright:: The MIT/X11 license
6
6
  #
7
7
  # see also ....
@@ -52,8 +52,10 @@ module IntervalTree
52
52
  divide_intervals(s_left), divide_intervals(s_right))
53
53
  end
54
54
 
55
+ DEFAULT_OPTIONS = {unique: true}
56
+ def search(interval, options = {})
57
+ options = DEFAULT_OPTIONS.merge(options)
55
58
 
56
- def search(interval)
57
59
  return nil unless @top_node
58
60
  if interval.respond_to?(:first)
59
61
  first = interval.first
@@ -71,7 +73,7 @@ module IntervalTree
71
73
  end
72
74
  result.sort_by{|x|[x.first, x.last]}
73
75
  else
74
- point_search(self.top_node, first, []).sort_by{|x|[x.first, x.last]}
76
+ point_search(self.top_node, first, [], options[:unique]).sort_by{|x|[x.first, x.last]}
75
77
  end
76
78
  end
77
79
 
@@ -97,7 +99,7 @@ module IntervalTree
97
99
  i.first + (i.last - i.first) / 2
98
100
  end
99
101
 
100
- def point_search(node, point, result)
102
+ def point_search(node, point, result, unique = true)
101
103
  node.s_center.each do |k|
102
104
  if k.include?(point)
103
105
  result << k
@@ -109,7 +111,11 @@ module IntervalTree
109
111
  if node.right_node && ( point >= node.x_center )
110
112
  point_search(node.right_node, point, []).each{|k|result << k}
111
113
  end
112
- result.uniq
114
+ if unique
115
+ result.uniq
116
+ else
117
+ result
118
+ end
113
119
  end
114
120
  end # class Tree
115
121
 
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: augmented_interval_tree
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
  - Hiroyuki Mishima
8
8
  - Simeon Simeonov
9
9
  - Carlos Alonso
10
+ - Sam Davies
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2015-11-09 00:00:00.000000000 Z
14
+ date: 2017-05-12 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: rspec
@@ -57,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
58
  version: '0'
58
59
  requirements: []
59
60
  rubyforge_project:
60
- rubygems_version: 2.4.5
61
+ rubygems_version: 2.5.1
61
62
  signing_key:
62
63
  specification_version: 4
63
64
  summary: A Ruby implementation of the Augmented Interval Tree data structure