ATSLIB/libats/funset_listord

This package implements functional sets based on lists ordered according to some total ordering. The implementation should only be used for handling sets that are relatively small. For large sets, an implementation based on balanced trees may be considered.


  • set
  • set_type
  • compare_elt_elt
  • funset_nil
  • funset_sing
  • funset_make_list
  • funset_is_nil
  • funset_isnot_nil
  • funset_size
  • funset_is_member
  • funset_isnot_member
  • funset_insert
  • funset_remove
  • funset_union
  • funset_intersect
  • funset_diff
  • funset_symdiff
  • funset_equal
  • funset_compare
  • funset_is_subset
  • funset_is_supset
  • fprint_funset
  • fprint_funset$sep
  • funset_foreach
  • funset_foreach_env
  • funset_foreach$fwork
  • funset_listize
  • funset_flistize
  • funset_flistize$fopr
  • funset2list

  • set

    Synopsis

    typedef set (a:t0p) = set_type (a)

    Description

    The type constructor set is a shorthand for set_t0ype_type.

    set_type

    Synopsis

    abstype
    set_type (a:t@ype+) = ptr

    compare_elt_elt

    Synopsis

    fun{a:t0p}
    compare_elt_elt (x1: a, x2: a):<> int

    Description

    This function is for comparing elements in sets.

    funset_nil

    Synopsis

    fun{}
    funset_nil {a:t0p} ():<> set(a)

    Description

    This function forms an empty set.

    funset_sing

    Synopsis

    fun{a:t0p}
    funset_sing (x0: a):<> set(a) // singleton set

    Description

    Given an element x, this function forms the singleton set containing x.

    funset_make_list

    Synopsis

    fun{a:t0p}
    funset_make_list (xs: List(INV(a))):<> set(a)

    Description

    Given a list xs, this function forms the set consisting of elements in xs. Note that duplicated elements in xs are all removed in the formed set.

    funset_is_nil

    Synopsis

    fun{}
    funset_is_nil {a:t0p} (xs: set(INV(a))):<> bool

    funset_isnot_nil

    Synopsis

    fun{}
    funset_isnot_nil {a:t0p} (xs: set(INV(a))):<> bool

    funset_size

    Synopsis

    fun{a:t0p}
    funset_size (xs: set(INV(a))):<> size_t

    Description

    This function returns the size of a given set xs. Its time complexity is O(|xs|).

    funset_is_member

    Synopsis

    fun{a:t0p}
    funset_is_member (xs: set(INV(a)), x0: a):<> bool

    Description

    This function tests whether an element occurs in a given set xs. The time complexity of this function is O(|xs|).

    funset_isnot_member

    Synopsis

    fun{a:t0p}
    funset_isnot_member (xs: set(INV(a)), x0: a):<> bool

    Description

    This function tests whether an element does not occur in a given set xs. The time complexity of this function is O(|xs|).

    funset_insert

    Synopsis

    fun{a:t0p}
    funset_insert
      (xs: &set(INV(a)) >> _, x0: a):<!wrt> bool(*[x0] in [xs]*)

    Description

    This function adds an element to a given set xs. The time complexity of this function is O(|xs|).

    Return Value

    The function returns a boolean value indicating whether the element is already in the set xs.

    funset_remove

    Synopsis

    fun{a:t0p}
    funset_remove
      (xs: &set(INV(a)) >> _, x0: a):<!wrt> bool(*[x0] in [xs]*)

    Description

    This function removes an element from a given set xs. The time complexity of this function is O(|xs|).

    Return Value

    The function returns a boolean value indicating whether the element is actually removed from the set xs.

    funset_union

    Synopsis

    fun{a:t0p}
    funset_union (xs1: set(INV(a)), xs2: set(a)):<> set(a)

    Description

    Given sets xs1 and xs2, this function returns the union of xs1 and xs2. The time complexity of this function is O(|xs1|+|xs2|).

    funset_intersect

    Synopsis

    fun{a:t0p}
    funset_intersect (xs1: set(INV(a)), xs2: set(a)):<> set(a)

    Description

    Given sets xs1 and xs2, this function returns the intersection of xs1 and xs2. The time complexity of this function is O(|xs1|+|xs2|).

    funset_diff

    Synopsis

    Synopsis for [funset_diff] is unavailable.

    Description

    Given sets xs1 and xs2, this function returns the difference of xs1 from xs2. The time complexity of this function is O(|xs1|+|xs2|).

    funset_symdiff

    Synopsis

    fun{a:t0p}
    funset_symdiff (xs1: set(INV(a)), xs2: set(a)):<> set(a)

    Description

    Given sets xs1 and xs2, this function returns the symmetric difference between xs1 and xs2. The time complexity of this function is O(|xs1|+|xs2|).

    funset_equal

    Synopsis

    fun{a:t0p}
    funset_equal (xs1: set(INV(a)), xs2: set(a)):<> bool

    Description

    This function tests whether two given sets xs1 and xs2 are equal. The time complexity of this function is O(|xs1|+|xs2|).

    funset_compare

    Synopsis

    fun{a:t0p}
    funset_compare (xs1: set(INV(a)), xs2: set(a)):<> Sgn

    Description

    This function compares two given sets xs1 and xs2 based on the ordering induced from the one on set elements, which is implemented by compare_elt_elt. The time complexity of this function is O(|xs1|+|xs2|).

    funset_is_subset

    Synopsis

    fun{a:t0p}
    funset_is_subset (xs1: set(INV(a)), xs2: set(a)):<> bool

    Description

    Given sets xs1 and xs2, this function tests whether xs1 is a subset of xs2. The time complexity of this function is O(|xs1|+|xs2|).

    funset_is_supset

    Synopsis

    fun{a:t0p}
    funset_is_supset (xs1: set(INV(a)), xs2: set(a)):<> bool

    Description

    Given sets xs1 and xs2, this function tests whether xs1 is a superset of xs2. The time complexity of this function is O(|xs1|+|xs2|).

    fprint_funset

    Synopsis

    fun{a:t0p}
    fprint_funset
      (out: FILEref, xs: set(INV(a))): void

    Description

    This function prints out the elements in a given set. It calls fprint_funset$sep to print a separator between every two consecutive elements.

    fprint_funset$sep

    Synopsis

    fun{}
    fprint_funset$sep
      (out: FILEref): void // ", "

    Description

    This function template is called by fprint_funset. It prints out the string ", " (a comma followed by a space character) by default.

    funset_foreach

    Synopsis

    fun{a:t0p}
    funset_foreach (set: set(INV(a))): void

    funset_foreach_env

    Synopsis

    fun{
    a:t0p}{env:vt0p
    } funset_foreach_env
      (set: set(INV(a)), env: &(env) >> _): void

    funset_foreach$fwork

    Synopsis

    fun{
    a:t0p}{env:vt0p
    } funset_foreach$fwork
      (x: a, env: &(env) >> _): void

    funset_listize

    Synopsis

    fun{a:t0p}
    funset_listize(xs: set(INV(a))):<!wrt> List0_vt(a)

    Description

    Given a set xs, this function returns a linear list consisting of all the elements in xs. The time complexity of this function is O(|xs|).

    funset_flistize

    Synopsis

    fun{
    a:t0p}{b:t0p
    } funset_flistize (xs: set(INV(a))): List0_vt(b)

    Description

    Given a set xs, this function returns a linear list consisting of all the elements returned by calling funset_flistize$fopr on elements in xs.

    funset_flistize$fopr

    Synopsis

    fun{
    a:t0p}{b:t0p
    } funset_flistize$fopr(x: a): b

    funset2list

    Synopsis

    castfn
    funset2list{a:t0p} (xs: set(INV(a))):<> List0 (a)

    Description

    This function casts a set into a list in which elements are ordered descendingly.
    This page is created with ATS by Hongwei Xi and also maintained by Hongwei Xi. SourceForge.net Logo