Class Bio::RestrictionEnzyme::DenseIntArray
In: lib/bio/util/restriction_enzyme/dense_int_array.rb
Parent: Object

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.

Methods

+   <<   ==   []   []   []=   concat   delete   each   first   include?   initialize_copy   internal_data   internal_data=   last   length   new   push   reverse_each   size   sort!   uniq!   unshift  

Included Modules

Enumerable

Constants

MutableRange = Struct.new(:first, :last)

Public Class methods

Same usage as Array.[]

[Source]

    # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 27
27:     def self.[](*args)
28:       a = self.new
29:       args.each do |elem|
30:         a.push elem
31:       end
32:       a
33:     end

creates a new object

[Source]

    # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 36
36:     def initialize
37:       @data = []
38:     end

Public Instance methods

Same usage as Array#+, but accepts only the same classes instance.

[Source]

     # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 88
 88:     def +(other)
 89:       unless other.is_a?(self.class) then
 90:         raise TypeError, 'unsupported data type'
 91:       end
 92:       tmpdata = @data + other.internal_data
 93:       tmpdata.sort! { |a,b| a.first <=> b.first }
 94:       result = self.class.new
 95:       return result if tmpdata.empty?
 96:       newdata = result.internal_data
 97:       newdata.push tmpdata[0].dup
 98:       (1...(tmpdata.size)).each do |i|
 99:         if (x = newdata[-1].last) >= tmpdata[i].first then
100:           newdata[-1].last = tmpdata[i].last if tmpdata[i].last > x
101:         else
102:           newdata.push tmpdata[i].dup
103:         end
104:       end
105:       result
106:     end

Same usage as Array#<<

[Source]

     # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 139
139:     def <<(elem)
140:       if !@data.empty? and
141:           @data[-1].last + 1 == elem then
142:         @data[-1].last = elem
143:       else
144:         @data << MutableRange.new(elem, elem)
145:       end
146:       self
147:     end

Same usage as Array#==

[Source]

     # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 109
109:     def ==(other)
110:       if r = super(other) then
111:         r
112:       elsif other.is_a?(self.class) then
113:         other.internal_data == @data
114:       else
115:         false
116:       end
117:     end

Same usage as Array#[]

[Source]

    # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 61
61:     def [](*arg)
62:       #$stderr.puts "SortedIntArray#[]"
63:       to_a[*arg]
64:     end

Not implemented

[Source]

    # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 67
67:     def []=(*arg)
68:       raise NotImplementedError, 'DenseIntArray#[]= is not implemented.'
69:     end

Same usage as Array#concat

[Source]

     # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 120
120:     def concat(ary)
121:       ary.each { |elem| self.<<(elem) }
122:       self
123:     end

Same usage as Array#delete

[Source]

     # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 180
180:     def delete(elem)
181:       raise NotImplementedError, 'DenseIntArray#delete is not implemented.'
182:     end

Same usage as Array#each

[Source]

    # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 72
72:     def each
73:       @data.each do |elem|
74:         elem.first.upto(elem.last) { |num| yield num }
75:       end
76:       self
77:     end

Same usage as Array#first

[Source]

     # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 158
158:     def first
159:       elem = @data.first
160:       elem ? elem.first : nil
161:     end

Same usage as Array#include?

[Source]

     # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 150
150:     def include?(elem)
151:       return false if @data.empty? or elem < self.first or self.last < elem
152:       @data.any? do |range|
153:         range.first <= elem && elem <= range.last
154:       end
155:     end

initialize copy

[Source]

    # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 41
41:     def initialize_copy(other)
42:       super(other)
43:       @data = @data.collect { |elem| elem.dup }
44:     end

Same usage as Array#last

[Source]

     # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 164
164:     def last
165:       elem = @data.last
166:       elem ? elem.last : nil
167:     end
length()

Alias for size

Same usage as Array#push

[Source]

     # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 126
126:     def push(*args)
127:       args.each do |elem|
128:         self.<<(elem)
129:       end
130:       self
131:     end

Same usage as Array#reverse_each

[Source]

    # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 80
80:     def reverse_each
81:       @data.reverse_each do |elem|
82:         elem.last.downto(elem.first) { |num| yield num }
83:       end
84:       self
85:     end

Same usage as Array#size

[Source]

     # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 170
170:     def size
171:       sum = 0
172:       @data.each do |range|
173:         sum += (range.last - range.first + 1)
174:       end
175:       sum
176:     end

Does nothing

[Source]

     # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 185
185:     def sort!(&block)
186:       # does nothing
187:       self
188:     end

Does nothing

[Source]

     # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 191
191:     def uniq!
192:       # does nothing
193:       self
194:     end

Same usage as Array#unshift

[Source]

     # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 134
134:     def unshift(*arg)
135:       raise NotImplementedError, 'DenseIntArray#unshift is not implemented.'
136:     end

Protected Instance methods

gets internal data object

[Source]

    # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 55
55:     def internal_data
56:       @data
57:     end

sets internal data object

[Source]

    # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 47
47:     def internal_data=(a)
48:       #clear_cache
49:       @data = a
50:       self
51:     end

[Validate]