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

[](*args)

Same usage as Array.[]

[Source]

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

new()

creates a new object

[Source]

        # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 33
    33:     def initialize
    34:       @data = []
    35:     end

### Public Instance methods

+(other)

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

[Source]

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

<<(elem)

Same usage as Array#<<

[Source]

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

==(other)

Same usage as Array#==

[Source]

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

[](*arg)

Same usage as Array#[]

[Source]

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

[]=(*arg)

Not implemented

[Source]

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

concat(ary)

Same usage as Array#concat

[Source]

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

delete(elem)

Same usage as Array#delete

[Source]

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

each() {|num| ...}

Same usage as Array#each

[Source]

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

first()

Same usage as Array#first

[Source]

         # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 155
    155:     def first
    156:       elem = @data.first
    157:       elem ? elem.first : nil
    158:     end

include?(elem)

Same usage as Array#include?

[Source]

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

initialize_copy(other)

initialize copy

[Source]

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

last()

Same usage as Array#last

[Source]

         # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 161
    161:     def last
    162:       elem = @data.last
    163:       elem ? elem.last : nil
    164:     end

length()

Alias for size

push(*args)

Same usage as Array#push

[Source]

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

reverse_each() {|num| ...}

Same usage as Array#reverse_each

[Source]

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

size()

Same usage as Array#size

[Source]

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

sort!(&block)

Does nothing

[Source]

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

uniq!()

Does nothing

[Source]

         # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 188
    188:     def uniq!
    189:       # does nothing
    190:       self
    191:     end

unshift(*arg)

Same usage as Array#unshift

[Source]

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

### Protected Instance methods

internal_data()

gets internal data object

[Source]

        # File lib/bio/util/restriction_enzyme/dense_int_array.rb, line 52
    52:     def internal_data
    53:       @data
    54:     end

internal_data=(a)

sets internal data object

[Source]

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

[Validate]