Class: Bio::RestrictionEnzyme::SortedNumArray

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/util/restriction_enzyme/sorted_num_array.rb

Overview

a class to store sorted numerics.

Bio::RestrictionEnzyme internal use only. Please do not create the instance outside Bio::RestrictionEnzyme.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSortedNumArray

Creates a new object


31
32
33
34
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 31

def initialize
  @hash = {}
  #clear_cache
end

Class Method Details

.[](*args) ⇒ Object

Same usage as Array.[]


22
23
24
25
26
27
28
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 22

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.


124
125
126
127
128
129
130
131
132
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 124

def +(other)
  unless other.is_a?(self.class) then
    raise TypeError, 'unsupported data type'
  end
  new_hash = @hash.merge(other.internal_data_hash)
  result = self.class.new
  result.internal_data_hash = new_hash
  result
end

#<<(elem) ⇒ Object

Same usage as Array#<<


168
169
170
171
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 168

def <<(elem)
  push_element(elem)
  self
end

#==(other) ⇒ Object

Same usage as Array#==


135
136
137
138
139
140
141
142
143
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 135

def ==(other)
  if r = super(other) then
    r
  elsif other.is_a?(self.class) then
    other.internal_data_hash == @hash
  else
    false
  end
end

#[](*arg) ⇒ Object

Same usage as Array#[]


103
104
105
106
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 103

def [](*arg)
  #$stderr.puts "SortedNumArray#[]"
  sorted_keys[*arg]
end

#[]=(*arg) ⇒ Object

Not implemented

Raises:

  • (NotImplementedError)

109
110
111
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 109

def []=(*arg)
  raise NotImplementedError, 'SortedNumArray#[]= is not implemented.'
end

#concat(ary) ⇒ Object

Same usage as Array#concat


146
147
148
149
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 146

def concat(ary)
  ary.each { |elem| push_element(elem) }
  self
end

#delete(elem) ⇒ Object

Same usage as Array#delete


195
196
197
198
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 195

def delete(elem)
  #clear_cache
  @hash.delete(elem) ? elem : nil
end

#each(&block) ⇒ Object

Same usage as Array#each


114
115
116
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 114

def each(&block)
  sorted_keys.each(&block)
end

#firstObject

Same usage as Array#first


179
180
181
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 179

def first
  sorted_keys.first
end

#include?(elem) ⇒ Boolean

Same usage as Array#include?


174
175
176
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 174

def include?(elem)
  @hash.has_key?(elem)
end

#initialize_copy(other) ⇒ Object

initialize copy


37
38
39
40
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 37

def initialize_copy(other)
  super(other)
  @hash = @hash.dup
end

#lastObject

Same usage as Array#last


184
185
186
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 184

def last
  sorted_keys.last
end

#push(*args) ⇒ Object

Same usage as Array#push


152
153
154
155
156
157
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 152

def push(*args)
  args.each do |elem|
    push_element(elem)
  end
  self
end

#reverse_each(&block) ⇒ Object

Same usage as Array#reverse_each


119
120
121
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 119

def reverse_each(&block)
  sorted_keys.reverse_each(&block)
end

#sizeObject Also known as: length

Same usage as Array#size


189
190
191
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 189

def size
  @hash.size
end

#sort!(&block) ⇒ Object

Does nothing


201
202
203
204
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 201

def sort!(&block)
  # does nothing
  self
end

#to_aObject

Converts to an array


213
214
215
216
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 213

def to_a
  #sorted_keys.dup
  sorted_keys
end

#uniq!Object

Does nothing


207
208
209
210
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 207

def uniq!
  # does nothing
  self
end

#unshift(*arg) ⇒ Object

Same usage as Array#unshift


160
161
162
163
164
165
# File 'lib/bio/util/restriction_enzyme/sorted_num_array.rb', line 160

def unshift(*arg)
  arg.reverse_each do |elem|
    unshift_element(elem)
  end
  self
end