module FastBitset

Constants

VERSION

Public Class Methods

bitstring_to_ids(p1)
native_bitstring_to_ids(p1) click to toggle source
VALUE rb_fast_bitset_get_ids(VALUE self, VALUE bitstring) {
  VALUE ids = rb_ary_new();

  Check_Type(bitstring, T_STRING);


  char *ids_input = RSTRING_PTR(bitstring);
  int length      = RSTRING_LEN(bitstring);

  int base = 0;

  char current;
  int i, j;

  for(i = 0; i < length; i++) {
    current = ids_input[i];


    for(j = 0; j < 8; j++) {
      char bitmask = (1<<(7-j));
      if(bitmask & current) {
        rb_ary_push(ids, INT2NUM(base + j));
      } 
    }

    base += 8;
  }

  return ids;
}
Also aliased as: bitstring_to_ids
pure_bitstring_to_ids(value) click to toggle source
# File lib/fast_bitset.rb, line 5
def self.pure_bitstring_to_ids(value)
  unless value.is_a?(String)
    raise TypeError.new("wrong argument type #{value.class} (expected String)")
  end
  offset = 0
  ids    = []
  return ids if value.nil?
  value.each_byte do |byte|
    7.downto(0) do |i|
      value = (1<<i)
      ids << offset if (value & byte) == value
      offset += 1
    end
  end
  ids
end
Also aliased as: bitstring_to_ids