Class std.set

Set container prototype.

Note that Functions listed below are only available from the Set prototype returned by requiring this module, because Container objects cannot have object methods.

Prototype Chain ---------------

table `-> Object `-> Container `-> Set

See also:

Objects

std.set.Set Set prototype object.

Functions

std.set.delete (set, e) Delete an element from a set.
std.set.difference (set1, set2) Find the difference of two sets.
std.set.difference (set, e) Say whether an element is in a set.
std.set.elems (set) Iterator for sets.
std.set.equal (set1, set2) Find whether two sets are equal.
std.set.insert (set, e) Insert an element into a set.
std.set.intersection (set1, set2) Find the intersection of two sets.
std.set.proper_subset (set1, set2) Find whether one set is a proper subset of another.
std.set.subset (set1, set2) Find whether one set is a subset of another.
std.set.symmetric_difference (set1, set2) Find the symmetric difference of two sets.
std.set.union (set1, set2) Find the union of two sets.

Metamethods

std.set.__add (set1, set2) Union operator.
std.set.__div (set1, set2) Symmetric difference operator.
std.set.__le (set1, set2) Subset operator.
std.set.__lt (set1, set2) Proper subset operator.
std.set.__mul (set1, set2) Intersection operator.
std.set.__sub (set1, set2) Difference operator.


Objects

std.set.Set
Set prototype object.

Set also inherits all the fields and methods from std.container.Container.

Fields:

  • _type string object name (default "Set")

See also:

Usage:

    local std = require "std"
    std.prototype (std.set) --> "Set"
    os.exit (0)

Functions

Methods
std.set.delete (set, e)
Delete an element from a set.

Parameters:

Returns:

    std.set.Set the modified *set*

Usage:

    set.delete (available, found)
std.set.difference (set1, set2)
Find the difference of two sets.

Parameters:

Returns:

    std.set.Set a copy of *set1* with elements of *set2* removed

Usage:

    all = set.difference (all, {32, 49, 56})
std.set.difference (set, e)
Say whether an element is in a set.

Parameters:

Returns:

    `true` if *e* is in *set*, otherwise `false` otherwise

Usage:

    if not set.member (keyset, pressed) then return nil end
std.set.elems (set)
Iterator for sets.

Parameters:

Returns:

    *set* iterator

Usage:

    for code in set.elems (isprintable) do print (code) end
std.set.equal (set1, set2)
Find whether two sets are equal.

Parameters:

Returns:

    std.set.Set `true` if *set1* and *set2* each contain identical elements, `false` otherwise

Usage:

    if set.equal (keys, {META, CTRL, "x"}) then process (keys) end
std.set.insert (set, e)
Insert an element into a set.

Parameters:

Returns:

    std.set.Set the modified *set*

Usage:

    for byte = 32,126 do
      set.insert (isprintable, string.char (byte))
    end
std.set.intersection (set1, set2)
Find the intersection of two sets.

Parameters:

Returns:

    std.set.Set a new set with elements in both *set1* and *set2*

Usage:

    common = set.intersection (a, b)
std.set.proper_subset (set1, set2)
Find whether one set is a proper subset of another.

Parameters:

Returns:

    std.set.Set `true` if *set2* contains all elements in *set1* but not only those elements, `false` otherwise

Usage:

    if set.proper_subset (a, b) then
      for e in set.elems (set.difference (b, a)) do
        set.delete (b, e)
      end
    end
    assert (set.equal (a, b))
std.set.subset (set1, set2)
Find whether one set is a subset of another.

Parameters:

Returns:

    std.set.Set `true` if all elements in *set1* are also in *set2*, `false` otherwise

Usage:

    if set.subset (a, b) then a = b end
std.set.symmetric_difference (set1, set2)
Find the symmetric difference of two sets.

Parameters:

Returns:

    std.set.Set a new set with elements that are in *set1* or *set2* but not both

Usage:

    unique = set.symmetric_difference (a, b)
std.set.union (set1, set2)
Find the union of two sets.

Parameters:

Returns:

    std.set.Set a copy of *set1* with elements in *set2* merged in

Usage:

    all = set.union (a, b)

Metamethods

std.set.__add (set1, set2)
Union operator.

Parameters:

Returns:

    std.set.Set everything from *set1* plus everything from *set2*

See also:

Usage:

    union = set1 + set2
std.set.__div (set1, set2)
Symmetric difference operator.

Parameters:

Returns:

    std.set.Set everything from *set1* or *set2* but not both

See also:

Usage:

    symmetric_difference = set1 / set2
std.set.__le (set1, set2)
Subset operator.

Parameters:

Returns:

    std.set.Set `true` if everything in *set1* is also in *set2*

See also:

Usage:

    issubset = set1 <= set2
std.set.__lt (set1, set2)
Proper subset operator.

Parameters:

Returns:

    std.set.Set `true` if *set2* is not equal to *set1*, but does contain everything from *set1*

See also:

Usage:

    ispropersubset = set1 < set2
std.set.__mul (set1, set2)
Intersection operator.

Parameters:

Returns:

    std.set.Set anything this is in both *set1* and *set2*

See also:

Usage:

    intersection = set1 * set2
std.set.__sub (set1, set2)
Difference operator.

Parameters:

Returns:

    std.set.Set everything from *set1* that is not also in *set2*

See also:

Usage:

    difference = set1 - set2
generated by LDoc 1.5.0 Last updated 2026-07-25 13:31:42