class Hwloc::Bitmap

Attributes

ptr[R]
to_ptr[R]

Public Class Methods

new( *args ) click to toggle source
# File lib/hwloc/Bitmap.rb, line 62
def initialize( *args )
  if args.length == 0 then
    @ptr = FFI::AutoPointer::new( Hwloc.hwloc_bitmap_alloc, Hwloc.method(:hwloc_bitmap_free) )
  elsif args.length == 1 then
    arg = args[0]
    if arg.kind_of?( Bitmap ) then
      @ptr = FFI::AutoPointer::new( Hwloc.hwloc_bitmap_dup(arg.ptr), Hwloc.method(:hwloc_bitmap_free) )
    elsif arg.kind_of?( FFI::Pointer ) then
      @ptr = FFI::AutoPointer::new( Hwloc.hwloc_bitmap_dup(arg), Hwloc.method(:hwloc_bitmap_free) )
    elsif arg.kind_of?( String ) then
      s_ptr = FFI::MemoryPointer::from_string(arg)
      @ptr = FFI::AutoPointer::new( Hwloc.hwloc_bitmap_alloc, Hwloc.method(:hwloc_bitmap_free) )
      Hwloc.hwloc_bitmap_sscanf(@ptr,s_ptr)
    elsif arg.kind_of?( Array ) then
      list = []
      arg.each { |e|
        if e.kind_of?(Range) then
          if e.last == Float::INFINITY then
            list << "#{e.first}-"
          else
            list << "#{e.first}-#{e.last - (e.exclude_end? ? 1 : 0)}"
          end
        else
          list << e.to_s
        end
      }
      str = list.join(",")
      s_ptr = FFI::MemoryPointer::from_string(str)
      @ptr = FFI::AutoPointer::new( Hwloc.hwloc_bitmap_alloc, Hwloc.method(:hwloc_bitmap_free) )
      Hwloc.hwloc_bitmap_list_sscanf(@ptr,s_ptr)
    elsif arg.kind_of?( Range ) then
      if arg.last == Float::INFINITY then
        str = "#{arg.first}-"
      else
        str = "#{arg.first}-#{arg.last - (arg.exclude_end? ? 1 : 0)}"
      end
      s_ptr = FFI::MemoryPointer::from_string(str)
      @ptr = FFI::AutoPointer::new( Hwloc.hwloc_bitmap_alloc, Hwloc.method(:hwloc_bitmap_free) )
      Hwloc.hwloc_bitmap_list_sscanf(@ptr,s_ptr)
    end
  end
end

Public Instance Methods

&(other) click to toggle source
# File lib/hwloc/Bitmap.rb, line 270
def &(other)
  res = Bitmap::new
  Hwloc.hwloc_bitmap_and(res.ptr, @ptr, other.ptr)
  return res
end
Also aliased as: intersection
+(other)
Alias for: |
-(other) click to toggle source
# File lib/hwloc/Bitmap.rb, line 300
def -(other)
  res = Bitmap::new
  Hwloc.hwloc_bitmap_andnot(res.ptr, @ptr, other.ptr)
  return res
end
<(other) click to toggle source
# File lib/hwloc/Bitmap.rb, line 326
def <(other)
  return self <= other && !(self == other)
end
<=(other)
Alias for: included?
<=>(other)
Alias for: compare
==(other) click to toggle source
# File lib/hwloc/Bitmap.rb, line 306
def ==(other)
  return Hwloc.hwloc_bitmap_isequal(@ptr, other.ptr) != 0
end
>(other) click to toggle source
# File lib/hwloc/Bitmap.rb, line 316
def >(other)
  return self >= other && !(self == other)
end
>=(other)
Alias for: include?
[](indx) click to toggle source
# File lib/hwloc/Bitmap.rb, line 201
def [](indx)
  if Hwloc.hwloc_bitmap_isset(@ptr, indx) != 0 then
    return true
  else
    return false
  end
end
[]=(indx, val) click to toggle source
# File lib/hwloc/Bitmap.rb, line 193
def []=(indx, val)
  if indx.kind_of?(Range) then
    set_range(indx, val)
  else
    set(indx, val)
  end
end
^(other) click to toggle source
# File lib/hwloc/Bitmap.rb, line 288
def ^(other)
  res = Bitmap::new
  Hwloc.hwloc_bitmap_xor(res.ptr, @ptr, other.ptr)
  return res
end
all_but!(indx) click to toggle source
# File lib/hwloc/Bitmap.rb, line 161
def all_but!(indx)
  Hwloc.hwloc_bitmap_allbut(@ptr, indx)
  return self
end
clear()
Alias for: zero!
compare(other) click to toggle source
# File lib/hwloc/Bitmap.rb, line 342
def compare(other)
  return Hwloc.hwloc_bitmap_compare(@ptr, other.ptr)
end
Also aliased as: <=>
compare_first(other) click to toggle source
# File lib/hwloc/Bitmap.rb, line 338
def compare_first(other)
  return Hwloc.hwloc_bitmap_compare_first(@ptr, other.ptr)
end
disjoint?(other) click to toggle source
# File lib/hwloc/Bitmap.rb, line 334
def disjoint?(other)
  return Hwloc.hwloc_bitmap_intersects(@ptr, other.ptr) == 0
end
dup() click to toggle source
# File lib/hwloc/Bitmap.rb, line 105
def dup
  return Bitmap::new( self )
end
each() { |indx| ... } click to toggle source
# File lib/hwloc/Bitmap.rb, line 258
def each
  if block_given? then
    indx = -1
    while (indx = Hwloc.hwloc_bitmap_next(@ptr, indx) ) != -1 do
      yield indx
    end
    return self
  else
    return to_enum(:each)
  end 
end
empty?()
Alias for: zero?
fill!() click to toggle source
# File lib/hwloc/Bitmap.rb, line 151
def fill!
  Hwloc.hwloc_bitmap_fill(@ptr)
  return self
end
first() click to toggle source
# File lib/hwloc/Bitmap.rb, line 232
def first
  f = Hwloc.hwloc_bitmap_first(@ptr)
  return nil if f == -1
  return f
end
full?() click to toggle source
# File lib/hwloc/Bitmap.rb, line 224
def full?
  if Hwloc.hwloc_bitmap_isfull(@ptr) != 0 then
    return true
  else
    return false
  end
end
include?(other) click to toggle source
# File lib/hwloc/Bitmap.rb, line 310
def include?(other)
  return Hwloc.hwloc_bitmap_isincluded(other.ptr, @ptr) != 0
end
Also aliased as: >=
included?(other) click to toggle source
# File lib/hwloc/Bitmap.rb, line 320
def included?(other)
  return Hwloc.hwloc_bitmap_isincluded(@ptr, other.ptr) != 0
end
Also aliased as: <=
inspect() click to toggle source
# File lib/hwloc/Bitmap.rb, line 58
def inspect
  return "#<#{self.class}: {#{to_a.join(",")}}>"
end
intersect?(other) click to toggle source
# File lib/hwloc/Bitmap.rb, line 330
def intersect?(other)
  return Hwloc.hwloc_bitmap_intersects(@ptr, other.ptr) != 0
end
intersection(other)
Alias for: &
last() click to toggle source
# File lib/hwloc/Bitmap.rb, line 238
def last
  f = Hwloc.hwloc_bitmap_last(@ptr)
  if f == -1 then
    if full? then
      return Float::INFINITY
    else
      return nil
    end
  end
  return f
end
list_to_s() click to toggle source
# File lib/hwloc/Bitmap.rb, line 116
def list_to_s
  size = Hwloc.hwloc_bitmap_list_snprintf(nil, 0, @ptr)
  s_ptr = FFI::MemoryPointer::new(size+1)
  Hwloc.hwloc_bitmap_list_snprintf(s_ptr, size+1, @ptr)
  s_ptr.read_string
end
only!(indx) click to toggle source
# File lib/hwloc/Bitmap.rb, line 156
def only!(indx)
  Hwloc.hwloc_bitmap_only(@ptr, indx)
  return self
end
singlify!() click to toggle source
# File lib/hwloc/Bitmap.rb, line 209
def singlify!
  Hwloc.hwloc_bitmap_singlify(@ptr)
  return self
end
size()
Alias for: weight
to_a() click to toggle source
# File lib/hwloc/Bitmap.rb, line 123
def to_a
  str = list_to_s
  str.split(",").collect { |e|
    if e.match("-") then
      rgs = e.split("-")
      if rgs.length == 1 then
        en = Float::INFINITY
      else
        en = rgs[1].to_i
      end
      Range::new(rgs[0].to_i,en)
    else
      e.to_i
    end
  }
end
to_i() click to toggle source
# File lib/hwloc/Bitmap.rb, line 140
def to_i
  return to_s.to_i(16)
end
to_s() click to toggle source
# File lib/hwloc/Bitmap.rb, line 109
def to_s
  size = Hwloc.hwloc_bitmap_snprintf(nil, 0, @ptr)
  s_ptr = FFI::MemoryPointer::new(size+1)
  Hwloc.hwloc_bitmap_snprintf(s_ptr, size+1, @ptr)
  s_ptr.read_string
end
union(other)
Alias for: |
weight() click to toggle source
# File lib/hwloc/Bitmap.rb, line 250
def weight
  w = Hwloc.hwloc_bitmap_weight(@ptr)
  return Float::INFINITY if w == -1
  return w
end
Also aliased as: size
zero!() click to toggle source
# File lib/hwloc/Bitmap.rb, line 144
def zero!
  Hwloc.hwloc_bitmap_zero(@ptr)
  return self
end
Also aliased as: clear
zero?() click to toggle source
# File lib/hwloc/Bitmap.rb, line 214
def zero?
  if Hwloc.hwloc_bitmap_iszero(@ptr) != 0 then
    return true
  else
    return false
  end
end
Also aliased as: empty?
|(other) click to toggle source
# File lib/hwloc/Bitmap.rb, line 278
def |(other)
  res = Bitmap::new
  Hwloc.hwloc_bitmap_or(res.ptr, @ptr, other.ptr)
  return res
end
Also aliased as: +, union
~() click to toggle source
# File lib/hwloc/Bitmap.rb, line 294
def ~
  res = Bitmap::new
  Hwloc.hwloc_bitmap_not(res.ptr, @ptr)
  return res
end

Private Instance Methods

set(indx, val) click to toggle source
# File lib/hwloc/Bitmap.rb, line 166
def set(indx, val)
  if val then
    Hwloc.hwloc_bitmap_set(@ptr, indx)
  else
    Hwloc.hwloc_bitmap_clr(@ptr, indx)
  end
  return val
end
set_range(indx, val) click to toggle source
# File lib/hwloc/Bitmap.rb, line 175
def set_range(indx, val)
  b = indx.first
  if indx.last == Float::INFINITY then
    e = -1
  else
    e = indx.last
    e = e - 1 if indx.exclude_end?
  end
  if val then
    Hwloc.hwloc_bitmap_set_range(@ptr, b, e)
  else
    Hwloc.hwloc_bitmap_clr_range(@ptr, b, e)
  end
  return val
end