OScript API/Built-in Package Index |
The Set built-in provides a set datatype with fast membership checks, and support for common set operations like union, intersection and difference.
Unlike a List, Sets contain each element only once, and have no defined order.
Generates a Set from a List
Inserts a new element into a Set.
Computes the intersection of two sets
Returns the largest numerical element in the set.
Returns the smallest numerical element in the set.
Removes an element from the Set.
Subtracts the contents of one set from another
Computes the symmetric difference of two sets
Generates a List from a Set
Computes the union of two sets
Inserts an element into this Set.
Computes the intersection of this and another set
Returns the largest numerical element in the set.
Returns the smallest numerical element in the set.
Removes an element from this Set.
Subtracts the contents of another set from this one
Computes the symmetric difference of this and another set
Generates a List from this Set
Computes the union of this and another set
Converts a List into a Set.
The List to convert.
The Set generated from the List.
List myList = { 'a', 'b', 'c', 'a', 1, 1, 1, 2, 3 } Set mySet = Set.FromList( myList ) echo( mySet )
results in
set{'a','b','c',1,2,3}
Adds an element to the Set. Unlike Lists, Sets are mutable, so the this set is modified.
The set to add the element to.
The element to add to the set.
The Set, with the element added.
Set mySet = Set.FromList({'a', 'b', 1, 3}) Set myOtherSet = Set.Insert( mySet, 'c' ) echo( mySet ) echo( myOtherSet )
results in
{'a','b','c',1,3} {'a','b','c',1,3}
Computes the intersection of two sets - the set will contain an element if and only if it was contained in both of the source sets.
First set in the intersection.
Second set in the intersection.
The intersection of the two sets.
Set first = Set.FromList({'a', 'b', 1, 3}) Set second = Set.FromList({'a', 'c', 1, 2}) Set intersection = Set.Intersect( first, second ) echo( intersection )
results in
set{'a',1}
Returns the largest numerical element in the set. See List.Max().
Set to find the largest numerical value from.
Largest numerical element in the set.
Returns the smallest numerical element in the set. See List.Min().
Set to find the smallest numerical value from.
Smallest numerical element in the set.
Removes an element from the Set. Unlike Lists, Sets are mutable, so the this set is modified.
The set to remove the element from.
The element to remove from the set.
The Set, with the element removed.
Set mySet = Set.FromList({'a', 'b', 1, 3}) Set myOtherSet = Set.Remove( mySet, 'a' ) echo( mySet ) echo( myOtherSet )
results in
{'b',1,3} {'b',1,3}
Subtracts the contents of the second set from the first. The set will contain an element if and only if it was contained in the first set and not in the second.
The set being subtracted from.
The set being subtracted.
The difference of the two sets.
Set first = Set.FromList({'a', 'b', 1, 3}) Set second = Set.FromList({'a', 'c', 1, 2}) Set difference = Set.Subtract( first, second ) echo( difference )
results in
set{'b',3}
Computes the symmetric difference of two sets - the set will contain an element if and only if it was contained in only one of the source sets.
Set.SymmetricDifference( a, b )
is equivalent to
Set.Union( Set.Subtract( a, b ), Set.Subtract( b, a ) )
First set in the symmetric difference.
Second set in the symmetric difference.
The symmetric difference of the two sets.
Set first = Set.FromList({'a', 'b', 1, 3}) Set second = Set.FromList({'a', 'c', 1, 2}) Set symdiff = Set.SymmetricDifference( first, second ) echo( symdiff )
results in
set{'b','c',2,3}
Converts a Set into a List.
The Set to convert.
The List generated from the Set.
Set first = Set.FromList({'a', 'b', 1, 3}) Set second = Set.FromList({'a', 'c', 1, 2}) Set symdiff = Set.SymmetricDifference( first, second ) echo( Set.ToList( symdiff ) )
results in
{'a','b','c',1,2,3}
Computes the union of two sets - the set will contain an element if and only if it was contained in at least one of the source sets.
First set in the union.
Second set in the union.
The union of the two sets.
Set first = Set.FromList({'a', 'b', 1, 3}) Set second = Set.FromList({'a', 'c', 1, 2}) Set union = Set.Union( first, second ) echo( union )
results in
set{'a','b','c',1,2,3}
Adds an element to this Set. Unlike Lists, Sets are mutable, so the this set is modified.
The element to add to this set.
This Set, with the element added.
Set mySet = Set.FromList({'a', 'b', 1, 3}) Set myOtherSet = mySet.Insert( mySet, 'c' ) echo( mySet ) echo( myOtherSet )
results in
{'a','b','c',1,3} {'a','b','c',1,3}
Computes the intersection of this and another set - the resulting set will contain an element if and only if it was contained in both of the source sets.
The other set in the intersection.
The intersection of this and another set.
Set first = Set.FromList({'a', 'b', 1, 3}) Set second = Set.FromList({'a', 'c', 1, 2}) Set intersection = first.Intersect( second ) echo( intersection )
results in
set{'a',1}
Returns the largest numerical element in the set. See List.Max().
Largest numerical element in the set.
Returns the smallest numerical element in the set. See List.Min().
Smallest numerical element in the set.
Removes an element from this Set. Unlike Lists, Sets are mutable, so the this set is modified.
The element to remove from this set.
This Set, with the element removed.
Set mySet = Set.FromList({'a', 'b', 1, 3}) Set myOtherSet = mySet.Remove( mySet, 'a' ) echo( mySet ) echo( myOtherSet )
results in
{'b',1,3} {'b',1,3}
Subtracts the contents of another set from this one. The resulting set will contain an element if and only if it was contained in the first set and not in the second.
The set being subtracted.
The difference of this and another set.
Set first = Set.FromList({'a', 'b', 1, 3}) Set second = Set.FromList({'a', 'c', 1, 2}) Set difference = first.Subtract( second ) echo( difference )
results in
set{'b',3}
Computes the symmetric difference of this and another set - the resulting set will contain an element if and only if it was contained in only one of the source sets.
a.SymmetricDifference( b )
is equivalent to
a.Subtract( b ).Union( b.Subtract( a ) )
The other set in the symmetric difference.
The symmetric difference of this and the other set.
Set first = Set.FromList({'a', 'b', 1, 3}) Set second = Set.FromList({'a', 'c', 1, 2}) Set symdiff = first.SymmetricDifference( second ) echo( symdiff )
results in
set{'b','c',2,3}
Converts this Set into a List.
The List generated from this Set.
Set first = Set.FromList({'a', 'b', 1, 3}) Set second = Set.FromList({'a', 'c', 1, 2}) Set symdiff = Set.SymmetricDifference( first, second ) echo( symdiff.ToList() )
results in
{'a','b','c',1,2,3}
Computes the union of this and another set - the resulting set will contain an element if and only if it was contained in at least one of the source sets.
The other set in the union.
The union of the two sets.
Set first = Set.FromList({'a', 'b', 1, 3}) Set second = Set.FromList({'a', 'c', 1, 2}) Set union = first.Union( second ) echo( union )
results in
set{'a','b','c',1,2,3}
Copyright © 2023 OpenText Corporation. All rights reserved. |