From b27d96382b0e37df55fc8d347634a13d487e55a9 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Mon, 17 Oct 2011 12:40:14 +0000 Subject: [PATCH] changed bitwise operators in bitarray to inline git-svn-id: http://biopieces.googlecode.com/svn/trunk@1579 74ccb610-7750-0410-82ae-013aeee3265d --- code_ruby/lib/maasha/bitarray.rb | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/code_ruby/lib/maasha/bitarray.rb b/code_ruby/lib/maasha/bitarray.rb index 4ce560b..d054eb0 100644 --- a/code_ruby/lib/maasha/bitarray.rb +++ b/code_ruby/lib/maasha/bitarray.rb @@ -74,42 +74,36 @@ class BitArray end # Method to run bitwise AND (&) on two bit arrays and return the - # result in a new bit array. Bits are copied if they exists in BOTH operands. + # result in the first bit array. Bits are copied if they exists in BOTH operands. # 00111100 & 00001101 = 00001100 def &(ba) raise BitArrayError, "uneven size of bit arrays: #{self.size} != #{ba.size}" if self.size != ba.size - result = BitArray.new(ba.size) + self.byte_array = self.byte_array & ba.byte_array - result.byte_array = self.byte_array & ba.byte_array - - result + self end # Method to run bitwise OR (|) on two bit arrays and return the - # result in a new bit array. Bits are copied if they exists in EITHER operands. + # result in the first bit array. Bits are copied if they exists in EITHER operands. # 00111100 | 00001101 = 00111101 def |(ba) raise BitArrayError, "uneven size of bit arrays: #{self.size} != #{ba.size}" if self.size != ba.size - result = BitArray.new(ba.size) - - result.byte_array = self.byte_array | ba.byte_array + self.byte_array = self.byte_array | ba.byte_array - result + self end # Method to run bitwise XOR (^) on two bit arrays and return the - # result in a new bit array. Bits are copied if they exists in ONE BUT NOT BOTH operands. + # result in the first bit array. Bits are copied if they exists in ONE BUT NOT BOTH operands. # 00111100 ^ 00001101 = 00110001 def ^(ba) raise BitArrayError, "uneven size of bit arrays: #{self.size} != #{ba.size}" if self.size != ba.size - result = BitArray.new(ba.size) - - result.byte_array = self.byte_array ^ ba.byte_array + self.byte_array = self.byte_array ^ ba.byte_array - result + self end # Method to convert a bit array to a string. -- 2.39.5