]> git.donarmstrong.com Git - biopieces.git/commitdiff
changed bitwise operators in bitarray to inline
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 17 Oct 2011 12:40:14 +0000 (12:40 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 17 Oct 2011 12:40:14 +0000 (12:40 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1579 74ccb610-7750-0410-82ae-013aeee3265d

code_ruby/lib/maasha/bitarray.rb

index 4ce560b3b7cf94e0b45f04477d2722ffb14dff9c..d054eb07a5db394ae12e1e1634dc391b21c11376 100644 (file)
@@ -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.