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
アイデア?
乾杯、
マーティン