Class: Bio::RestrictionEnzyme::DenseIntArray
- Includes:
- Enumerable
- Defined in:
- lib/bio/util/restriction_enzyme/dense_int_array.rb
Overview
a class to store integer numbers, containing many contiguous integral numbers.
Bio::RestrictionEnzyme internal use only. Please do not create the instance outside Bio::RestrictionEnzyme.
Defined Under Namespace
Classes: MutableRange
Class Method Summary collapse
-
.[](*args) ⇒ Object
Same usage as Array.[].
Instance Method Summary collapse
-
#+(other) ⇒ Object
Same usage as Array#+, but accepts only the same classes instance.
-
#<<(elem) ⇒ Object
Same usage as Array#<<.
-
#==(other) ⇒ Object
Same usage as Array#==.
-
#[](*arg) ⇒ Object
Same usage as Array#[].
-
#[]=(*arg) ⇒ Object
Not implemented.
-
#concat(ary) ⇒ Object
Same usage as Array#concat.
-
#delete(elem) ⇒ Object
Same usage as Array#delete.
-
#each ⇒ Object
Same usage as Array#each.
-
#first ⇒ Object
Same usage as Array#first.
-
#include?(elem) ⇒ Boolean
Same usage as Array#include?.
-
#initialize ⇒ DenseIntArray
constructor
creates a new object.
-
#initialize_copy(other) ⇒ Object
initialize copy.
-
#last ⇒ Object
Same usage as Array#last.
-
#push(*args) ⇒ Object
Same usage as Array#push.
-
#reverse_each ⇒ Object
Same usage as Array#reverse_each.
-
#size ⇒ Object
(also: #length)
Same usage as Array#size.
-
#sort!(&block) ⇒ Object
Does nothing.
-
#uniq! ⇒ Object
Does nothing.
-
#unshift(*arg) ⇒ Object
Same usage as Array#unshift.
Constructor Details
#initialize ⇒ DenseIntArray
creates a new object
33 34 35 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 33 def initialize @data = [] end |
Class Method Details
.[](*args) ⇒ Object
Same usage as Array.[]
24 25 26 27 28 29 30 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 24 def self.[](*args) a = self.new args.each do |elem| a.push elem end a end |
Instance Method Details
#+(other) ⇒ Object
Same usage as Array#+, but accepts only the same classes instance.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 85 def +(other) unless other.is_a?(self.class) then raise TypeError, 'unsupported data type' end tmpdata = @data + other.internal_data tmpdata.sort! { |a,b| a.first <=> b.first } result = self.class.new return result if tmpdata.empty? newdata = result.internal_data newdata.push tmpdata[0].dup (1...(tmpdata.size)).each do |i| if (x = newdata[-1].last) >= tmpdata[i].first then newdata[-1].last = tmpdata[i].last if tmpdata[i].last > x else newdata.push tmpdata[i].dup end end result end |
#<<(elem) ⇒ Object
Same usage as Array#<<
136 137 138 139 140 141 142 143 144 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 136 def <<(elem) if !@data.empty? and @data[-1].last + 1 == elem then @data[-1].last = elem else @data << MutableRange.new(elem, elem) end self end |
#==(other) ⇒ Object
Same usage as Array#==
106 107 108 109 110 111 112 113 114 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 106 def ==(other) if r = super(other) then r elsif other.is_a?(self.class) then other.internal_data == @data else false end end |
#[](*arg) ⇒ Object
Same usage as Array#[]
58 59 60 61 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 58 def [](*arg) #$stderr.puts "SortedIntArray#[]" to_a[*arg] end |
#[]=(*arg) ⇒ Object
Not implemented
64 65 66 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 64 def []=(*arg) raise NotImplementedError, 'DenseIntArray#[]= is not implemented.' end |
#concat(ary) ⇒ Object
Same usage as Array#concat
117 118 119 120 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 117 def concat(ary) ary.each { |elem| self.<<(elem) } self end |
#delete(elem) ⇒ Object
Same usage as Array#delete
177 178 179 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 177 def delete(elem) raise NotImplementedError, 'DenseIntArray#delete is not implemented.' end |
#each ⇒ Object
Same usage as Array#each
69 70 71 72 73 74 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 69 def each @data.each do |elem| elem.first.upto(elem.last) { |num| yield num } end self end |
#first ⇒ Object
Same usage as Array#first
155 156 157 158 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 155 def first elem = @data.first elem ? elem.first : nil end |
#include?(elem) ⇒ Boolean
Same usage as Array#include?
147 148 149 150 151 152 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 147 def include?(elem) return false if @data.empty? or elem < self.first or self.last < elem @data.any? do |range| range.first <= elem && elem <= range.last end end |
#initialize_copy(other) ⇒ Object
initialize copy
38 39 40 41 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 38 def initialize_copy(other) super(other) @data = @data.collect { |elem| elem.dup } end |
#last ⇒ Object
Same usage as Array#last
161 162 163 164 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 161 def last elem = @data.last elem ? elem.last : nil end |
#push(*args) ⇒ Object
Same usage as Array#push
123 124 125 126 127 128 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 123 def push(*args) args.each do |elem| self.<<(elem) end self end |
#reverse_each ⇒ Object
Same usage as Array#reverse_each
77 78 79 80 81 82 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 77 def reverse_each @data.reverse_each do |elem| elem.last.downto(elem.first) { |num| yield num } end self end |
#size ⇒ Object Also known as: length
Same usage as Array#size
167 168 169 170 171 172 173 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 167 def size sum = 0 @data.each do |range| sum += (range.last - range.first + 1) end sum end |
#sort!(&block) ⇒ Object
Does nothing
182 183 184 185 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 182 def sort!(&block) # does nothing self end |
#uniq! ⇒ Object
Does nothing
188 189 190 191 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 188 def uniq! # does nothing self end |
#unshift(*arg) ⇒ Object
Same usage as Array#unshift
131 132 133 |
# File 'lib/bio/util/restriction_enzyme/dense_int_array.rb', line 131 def unshift(*arg) raise NotImplementedError, 'DenseIntArray#unshift is not implemented.' end |