Back to Atomvm

Module sets

main-apidocs-erlang-estdlib-sets.md

latest10.1 KB
Original Source

Module sets

Data Types

set()

abstract datatype : set(Element)

set()

set() = set(term())

Function Index

| add_element/2 | Return Set1 with Element inserted in it. | | del_element/2 | Return Set1 but with Element removed. | | filter/2 | Filter Set with Fun. | | filtermap/2 | Filters and maps elements in Set1 with function Fun. | | fold/3 | Fold function Fun over all elements in Set and return Accumulator. | | from_list/1 | Builds a set from the elements in List. | | from_list/2 | Builds a set from the elements in List using the specified version. | | intersection/1 | Return the intersection of the list of sets. | | intersection/2 | Return the intersection of Set1 and Set2. | | is_disjoint/2 | Check whether Set1 and Set2 are disjoint. | | is_element/2 | Return true if Element is an element of Set, else false. | | is_empty/1 | Returns true if Set is an empty set, otherwise false. | | is_equal/2 | Returns true if Set1 and Set2 are equal, that is when every element of one set is also a member of the respective other set, otherwise false. | | is_set/1 | Returns true if Set appears to be a set of elements, otherwise false. | | is_subset/2 | Return 'true' when every element of Set1 is also a member of Set2, else 'false'. | | map/2 | Map Set with Fun. | | new/0 | Returns a new empty set using the v2 format (a map). | | new/1 | Returns a new empty set (only v2 format is supported). | | size/1 | Returns the number of elements in Set. | | subtract/2 | Return all and only the elements of Set1 which are not also in Set2. | | to_list/1 | Returns the elements of Set as a list. | | union/1 | Return the union of the list of sets. | | union/2 | Return the union of Set1 and Set2. |

Function Details

add_element/2

add_element(Element, Set1) -> Set2
  • Set1 = set(Element)
  • Set2 = set(Element)

Element: the element to add
Set1: the set to add the element to

returns: Returns a new set formed from Set1 with Element inserted.

Return Set1 with Element inserted in it.

del_element/2

del_element(Element, Set1) -> Set2
  • Set1 = set(Element)
  • Set2 = set(Element)

Element: the element to remove
Set1: the set to remove the element from

returns: Returns Set1, but with Element removed.

Return Set1 but with Element removed.

filter/2

filter(Pred, Set1) -> Set2
  • Pred = fun((Element) -> boolean())
  • Set1 = set(Element)
  • Set2 = set(Element)

Pred: the boolean function to filter elements with
Set1: the set to filter

returns: Returns a set containing elements of Set1 that satisfy the boolean function Fun. The evaluation order is undefined.

Filter Set with Fun.

filtermap/2

filtermap(Fun, Set1) -> Set2
  • Fun = fun((Element1) -> boolean() | {true, Element2})
  • Set1 = set(Element1)
  • Set2 = set(Element1 | Element2)

Fun: the filter and map fun
Set1: the set to filter and map over

returns: Returns a set containing elements of Set1 that are filtered and mapped using Fun.

Filters and maps elements in Set1 with function Fun.

fold/3

fold(Function, Acc0, Set) -> Acc1
  • Function = fun((Element, AccIn) -> AccOut)
  • Set = set(Element)
  • Acc0 = Acc
  • Acc1 = Acc
  • AccIn = Acc
  • AccOut = Acc

Set: the set to fold over

returns: Returns the final value of the accumulator after folding the function over every element in the set.

Fold function Fun over all elements in Set and return Accumulator.

from_list/1

from_list(List) -> Set
  • List = [Element]
  • Set = set(Element)

List: the list of items that is used for building the set

returns: Returns a set of the elements in List.

Builds a set from the elements in List.

from_list/2

from_list(List, Version::[{version, 2}]) -> Set
  • List = [Element]
  • Set = set(Element)

List: the list to be converted to a set
Version: only version 2 is supported

returns: Returns a set of the elements in List at the given version.

Builds a set from the elements in List using the specified version. Only v2 format is supported.

intersection/1

intersection(SetList) -> Set
  • SetList = [set(Element), ...]
  • Set = set(Element)

SetList: the non-empty list of sets

returns: Returns the intersection of the non-empty list of sets.

Return the intersection of the list of sets.

intersection/2

intersection(Set1, Set2) -> Set3
  • Set1 = set(Element)
  • Set2 = set(Element)
  • Set3 = set(Element)

Set1: the first set
Set2: the second set

returns: Returns the intersection of Set1 and Set2.

Return the intersection of Set1 and Set2.

is_disjoint/2

is_disjoint(Set1, Set2) -> boolean()
  • Set1 = set(Element)
  • Set2 = set(Element)

Set1: the first set
Set2: the second set

returns: Returns true if Set1 and Set2 are disjoint (have no elements in common), otherwise false.

Check whether Set1 and Set2 are disjoint.

is_element/2

is_element(Element, Set) -> boolean()
  • Set = set(Element)

Element: the element to check
Set: the set to check against

returns: Returns true if Element is an element of Set, otherwise false.

Return true if Element is an element of Set, else false.

is_empty/1

is_empty(Set) -> boolean()
  • Set = set()

Set: the set to be checked for emptiness

returns: Returns true if Set is an empty set, otherwise false.

Returns true if Set is an empty set, otherwise false.

is_equal/2

is_equal(Set1, Set2) -> boolean()
  • Set1 = set()
  • Set2 = set()

Set1: first set to be checked for equality
Set2: second set to be checked for equality

returns: Return true if Set1 and Set2 contain the same elements, otherwise false.

Returns true if Set1 and Set2 are equal, that is when every element of one set is also a member of the respective other set, otherwise false.

is_set/1

is_set(Set) -> boolean()
  • Set = term()

Set: the term that will be checked

returns: Return true if Set is a set of elements, else false.

Returns true if Set appears to be a set of elements, otherwise false.

Note that the test is shallow and will return true for any term that coincides with the possible representations of a set.

is_subset/2

is_subset(Set1, Set2) -> boolean()
  • Set1 = set(Element)
  • Set2 = set(Element)

Set1: the first set
Set2: the second set

returns: Returns true when every element of Set1 is also a member of Set2, otherwise false.

Return ‘true’ when every element of Set1 is also a member of Set2, else ‘false’.

map/2

map(Fun, Set1) -> Set2
  • Fun = fun((Element1) -> Element2)
  • Set1 = set(Element1)
  • Set2 = set(Element2)

Fun: the mapping function
Set1: the set to map over

returns: Returns a set containing elements of Set1 that are mapped using Fun.

Map Set with Fun.

new/0

new() -> set(none())

returns: Returns a new empty set.

Returns a new empty set using the v2 format (a map).

new/1

new(Version::[{version, 2}]) -> set(none())

Version: must be {version, 2}

returns: Returns a new empty set.

Returns a new empty set (only v2 format is supported).

size/1

size(Set) -> non_neg_integer()
  • Set = set()

Set: the set for which size will be returned

returns: Return the number of elements in Set.

Returns the number of elements in Set.

subtract/2

subtract(Set1, Set2) -> Set3
  • Set1 = set(Element)
  • Set2 = set(Element)
  • Set3 = set(Element)

Set1: the first set
Set2: the second set

returns: Returns only the elements of Set1 that are not also elements of Set2.

Return all and only the elements of Set1 which are not also in Set2.

to_list/1

to_list(Set) -> List
  • Set = set(Element)
  • List = [Element]

Set: the set to be converted to a list

returns: Return the elements in Set as a list.

Returns the elements of Set as a list. The order of the returned elements is undefined.

union/1

union(SetList) -> Set
  • SetList = [set(Element)]
  • Set = set(Element)

SetList: the list of sets

returns: Returns the merged (union) set of the list of sets.

Return the union of the list of sets.

union/2

union(Set1, Set2) -> Set3
  • Set1 = set(Element)
  • Set2 = set(Element)
  • Set3 = set(Element)

Set1: the first set
Set2: the second set

returns: Returns the merged (union) set of Set1 and Set2.

Return the union of Set1 and Set2.