class Bio::RestrictionEnzyme::SortedNumArray
a class to store sorted numerics.
Bio::RestrictionEnzyme
internal use only. Please do not create the instance outside Bio::RestrictionEnzyme
.
Public Class Methods
Same usage as Array.[]
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 22 def self.[](*args) 23 a = self.new 24 args.each do |elem| 25 a.push elem 26 end 27 a 28 end
Creates a new object
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 31 def initialize 32 @hash = {} 33 #clear_cache 34 end
Public Instance Methods
Same usage as Array#+, but accepts only the same classes instance.
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 124 def +(other) 125 unless other.is_a?(self.class) then 126 raise TypeError, 'unsupported data type' 127 end 128 new_hash = @hash.merge(other.internal_data_hash) 129 result = self.class.new 130 result.internal_data_hash = new_hash 131 result 132 end
Same usage as Array#<<
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 168 def <<(elem) 169 push_element(elem) 170 self 171 end
Same usage as Array#==
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 135 def ==(other) 136 if r = super(other) then 137 r 138 elsif other.is_a?(self.class) then 139 other.internal_data_hash == @hash 140 else 141 false 142 end 143 end
Same usage as Array#[]
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 103 def [](*arg) 104 #$stderr.puts "SortedNumArray#[]" 105 sorted_keys[*arg] 106 end
Not implemented
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 109 def []=(*arg) 110 raise NotImplementedError, 'SortedNumArray#[]= is not implemented.' 111 end
Same usage as Array#concat
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 146 def concat(ary) 147 ary.each { |elem| push_element(elem) } 148 self 149 end
Same usage as Array#delete
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 195 def delete(elem) 196 #clear_cache 197 @hash.delete(elem) ? elem : nil 198 end
Same usage as Array#each
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 114 def each(&block) 115 sorted_keys.each(&block) 116 end
Same usage as Array#first
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 179 def first 180 sorted_keys.first 181 end
Same usage as Array#include?
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 174 def include?(elem) 175 @hash.has_key?(elem) 176 end
initialize copy
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 37 def initialize_copy(other) 38 super(other) 39 @hash = @hash.dup 40 end
Same usage as Array#last
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 184 def last 185 sorted_keys.last 186 end
Same usage as Array#push
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 152 def push(*args) 153 args.each do |elem| 154 push_element(elem) 155 end 156 self 157 end
Same usage as Array#reverse_each
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 119 def reverse_each(&block) 120 sorted_keys.reverse_each(&block) 121 end
Same usage as Array#size
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 189 def size 190 @hash.size 191 end
Does nothing
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 201 def sort!(&block) 202 # does nothing 203 self 204 end
Converts to an array
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 213 def to_a 214 #sorted_keys.dup 215 sorted_keys 216 end
Does nothing
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 207 def uniq! 208 # does nothing 209 self 210 end
Same usage as Array#unshift
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 160 def unshift(*arg) 161 arg.reverse_each do |elem| 162 unshift_element(elem) 163 end 164 self 165 end
Protected Instance Methods
gets internal hash object
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 51 def internal_data_hash 52 @hash 53 end
sets internal hash object
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 43 def internal_data_hash=(h) 44 #clear_cache 45 @hash = h 46 self 47 end
Private Instance Methods
adds a new element
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 73 def push_element(n) 74 #return if @hash.has_key?(n) #already existed; do nothing 75 @hash.store(n, true) 76 #if @sorted_keys then 77 # if thelast = @sorted_keys[-1] and n > thelast then 78 # @sorted_keys.push n 79 # else 80 # clear_cache 81 # end 82 #end 83 nil 84 end
sorted keys
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 65 def sorted_keys 66 #@sorted_keys ||= @hash.keys.sort 67 #@sorted_keys 68 @hash.keys.sort 69 end
adds a new element in the beginning of the array
# File lib/bio/util/restriction_enzyme/sorted_num_array.rb 88 def unshift_element(n) 89 #return if @hash.has_key?(n) #already existed; do nothing 90 @hash.store(n, true) 91 #if @sorted_keys then 92 # if thefirst = @sorted_keys[0] and n < thefirst then 93 # @sorted_keys.unshift n 94 # else 95 # clear_cache 96 # end 97 #end 98 nil 99 end