Я использовал NArray для реализации битового массива, но меня не совсем устраивает скорость метода bits_on.В настоящее время у меня есть:
# Method that returns the number of bits set "on" in a bit array.
def bits_on
bits_on = 0
self.byte_array.each do |byte|
bits_on += @count_array[byte]
end
bits_on
end
byte_array
является типом NArray.byte (), а @count_array
построен следующим образом:
# Method that returns an array where the element index value is
# the number of bits set for that index value.
def init_count_array
count_array = []
(0 ... (2 ** BitsInChar)).each do |i|
count_array << bits_in_char(i)
end
count_array
end
Идеи?
Ура,
Мартин