Vectors

Utility functions for vectors.

Interface

find_upper_bound

Searches a sorted vec and returns the first index that contains a value greater or equal to element. If no such index exists (i.e. all values in the vector are strictly less than element), and the vector length is returned.

circle-check
public fun find_upper_bound(vec: vector<u64>, element: u64): u64
  • @param vec: The vector to be searched.

  • @param element: We check if there is a value higher than it in the vector.

  • @return u64. The index of the member that is larger than element. The length is returned if no member is found.

lt

Checks if a is smaller than b. E.g. x"123" < x"456".

public fun lt(a: vector<u8>, b: vector<u8>): bool
  • @param a: The first operand.

  • @param b: The second operand..

  • @return bool. If a is smaller than b.

Aborts

  • a and b have different lengths.

gt

Checks if a is larger than b. E.g. x"123" < x"456".

  • @param a: The first operand.

  • @param b: The second operand..

  • @return bool. If a is larger than b.

Aborts

  • a and b have different lengths.

lte

Checks if a is smaller or equal to b. E.g. x"123" =< x"456".

  • @param a: The first operand.

  • @param b: The second operand..

  • @return bool. If a is smaller or equal to b.

Aborts

  • a and b have different lengths.

gte

Checks if a is larger or equal to b. E.g. x"123" =< x"456".

  • @param a: The first operand.

  • @param b: The second operand..

  • @return bool. If a is larger or equal to b.

Aborts

  • a and b have different lengths.

ascending_insertion_sort

Sorts a a in ascending order. E.g. [342] => [234].

  • @param a: The vector to sort.

  • @return vector. Sorted a.

Aborts

  • a and b have different lengths.

descending_insertion_sort

Sorts a a in descending order. E.g. [342] => [432].

  • @param a: The vector to sort.

  • @return vector. Sorted a.

Aborts

  • a and b have different lengths.

quick_sort

Sorts a values. E.g. [342] => [234].

circle-exclamation
  • @param values: The vector to sort.

  • @param left: The smaller side of the pivot. Pass 0.

  • @param right: The larger side of the pivot. Pass vector::length - 1.

Last updated

Was this helpful?