16. Miscelanious algorithms

The ALGORITHM module exposes collection of miscellaneous array manipulation algorithms.

All functions and symbols are in “algorithm” module, use require to get access to it.

require daslib/algorithm

16.2. Array manipulation

unique(a: array<auto(TT)>): auto

Returns array of the elements of a with duplicates removed.

Arguments:
  • a : array<auto(TT)>

sort_unique(a: array<auto(TT)>): auto

Returns array of the elements of a, sorted and with duplicates removed. The elements of a are sorted in ascending order. The resulted array has only unqiue elements.

Arguments:
  • a : array<auto(TT)>

reverse(a: array<auto>): auto

Returns array of the elements of a in reverse order.

Arguments:
  • a : array<auto>

combine(a: array<auto(TT)>; b: array<auto(TT)>): auto

Returns array of the elements of a and then b.

Arguments:
  • a : array<auto(TT)>

  • b : array<auto(TT)>

reverse(a: auto): auto

Reverses the elements of array a in place.

Arguments:
  • a : auto

combine(a: auto; b: auto): auto

Returns array of the elements of a and then b.

Arguments:
  • a : auto

  • b : auto

erase_all(arr: auto; value: auto): auto

Erase all elements equal to value from arr

Arguments:
  • arr : auto

  • value : auto

topological_sort(nodes: array<auto(Node)>): auto

Topological sort of a graph. Each node has an id, and set (table with no values) of dependencies. Dependency before represents a link from a node, which should appear in the sorted list before the node. Returns a sorted list of nodes.

Arguments:
  • nodes : array<auto(Node)>

16.3. Table manipulation

intersection(a: table<auto(TT), void>; b: table<auto(TT), void>): table<TT, void>

Returns the intersection of two sets

Arguments:
  • a : table<auto(TT);void>

  • b : table<auto(TT);void>

union(a: table<auto(TT), void>; b: table<auto(TT), void>): table<TT, void>

Returns the union of two sets

Arguments:
  • a : table<auto(TT);void>

  • b : table<auto(TT);void>

difference(a: table<auto(TT), void>; b: table<auto(TT), void>): table<TT, void>

Returns the difference of two sets

Arguments:
  • a : table<auto(TT);void>

  • b : table<auto(TT);void>

identical(a: table<auto(TT), void>; b: table<auto(TT), void>): bool

Returns true if the two sets are identical

Arguments:
  • a : table<auto(TT);void>

  • b : table<auto(TT);void>