vector.rl

Class Vector

 A memory contiguous datastructure similar to cpp vector.
 A vector is a list of elements. Just like cpp vector,
 the contents may be reallocated when added or deleated,
 so references elements are invalidated if the 
 vector is modified.

Fields

Methods

  • Function: init()

  • Function: drop()

  • Function: assign(Vector<T> other)

  • Function: resize(Int new_size)

 changes the size of the vector
 to be equal to `new_size`
 if the original size is larger
 than the new size, the extra 
 elements are destroyed
 
 if the original size is smaller
 than the new size, extra elements
 are constructed
  • Function: back()  -> ref T

 returns a reference to the
 last element of the vector
  • Function: get(Int index)  -> ref T

 returns a reference to the element
 with the provided index
  • Function: set(Int index, T value)

 assigns `value` to the element
 of the vector at the provided
 index
  • Function: append(T value)

 appends `value` to the 
 end of the vector
  • Function: empty()  -> Bool

 returns true if the
 size of the vector is equal
 to zero
  • Function: clear()

 erases all the elements
 of the vector
  • Function: pop()  -> T

 removes the last element
 of the vector and returns
 it by copy
  • Function: drop_back(Int quantity)

 removes `quantity` elements
 from the back of the vector
  • Function: erase(Int index)

 erase the element with the provided
 `index`
  • Function: size()  -> Int

Class BoundedVector

 A bounded vector is a wrapper
 around a vector that prevents 
 the size of the vector to ever 
 exced `max_size`
 this class is usefull when used
 for machine learning techniques, 
 since it allows the machine learning
 to know the maximal possible size
 of this vector when converted to
 a tensor

Fields

Methods

  • Function: assign(BoundedVector<T, max_size> other)

  • Function: resize(Int new_size)

 identical to Vector::resize,
 except `new_size` is clamped
 to be at most `max_size`
  • Function: max_size()  -> Int

 returns the maximal possible
 size of this vector
  • Function: back()  -> ref T

 same as vector::back
  • Function: get(Int index)  -> ref T

 same as vector::get
  • Function: set(Int index, T value)

 same as vector::set
  • Function: append(T value)

 append `value` to the end
 of the vector, but only if
 doing so would not excede
 max vector maximal size
  • Function: empty()  -> Bool

 same as vector::empty
  • Function: clear()

 same as vector::clear
  • Function: pop()  -> T

 same as vector::pop
  • Function: drop_back(Int quantity)

 same as vector::drop_back
  • Function: erase(Int index)

 same as vector::erase
  • Function: size()  -> Int

 same as vector::size