Libraries
Hashsetof Source Code
 previous   up   next 

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

hashset

const func type: hashset (in type: baseType)

Abstract data type, describing sets of baseType values. This abstract data type uses hash maps to represent a set. Therefore it can be used if baseType values cannot be mapped to integer.


Operator Summary
setType
(attr setType) . value
Default value of setType ({}).
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.
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.

Function Summary
integer
card (in setType: aSet)
Compute the cardinality of a set.
baseType
rand (in setType: aSet)
Compute pseudo-random element from aSet.
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.
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 ({}).


in

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

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

"one" in {"one", "three"})  returns  TRUE
"two" in {"one", "three"})  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.

"one" not in {"one", "three"})  returns  FALSE
"two" not in {"one", "three"})  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.

|

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

Union of two sets.

{"one", "two"} | {"one", "three"}  returns  {"one", "two", "three"}
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.

{"one", "two"} & {"one", "three"}  returns  {"one"}
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.

{"one", "two"} >< {"one", "three"}  returns  {"two", "three"}
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.

{"one", "two"} - {"one", "three"}  returns  {"two"}
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.

Function Detail

card

const func integer: card (in setType: aSet)

Compute the cardinality of a set.

card({"one", "two", "three"})  returns  3
Returns:
the number of elements in aSet.

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.

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.


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.

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