Libraries
Bitsetof Source Code
 previous   up   next 

Abstract data types
type
bitset (in type: baseType)
Abstract data type, describing sets of baseType values.

bitset

const func type: bitset (in type: baseType)

Abstract data type, describing sets of baseType values. This abstract data type assumes that baseType values can be mapped to integer with the ord function. Sets of integer numbers are described with bitset.


Operator Summary
setType
(attr setType) . value
Default value of setType ({}).
setType
(in setType: set1) | (in setType: set2)
Union of two sets.
setType
(in setType: set1) & (in setType: set2)
Intersection of two sets.
setType
(in setType: set1) >< (in setType: set2)
Symmetric difference of two sets.
setType
(in setType: set1) - (in setType: set2)
Difference of two sets.
void
(inout setType: dest) |:= (in setType: set2)
Assign the union of dest and set2 to dest.
void
(inout setType: dest) &:= (in setType: set2)
Assign the intersection of dest and set2 to dest.
void
(inout setType: dest) -:= (in setType: set2)
Assign the difference of dest and set2 to dest.
boolean
(in setType: set1) = (in setType: set2)
Check if two sets are equal.
boolean
(in setType: set1) <> (in setType: set2)
Check if two sets are not equal.
boolean
(in setType: set1) < (in setType: set2)
Determine if set1 is a proper subset of set2.
boolean
(in setType: set1) > (in setType: set2)
Determine if set1 is a proper superset of set2.
boolean
(in setType: set1) <= (in setType: set2)
Determine if set1 is a subset of set2.
boolean
(in setType: set1) >= (in setType: set2)
Determine if set1 is a superset of set2.
boolean
(in baseType: aValue) in (in setType: aSet)
Set membership test.
boolean
(in baseType: aValue) not in (in setType: aSet)
Negated set membership test.
void
(inout setType: aSet) @:= [ (in baseType: aValue) ] (in boolean: isElement)
Add or remove aValue to respectively from sSet.

Function Summary
integer
compare (in setType: set1, in setType: set2)
Compares two sets to make them useable as key in a hash table.
integer
hashCode (in setType: aSet)
Compute the hash value of a bitset.
void
incl (inout setType: aSet, in baseType: aValue)
Add aValue to the set aSet.
void
excl (inout setType: aSet, in baseType: aValue)
Remove aValue from the set aSet.
integer
card (in setType: aSet)
Compute the cardinality of a set.
baseType
rand (in setType: aSet)
Compute pseudo-random element from aSet.
baseType
min (in setType: aSet)
Minimum element of a set.
baseType
max (in setType: aSet)
Maximum element of a set.
baseType
next (in setType: aSet, in baseType: number)
Minimum element of aSet that is larger than number.
void
for (inout baseType: variable) range (in setType: aSet) do (in proc: statements) end for
For-loop where variable loops over the elements of the set aSet.
array baseType
toArray (in setType: aSet)
Obtain an array containing all the values in aSet.
string
str (in setType: aSet)
Convert a set to a string.

Operator Detail

. value

const setType: (attr setType) . value

Default value of setType ({}).


|

const func setType: (in setType: set1) | (in setType: set2)

Union of two sets.

{'a', 'b'} | {'a', 'c'}  returns  {'a', 'b', 'c'}
Returns:
the union of the two sets.
Raises:
MEMORY_ERROR - Not enough memory for the result.

&

const func setType: (in setType: set1) & (in setType: set2)

Intersection of two sets.

{'a', 'b'} & {'a', 'c'}  returns  {'a'}
Returns:
the intersection of the two sets.
Raises:
MEMORY_ERROR - Not enough memory for the result.

><

const func setType: (in setType: set1) >< (in setType: set2)

Symmetric difference of two sets.

{'a', 'b'} >< {'a', 'c'}  returns  {'b', 'c'}
Returns:
the symmetric difference of the two sets.
Raises:
MEMORY_ERROR - Not enough memory for the result.

-

const func setType: (in setType: set1) - (in setType: set2)

Difference of two sets.

{'a', 'b'} - {'a', 'c'}  returns  {'b'}
Returns:
the difference of the two sets.
Raises:
MEMORY_ERROR - Not enough memory for the result.

|:=

const proc: (inout setType: dest) |:= (in setType: set2)

Assign the union of dest and set2 to dest.

Raises:
MEMORY_ERROR - Not enough memory to create dest.

&:=

const proc: (inout setType: dest) &:= (in setType: set2)

Assign the intersection of dest and set2 to dest.

Raises:
MEMORY_ERROR - Not enough memory to create dest.

-:=

const proc: (inout setType: dest) -:= (in setType: set2)

Assign the difference of dest and set2 to dest.

Raises:
MEMORY_ERROR - Not enough memory to create dest.

=

const func boolean: (in setType: set1) = (in setType: set2)

Check if two sets are equal.

Returns:
TRUE if the two sets are equal, FALSE otherwise.

<>

const func boolean: (in setType: set1) <> (in setType: set2)

Check if two sets are not equal.

Returns:
FALSE if the two sets are equal, TRUE otherwise.

<

const func boolean: (in setType: set1) < (in setType: set2)

Determine if set1 is a proper subset of set2. set1 is a proper subset of set2 if

set1 <= set2 and set1 <> set2

holds.

Returns:
TRUE if set1 is a proper subset of set2, FALSE otherwise.

>

const func boolean: (in setType: set1) > (in setType: set2)

Determine if set1 is a proper superset of set2. set1 is a proper superset of set2 if

set1 >= set2 and set1 <> set2

holds.

Returns:
TRUE if set1 is a proper superset of set2, FALSE otherwise.

<=

const func boolean: (in setType: set1) <= (in setType: set2)

Determine if set1 is a subset of set2. set1 is a subset of set2 if no element X exists for which

X in set1 and X not in set2

holds.

Returns:
TRUE if set1 is a subset of set2, FALSE otherwise.

>=

const func boolean: (in setType: set1) >= (in setType: set2)

Determine if set1 is a superset of set2. set1 is a superset of set2 if no element X exists for which

X in set2 and X not in set1

holds.

Returns:
TRUE if set1 is a superset of set2, FALSE otherwise.

in

const func boolean: (in baseType: aValue) in (in setType: aSet)

Set membership test. Determine if aValue is a member of the set aSet.

'a' in {'a', 'c', 'd'}  returns  TRUE
'b' in {'a', 'c', 'd'}  returns  FALSE
Returns:
TRUE If aValue is a member of aSet, FALSE otherwise.

not in

const func boolean: (in baseType: aValue) not in (in setType: aSet)

Negated set membership test. Determine if aValue is not a member of the set aSet.

'a' not in {'a', 'c', 'd'}  returns  FALSE
'b' not in {'a', 'c', 'd'}  returns  TRUE
Returns:
FALSE If aValue is a member of aSet, TRUE otherwise.

@:= [

const proc: (inout setType: aSet) @:= [ (in baseType: aValue) ] (in boolean: isElement)

Add or remove aValue to respectively from sSet. Adding an existing value or remove a non-existing value leaves aSet unchanged.

Raises:
MEMORY_ERROR - If there is not enough memory.

Function Detail

compare

const func integer: compare (in setType: set1, in setType: set2)

Compares two sets to make them useable as key in a hash table. The sets are compared by determining the biggest element that is not present or absent in both sets. The set in which this element is not present is the smaller one. Note that the set comparison is not related to the concepts of subset or superset. With the comparison function compare it is possible to sort an array of sets or to use sets as key in a hash table.

Returns:
-1, 0 or 1 if the first argument is considered to be respectively less than, equal to, or greater than the second.

hashCode

const func integer: hashCode (in setType: aSet)

Compute the hash value of a bitset.

Returns:
the hash value.

incl

const proc: incl (inout setType: aSet, in baseType: aValue)

Add aValue to the set aSet. If aValue is already in aSet then aSet stays unchanged.

Raises:
MEMORY_ERROR - If there is not enough memory.

excl

const proc: excl (inout setType: aSet, in baseType: aValue)

Remove aValue from the set aSet. If aValue is not element of aSet then aSet stays unchanged.


card

const func integer: card (in setType: aSet)

Compute the cardinality of a set.

card({'a', 'b', 'c'})  returns  3
Returns:
the number of elements in aSet.
Raises:
RANGE_ERROR - Result does not fit into an integer.

rand

const func baseType: rand (in setType: aSet)

Compute pseudo-random element from aSet. The random values are uniform distributed.

Returns:
a random element such that rand(aSet) in aSet holds.
Raises:
RANGE_ERROR - If aSet is empty.

min

const func baseType: min (in setType: aSet)

Minimum element of a set. Delivers the element from aSet for which the following condition holds:

element <= X

for all X which are in the set.

min({'a', 'b', 'c'})  returns  'a'
Returns:
the minimum element of aSet.
Raises:
RANGE_ERROR - If aSet is the empty set.

max

const func baseType: max (in setType: aSet)

Maximum element of a set. Delivers the element from aSet for which the following condition holds:

element >= X

for all X which are in the set.

max({'a', 'b', 'c'})  returns  'c'
Returns:
the maximum element of aSet.
Raises:
RANGE_ERROR - If aSet is the empty set.

next

const func baseType: next (in setType: aSet, in baseType: number)

Minimum element of aSet that is larger than number.

next({'a', 'b', 'd', 'f', 'j'}, 'a')  returns  'b'
next({'a', 'b', 'd', 'f', 'j'}, 'b')  returns  'd'
next({'a', 'b', 'd', 'f', 'j'}, 'f')  returns  'j'
next({'a', 'b', 'd', 'f', 'j'}, 'j')  raises   RANGE_ERROR
Returns:
the minimum element of aSet that is larger than number.
Raises:
RANGE_ERROR - If aSet has no element larger than number.

for

const proc: for (inout baseType: variable) range (in setType: aSet) do (in proc: statements) end for

For-loop where variable loops over the elements of the set aSet.


toArray

const func array baseType: toArray (in setType: aSet)

Obtain an array containing all the values in aSet.

toArray({'a', 'b', 'c'})  returns  []('a', 'b', 'c')
Returns:
all the values from aSet.

str

const func string: str (in setType: aSet)

Convert a set to a string.

Returns:
the string result of the conversion.
Raises:
MEMORY_ERROR - Not enough memory to represent the result.


 previous   up   next