26. 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

26.2. Array manipulation

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

unique returns auto

argument

argument type

a

array<auto(TT)>

Returns array of the elements of a with duplicates removed.

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

sort_unique returns auto

argument

argument type

a

array<auto(TT)>

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.

reverse(a: array<auto>)

reverse returns auto

argument

argument type

a

array<auto>

Returns array of the elements of a in reverse order.

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

combine returns auto

argument

argument type

a

array<auto(TT)> const

b

array<auto(TT)> const

Returns array of the elements of a and then b.

reverse(a: auto)

reverse returns auto

argument

argument type

a

auto

Returns array of the elements of a in reverse order.

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

combine returns auto

argument

argument type

a

auto const

b

auto const

Returns array of the elements of a and then b.

26.3. Uncategorized

erase_all(arr: auto; value: auto const)

erase_all returns auto

argument

argument type

arr

auto

value

auto const

Erase all elements equal to value from arr

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

topological_sort returns auto

argument

argument type

nodes

array<auto(Node)> const

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.

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

intersection returns table<TT;void>

argument

argument type

a

table<auto(TT);void> const

b

table<auto(TT);void> const

Returns the intersection of two sets

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

union returns table<TT;void>

argument

argument type

a

table<auto(TT);void> const

b

table<auto(TT);void> const

Returns the union of two sets

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

difference returns table<TT;void>

argument

argument type

a

table<auto(TT);void> const

b

table<auto(TT);void> const

Returns the difference of two sets

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

identical returns bool

argument

argument type

a

table<auto(TT);void> const

b

table<auto(TT);void> const

Returns true if the two sets are identical