Class: Hwloc::Bitmap

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/hwloc/Bitmap.rb

Direct Known Subclasses

Cpuset, Nodeset

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Bitmap

Returns a new instance of Bitmap.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# 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

Instance Attribute Details

#ptrObject (readonly) Also known as: to_ptr

Returns the value of attribute ptr.



54
55
56
# File 'lib/hwloc/Bitmap.rb', line 54

def ptr
  @ptr
end

Instance Method Details

#&(other) ⇒ Object Also known as: intersection



266
267
268
269
270
# File 'lib/hwloc/Bitmap.rb', line 266

def &(other)
  res = Bitmap::new
  Hwloc.hwloc_bitmap_and(res.ptr, @ptr, other.ptr)
  return res
end

#-(other) ⇒ Object



296
297
298
299
300
# File 'lib/hwloc/Bitmap.rb', line 296

def -(other)
  res = Bitmap::new
  Hwloc.hwloc_bitmap_andnot(res.ptr, @ptr, other.ptr)
  return res
end

#<(other) ⇒ Object



322
323
324
# File 'lib/hwloc/Bitmap.rb', line 322

def <(other)
  return self <= other && !(self == other)
end

#==(other) ⇒ Object



302
303
304
# File 'lib/hwloc/Bitmap.rb', line 302

def ==(other)
  return Hwloc.hwloc_bitmap_isequal(@ptr, other.ptr) != 0
end

#>(other) ⇒ Object



312
313
314
# File 'lib/hwloc/Bitmap.rb', line 312

def >(other)
  return self >= other && !(self == other)
end

#[](indx) ⇒ Object



197
198
199
200
201
202
203
# File 'lib/hwloc/Bitmap.rb', line 197

def [](indx)
  if Hwloc.hwloc_bitmap_isset(@ptr, indx) != 0 then
    return true
  else
    return false
  end
end

#[]=(indx, val) ⇒ Object



189
190
191
192
193
194
195
# File 'lib/hwloc/Bitmap.rb', line 189

def []=(indx, val)
  if indx.kind_of?(Range) then
    set_range(indx, val)
  else
    set(indx, val)
  end
end

#^(other) ⇒ Object



284
285
286
287
288
# File 'lib/hwloc/Bitmap.rb', line 284

def ^(other)
  res = Bitmap::new
  Hwloc.hwloc_bitmap_xor(res.ptr, @ptr, other.ptr)
  return res
end

#all_but!(indx) ⇒ Object



157
158
159
160
# File 'lib/hwloc/Bitmap.rb', line 157

def all_but!(indx)
  Hwloc.hwloc_bitmap_allbut(@ptr, indx)
  return self
end

#compare(other) ⇒ Object Also known as: <=>



338
339
340
# File 'lib/hwloc/Bitmap.rb', line 338

def compare(other)
  return Hwloc.hwloc_bitmap_compare(@ptr, other.ptr)
end

#compare_first(other) ⇒ Object



334
335
336
# File 'lib/hwloc/Bitmap.rb', line 334

def compare_first(other)
  return Hwloc.hwloc_bitmap_compare_first(@ptr, other.ptr)
end

#disjoint?(other) ⇒ Boolean

Returns:

  • (Boolean)


330
331
332
# File 'lib/hwloc/Bitmap.rb', line 330

def disjoint?(other)
  return Hwloc.hwloc_bitmap_intersects(@ptr, other.ptr) == 0
end

#dupObject



105
106
107
# File 'lib/hwloc/Bitmap.rb', line 105

def dup
  return Bitmap::new( self )
end

#eachObject



254
255
256
257
258
259
260
261
262
263
264
# File 'lib/hwloc/Bitmap.rb', line 254

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

#fill!Object



147
148
149
150
# File 'lib/hwloc/Bitmap.rb', line 147

def fill!
  Hwloc.hwloc_bitmap_fill(@ptr)
  return self
end

#firstObject



228
229
230
231
232
# File 'lib/hwloc/Bitmap.rb', line 228

def first
  f = Hwloc.hwloc_bitmap_first(@ptr)
  return nil if f == -1
  return f
end

#full?Boolean

Returns:

  • (Boolean)


220
221
222
223
224
225
226
# File 'lib/hwloc/Bitmap.rb', line 220

def full?
  if Hwloc.hwloc_bitmap_isfull(@ptr) != 0 then
    return true
  else
    return false
  end
end

#include?(other) ⇒ Boolean Also known as: >=

Returns:

  • (Boolean)


306
307
308
# File 'lib/hwloc/Bitmap.rb', line 306

def include?(other)
  return Hwloc.hwloc_bitmap_isincluded(other.ptr, @ptr) != 0
end

#included?(other) ⇒ Boolean Also known as: <=

Returns:

  • (Boolean)


316
317
318
# File 'lib/hwloc/Bitmap.rb', line 316

def included?(other)
  return Hwloc.hwloc_bitmap_isincluded(@ptr, other.ptr) != 0
end

#inspectObject



58
59
60
# File 'lib/hwloc/Bitmap.rb', line 58

def inspect
  return "#<#{self.class}: {#{to_a.join(",")}}>"
end

#intersect?(other) ⇒ Boolean

Returns:

  • (Boolean)


326
327
328
# File 'lib/hwloc/Bitmap.rb', line 326

def intersect?(other)
  return Hwloc.hwloc_bitmap_intersects(@ptr, other.ptr) != 0
end

#lastObject



234
235
236
237
238
239
240
241
242
243
244
# File 'lib/hwloc/Bitmap.rb', line 234

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

#only!(indx) ⇒ Object



152
153
154
155
# File 'lib/hwloc/Bitmap.rb', line 152

def only!(indx)
  Hwloc.hwloc_bitmap_only(@ptr, indx)
  return self
end

#singlify!Object



205
206
207
208
# File 'lib/hwloc/Bitmap.rb', line 205

def singlify!
  Hwloc.hwloc_bitmap_singlify(@ptr)
  return self
end

#to_aObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/hwloc/Bitmap.rb', line 116

def to_a
  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)
  str = s_ptr.read_string
  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_iObject



136
137
138
# File 'lib/hwloc/Bitmap.rb', line 136

def to_i
  return to_s.to_i(16)
end

#to_sObject



109
110
111
112
113
114
# 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

#weightObject Also known as: size



246
247
248
249
250
# File 'lib/hwloc/Bitmap.rb', line 246

def weight
  w = Hwloc.hwloc_bitmap_weight(@ptr)
  return Float::INFINITY if w == -1
  return w
end

#zero!Object Also known as: clear



140
141
142
143
# File 'lib/hwloc/Bitmap.rb', line 140

def zero!
  Hwloc.hwloc_bitmap_zero(@ptr)
  return self
end

#zero?Boolean Also known as: empty?

Returns:

  • (Boolean)


210
211
212
213
214
215
216
# File 'lib/hwloc/Bitmap.rb', line 210

def zero?
  if Hwloc.hwloc_bitmap_iszero(@ptr) != 0 then
    return true
  else
    return false
  end
end

#|(other) ⇒ Object Also known as: +, union



274
275
276
277
278
# File 'lib/hwloc/Bitmap.rb', line 274

def |(other)
  res = Bitmap::new
  Hwloc.hwloc_bitmap_or(res.ptr, @ptr, other.ptr)
  return res
end

#~Object



290
291
292
293
294
# File 'lib/hwloc/Bitmap.rb', line 290

def ~
  res = Bitmap::new
  Hwloc.hwloc_bitmap_not(res.ptr, @ptr)
  return res
end