Class: Highs::BaseArray

Inherits:
Object
  • Object
show all
Defined in:
lib/highs/array.rb

Direct Known Subclasses

DoubleArray, IntArray

Constant Summary collapse

NOT_SET =
Object.new

Instance Method Summary collapse

Constructor Details

#initialize(size, value = NOT_SET) ⇒ BaseArray

Returns a new instance of BaseArray.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/highs/array.rb', line 5

def initialize(size, value = NOT_SET)
  @size = size
  @ptr =
    if value == NOT_SET
      Fiddle::Pointer.malloc(size * self.class::SIZE, Fiddle::RUBY_FREE)
    else
      if value.size != size
        # TODO add variable name to message
        raise ArgumentError, "wrong size (given #{value.size}, expected #{size})"
      end
      Fiddle::Pointer[value.pack("#{self.class::FORMAT}#{size}")]
    end
end

Instance Method Details

#to_aObject



19
20
21
# File 'lib/highs/array.rb', line 19

def to_a
  @ptr[0, @size * self.class::SIZE].unpack("#{self.class::FORMAT}#{@size}")
end

#to_ptrObject



23
24
25
# File 'lib/highs/array.rb', line 23

def to_ptr
  @ptr
end