Class: Hwloc::Bitmap
Instance Attribute Summary collapse
-
#ptr ⇒ Object
(also: #to_ptr)
readonly
Returns the value of attribute ptr.
Instance Method Summary collapse
- #&(other) ⇒ Object (also: #intersection)
- #-(other) ⇒ Object
- #<(other) ⇒ Object
- #==(other) ⇒ Object
- #>(other) ⇒ Object
- #[](indx) ⇒ Object
- #[]=(indx, val) ⇒ Object
- #^(other) ⇒ Object
- #all_but!(indx) ⇒ Object
- #compare(other) ⇒ Object (also: #<=>)
- #compare_first(other) ⇒ Object
- #disjoint?(other) ⇒ Boolean
- #dup ⇒ Object
- #each ⇒ Object
- #fill! ⇒ Object
- #first ⇒ Object
- #full? ⇒ Boolean
- #include?(other) ⇒ Boolean (also: #>=)
- #included?(other) ⇒ Boolean (also: #<=)
-
#initialize(*args) ⇒ Bitmap
constructor
A new instance of Bitmap.
- #inspect ⇒ Object
- #intersect?(other) ⇒ Boolean
- #last ⇒ Object
- #list_to_s ⇒ Object
- #only!(indx) ⇒ Object
- #singlify! ⇒ Object
- #to_a ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
- #weight ⇒ Object (also: #size)
- #zero! ⇒ Object (also: #clear)
- #zero? ⇒ Boolean (also: #empty?)
- #|(other) ⇒ Object (also: #+, #union)
- #~ ⇒ Object
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
#ptr ⇒ Object (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
270 271 272 273 274 |
# File 'lib/hwloc/Bitmap.rb', line 270 def &(other) res = Bitmap::new Hwloc.hwloc_bitmap_and(res.ptr, @ptr, other.ptr) return res end |
#-(other) ⇒ Object
300 301 302 303 304 |
# 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) ⇒ Object
326 327 328 |
# File 'lib/hwloc/Bitmap.rb', line 326 def <(other) return self <= other && !(self == other) end |
#==(other) ⇒ Object
306 307 308 |
# File 'lib/hwloc/Bitmap.rb', line 306 def ==(other) return Hwloc.hwloc_bitmap_isequal(@ptr, other.ptr) != 0 end |
#>(other) ⇒ Object
316 317 318 |
# File 'lib/hwloc/Bitmap.rb', line 316 def >(other) return self >= other && !(self == other) end |
#[](indx) ⇒ Object
201 202 203 204 205 206 207 |
# 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) ⇒ Object
193 194 195 196 197 198 199 |
# 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) ⇒ Object
288 289 290 291 292 |
# 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) ⇒ Object
161 162 163 164 |
# File 'lib/hwloc/Bitmap.rb', line 161 def all_but!(indx) Hwloc.hwloc_bitmap_allbut(@ptr, indx) return self end |
#compare(other) ⇒ Object Also known as: <=>
342 343 344 |
# File 'lib/hwloc/Bitmap.rb', line 342 def compare(other) return Hwloc.hwloc_bitmap_compare(@ptr, other.ptr) end |
#compare_first(other) ⇒ Object
338 339 340 |
# File 'lib/hwloc/Bitmap.rb', line 338 def compare_first(other) return Hwloc.hwloc_bitmap_compare_first(@ptr, other.ptr) end |
#disjoint?(other) ⇒ Boolean
334 335 336 |
# File 'lib/hwloc/Bitmap.rb', line 334 def disjoint?(other) return Hwloc.hwloc_bitmap_intersects(@ptr, other.ptr) == 0 end |
#dup ⇒ Object
105 106 107 |
# File 'lib/hwloc/Bitmap.rb', line 105 def dup return Bitmap::new( self ) end |
#each ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 |
# 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 |
#fill! ⇒ Object
151 152 153 154 |
# File 'lib/hwloc/Bitmap.rb', line 151 def fill! Hwloc.hwloc_bitmap_fill(@ptr) return self end |
#first ⇒ Object
232 233 234 235 236 |
# File 'lib/hwloc/Bitmap.rb', line 232 def first f = Hwloc.hwloc_bitmap_first(@ptr) return nil if f == -1 return f end |
#full? ⇒ Boolean
224 225 226 227 228 229 230 |
# 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) ⇒ Boolean Also known as: >=
310 311 312 |
# File 'lib/hwloc/Bitmap.rb', line 310 def include?(other) return Hwloc.hwloc_bitmap_isincluded(other.ptr, @ptr) != 0 end |
#included?(other) ⇒ Boolean Also known as: <=
320 321 322 |
# File 'lib/hwloc/Bitmap.rb', line 320 def included?(other) return Hwloc.hwloc_bitmap_isincluded(@ptr, other.ptr) != 0 end |
#inspect ⇒ Object
58 59 60 |
# File 'lib/hwloc/Bitmap.rb', line 58 def inspect return "#<#{self.class}: {#{to_a.join(",")}}>" end |
#intersect?(other) ⇒ Boolean
330 331 332 |
# File 'lib/hwloc/Bitmap.rb', line 330 def intersect?(other) return Hwloc.hwloc_bitmap_intersects(@ptr, other.ptr) != 0 end |
#last ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 |
# 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 ⇒ Object
116 117 118 119 120 121 |
# 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) ⇒ Object
156 157 158 159 |
# File 'lib/hwloc/Bitmap.rb', line 156 def only!(indx) Hwloc.hwloc_bitmap_only(@ptr, indx) return self end |
#singlify! ⇒ Object
209 210 211 212 |
# File 'lib/hwloc/Bitmap.rb', line 209 def singlify! Hwloc.hwloc_bitmap_singlify(@ptr) return self end |
#to_a ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# 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 ⇒ Object
140 141 142 |
# File 'lib/hwloc/Bitmap.rb', line 140 def to_i return to_s.to_i(16) end |
#to_s ⇒ Object
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 |
#weight ⇒ Object Also known as: size
250 251 252 253 254 |
# File 'lib/hwloc/Bitmap.rb', line 250 def weight w = Hwloc.hwloc_bitmap_weight(@ptr) return Float::INFINITY if w == -1 return w end |
#zero! ⇒ Object Also known as: clear
144 145 146 147 |
# File 'lib/hwloc/Bitmap.rb', line 144 def zero! Hwloc.hwloc_bitmap_zero(@ptr) return self end |
#zero? ⇒ Boolean Also known as: empty?
214 215 216 217 218 219 220 |
# File 'lib/hwloc/Bitmap.rb', line 214 def zero? if Hwloc.hwloc_bitmap_iszero(@ptr) != 0 then return true else return false end end |