![]() |
|
![]() |
| CondInclude | EmptySet | Exclude | HighIndex |
| Include | Included | SetDifference | SetIntersection |
| SetPopulation | SetSize | SetSymmetricDifference | SetToCompliment |
| SetToEmpty | SetToFull | SetUnion |
procedure CondInclude
(TheSet : in out ModSys.Word_U_Array;
bit : in ModSys.S_Natural16;
SetIt : in out boolean);
--*
-- CondInclude - Conditionally include an element in a set.
--
--
-- This routine adds the specified element to the set only if it is not
-- currently in the set. A flag is returned FALSE if the element is
-- already in the set.
--
-- CALLING SEQUENCE -
--
-- CondInclude (TheSet, Bit, SetIt)
--
-- ENTRY -
--
-- TheSet : ModSys.word_u_array
-- An array of words representing the elements of a set.
--
-- Bit : ModSys.S_natural
-- The set element (zero relative) to be included in the set TheSet (0..n).
--
-- EXIT -
--
-- TheSet : ModSys.word_u_array
-- An array of words representing the updated set.
--
-- SetIt : boolean
-- TRUE if the element was not already in the set.
--
-- EXAMPLE -
--
-- See Example at end of file.
--
function EmptySet
(TheSet : in ModSys.Word_U_Array;
totalElements : in ModSys.S_Natural16) return boolean;
--*
-- EmptySet - Test for an empty set.
--
--
-- This routine tests a set to see if it is empty.
--
-- CALLING SEQUENCE -
--
-- Test := EmptySet (TheSet, totalElements)
--
-- ENTRY -
--
-- totalElements : ModSys.S_natural
-- The total number of elements in the set.
--
-- TheSet : ModSys.word_u_array
-- An array of words representing the empty set.
--
-- EXIT -
--
-- Test : boolean
-- TRUE if TheSet is equivalent to the empty set.
--
-- EXAMPLE -
--
-- See Example at end of file.
--
procedure Exclude
(TheSet : in out ModSys.Word_U_Array;
bit : in ModSys.S_Natural16);
--*
-- Exclude - Exclude an element from a set.
--
--
-- This routine removes the element from the set represented by a general
-- set of words.
--
-- CALLING SEQUENCE -
--
-- Exclude (TheSet, Bit)
--
-- ENTRY -
--
-- TheSet : ModSys.word_u_array
-- An array of words representing the elements of a set.
--
-- Bit : ModSys.S_natural
-- The set element (zero relative) to be excluded from the set S.
--
-- EXIT -
--
-- TheSet : ModSys.word_u_array
-- An array of words representing the updated set.
--
-- EXAMPLE -
--
-- See Example at end of file.
--
function HighIndex
(totalElements : in ModSys.S_Natural16) return ModSys.S_Natural16;
--*
-- HighIndex - Return the highest index number for a set.
--
--
-- This routine returns index number (zero relative) of the highest word
-- for a set containing the specified number of elements.
--
-- CALLING SEQUENCE -
--
-- highIndex := SetSize (maxElement)
--
-- ENTRY -
--
-- totalElements : ModSys.S_natural
-- The total number of elements in the set.
--
-- EXIT -
--
-- highIndex : ModSys.S_natural
-- The high index of this set.
--
-- EXAMPLE -
--
-- See Example at end of file.
--
procedure Include
(TheSet : in out ModSys.Word_U_Array;
bit : in ModSys.S_Natural16);
--*
-- Include - Include an element in a set.
--
--
-- This routine adds the specified element to the set represented by the
-- general set of words.
--
-- CALLING SEQUENCE -
--
-- Include (TheSet, Bit)
--
-- ENTRY -
--
-- TheSet : ModSys.word_u_array
-- An array of words representing the elements of a set.
--
-- Bit : ModSys.S_natural
-- The set element (zero relative) to be included in the set TheSet (0..n).
--
-- EXIT -
--
-- TheSet : ModSys.word_u_array
-- An array of words representing the updated set.
--
-- EXAMPLE -
--
-- See Example at end of file.
--
function Included
(TheSet : in ModSys.Word_U_Array;
bit : in ModSys.S_Natural16) return boolean;
--*
-- Included - Check to see if an element is in a set.
--
--
-- This routine checks if an element is in the set represented by the
-- general set of words.
--
-- CALLING SEQUENCE -
--
-- Test := Included (TheSet, Bit)
--
-- ENTRY -
--
-- TheSet : ModSys.word_u_array
-- An array of words representing the elements of a set.
--
-- Bit : ModSys.S_natural
-- The set element (zero relative) to be tested in the set S.
--
-- EXIT -
--
-- Test : boolean
-- TRUE if the element is in the set.
--
-- EXAMPLE -
--
-- See Example at end of file.
--
procedure SetDifference
(S1 : in out ModSys.Word_U_Array;
S2 : in out ModSys.Word_U_Array;
TheSet : in out ModSys.Word_U_Array;
totalElements : in ModSys.S_Natural16);
--*
-- SetDifference - Perform the difference of two sets.
--
--
-- This routine performs the equivalent of a difference set operation for
-- a general set of words. An element x is IN the set (S1 Difference S2)
-- iff (x IN S1) AND NOT (x IN S2)
--
-- CALLING SEQUENCE -
--
-- SetDifference (S1, S2, TheSet, totalElements)
--
-- ENTRY -
--
-- S1 : ModSys.word_u_array
-- An array of words representing the elements of a set.
--
-- S2 : ModSys.word_u_array
-- An array of words representing the elements of a set.
--
-- totalElements : ModSys.S_natural
-- The total number of elements in the set.
--
-- EXIT -
--
-- TheSet : ModSys.word_u_array
-- An array of words representing the set (S1 Difference S2).
--
-- EXAMPLE -
--
-- See Example at end of file.
--
procedure SetIntersection
(S1 : in out ModSys.Word_U_Array;
S2 : in out ModSys.Word_U_Array;
TheSet : in out ModSys.Word_U_Array;
totalElements : in ModSys.S_Natural16);
--*
-- SetIntersection - Perform the intersection of two sets.
--
--
-- This routine performs the equivalent of an intersection set operation
-- for a general set of words. An element x is IN the set
-- (S1 Intersection S2) iff (x IN S1) AND (x IN S2).
--
-- CALLING SEQUENCE -
--
-- SetIntersection (S1, S2, TheSet, totalElements)
--
-- ENTRY -
--
-- S1 : ModSys.word_u_array
-- An array of words representing the elements of a set.
--
-- S2 : ModSys.word_u_array
-- An array of words representing the elements of a set.
--
-- totalElements : ModSys.S_natural
-- The total number of elements in the set.
--
-- EXIT -
--
-- TheSet : ModSys.word_u_array
-- An array of words representing the set (S1 Intersection S2).
--
-- EXAMPLE -
--
-- See Example at end of file.
--
function SetPopulation
(TheSet : in ModSys.Word_U_Array;
totalElements : in ModSys.S_Natural16) return ModSys.S_Natural16;
--*
-- SetPopulation - Count the number of elements in a set.
--
--
-- This routine returns the number of elements in a set. If the set is
-- empty then this routine returns zero.
--
-- CALLING SEQUENCE -
--
-- Knt := SetPopulation (TheSet, totalElements)
--
-- ENTRY -
--
-- TheSet : ModSys.word_u_array
-- An array of words representing the empty set.
--
-- totalElements : ModSys.S_natural
-- The total number of elements in the set.
--
-- EXIT -
--
-- Knt : ModSys.S_natural
-- The number of elements in the set.
--
-- EXAMPLE -
--
-- See Example at end of file.
--
function SetSize
(totalElements : in ModSys.S_Natural16) return ModSys.S_Natural16;
--*
-- SetSize - Return number of words required for a set.
--
--
-- This routine returns the number of words required to contain a set with
-- the specified number of elements.
--
-- CALLING SEQUENCE -
--
-- numberOfBitsets := SetSize (maxElement)
--
-- ENTRY -
--
-- totalElements : ModSys.S_natural
-- The total number of elements in the set.
--
-- EXIT -
--
-- numberOfBitsets : ModSys.S_natural
-- The number of words required for this set.
--
-- EXAMPLE -
--
-- See Example at end of file.
--
procedure SetSymmetricDifference
(S1 : in out ModSys.Word_U_Array;
S2 : in out ModSys.Word_U_Array;
TheSet : in out ModSys.Word_U_Array;
totalElements : in ModSys.S_Natural16);
--*
-- SetSymmetricDifference - Perform symmetric diff. of two sets.
--
--
-- This routine performs the equivalent of a symmetric difference set
-- operation for a general set of words. An element x is in the set
-- (S1 SymmetricDifference S2) iff ((x IN S1) AND NOT (x IN S2))
-- OR NOT (x IN S1) AND (x in S2)). This is sometimes known as an
-- exclusive OR operation.
--
-- CALLING SEQUENCE -
--
-- SetSymmetricDifference (S1, S2, R, totalElements)
--
-- ENTRY -
--
-- S1 : ModSys.word_u_array
-- An array of words representing the elements of a set.
--
-- S2 : ModSys.word_u_array
-- An array of words representing the elements of a set.
--
-- totalElements : ModSys.S_natural
-- The total number of elements in the set.
--
-- EXIT -
--
-- TheSet : ModSys.word_u_array
-- An array of words representing the set
-- (S1 SymmetricDifference S2).
--
-- EXAMPLE -
--
-- See Example at end of file.
--
procedure SetToCompliment
(TheSet : in out ModSys.Word_U_Array;
TheSet2 : in out ModSys.Word_U_Array;
totalElements : in ModSys.S_Natural16);
--*
-- SetToCompliment - Set a set to the complement of another.
--
--
-- This routine complements a set represented by an array of words.
--
-- CALLING SEQUENCE -
--
-- SetToCompliment (TheSet, TheSet2, totalElements)
--
-- ENTRY -
--
-- TheSet : ModSys.word_u_array
-- The set to be complemented.
--
-- totalElements : ModSys.S_natural
-- The total number of elements in the set.
--
-- EXIT -
--
-- TheSet2 : ModSys.word_u_array
-- An array of words representing the complemented set.
--
-- EXAMPLE -
--
-- See Example at end of file.
--
procedure SetToEmpty
(TheSet : in out ModSys.Word_U_Array;
totalElements : in ModSys.S_Natural16);
--*
-- SetToEmpty - Generate an empty set.
--
--
-- This routine clears a set represented by a general set of words, thus
-- making it equivalent to the empty set.
--
-- CALLING SEQUENCE -
--
-- SetToEmpty (TheSet, totalElements)
--
-- ENTRY -
--
-- totalElements : ModSys.S_natural
-- The total number of elements in the set. This cannot be zero.
--
-- EXIT -
--
-- TheSet : ModSys.word_u_array
-- An array of words representing the empty set.
--
-- EXAMPLE -
--
-- See Example at end of file.
--
procedure SetToFull
(TheSet : in out ModSys.Word_U_Array;
totalElements : in ModSys.S_Natural16);
--*
-- SetToFull - Generate a full set.
--
--
-- This routine adds every element to a set represented by a general array
-- of words, thus making it equivalent to the universe set.
--
-- CALLING SEQUENCE -
--
-- SetToFull (TheSet, totalElements)
--
-- ENTRY -
--
-- totalElements : ModSys.S_natural
-- The total number of elements in the set.
--
-- EXIT -
--
-- TheSet : ModSys.word_u_array
-- An array of words representing the universe set.
--
-- EXAMPLE -
--
-- See Example at end of file.
--
procedure SetUnion
(S1 : in out ModSys.Word_U_Array;
S2 : in out ModSys.Word_U_Array;
TheSet : in out ModSys.Word_U_Array;
totalElements : in ModSys.S_Natural16);
--*
-- SetUnion - Perform the union of two sets.
--
--
-- This routine performs the equivalent of a union set operation for a
-- general set of words. An element x is IN the set (S1 Union S2) if
-- (x IN S1) OR (x IN S2)
--
-- CALLING SEQUENCE -
--
-- SetUnion (S1, S2, TheSet, totalElements)
--
-- ENTRY -
--
-- S1 : ModSys.word_u_array
-- An array of words representing the elements of a set.
--
-- S2 : ModSys.word_u_array
-- An array of words representing the elements of a set.
--
-- totalElements : ModSys.S_natural
-- The total number of elements in the set.
--
-- EXIT -
--
-- TheSet : ModSys.word_u_array
-- An array of words representing the set (S1 Union S2).
--
-- EXAMPLE -
--
-- with NewSets;
-- with ModSys;
--
-- procedure setdemo is
-- NumBits : constant := 960;
--
-- numSets : ModSys.S_Natural16;
-- s1,s2,s3 : ModSys.word_u_access;
-- maxInd : ModSys.S_Natural16;
-- wordPos : ModSys.S_Natural16;
-- bitPos : ModSys.S_Natural16;
-- set,set2 : boolean;
-- empty : boolean;
-- setCount : ModSys.S_Natural16;
--
-- begin
-- -- Find out how big an array is needed to process the desired number
-- -- of elements. numSets should be 60. maxInd should be 59 (zero
-- -- relative)
--
-- numSets := NewSets.SetSize (NumBits);
-- maxInd := NewSets.HighIndex (NumBits);
--
-- s1 := new ModSys.word_u_array(1..numSets);
-- s2 := new ModSys.word_u_array(1..numSets);
-- s3 := new ModSys.word_u_array(1..numSets);
--
-- -- Make three sets equivalent to empty set
-- NewSets.SetToEmpty (s1.all, NumBits);
-- NewSets.SetToEmpty (s2.all, NumBits);
-- NewSets.SetToEmpty (s3.all, NumBits);
--
-- -- This one exceeds high element so set2 could be TRUE or FALSE
-- set2 := NewSets.Included (s1.all, NumBits);
--
-- -- This checks if last valid element is set set2 would be FALSE
-- set2 := NewSets.Included (s2.all, NumBits-1);
--
-- -- This one exceeds high element so expect the unexpected
-- NewSets.Include (s1.all, NumBits);
--
-- -- This sets the last valid element.
-- NewSets.Include (s2.all, NumBits-1);
--
-- -- This checks if first valid element is set and if it is, set2 is
-- -- FALSE. If it is not set, set it and set2 is TRUE
-- NewSets.CondInclude (s1.all, 0, set2);
--
-- -- This checks if 2nd valid element is set and if it is, set2 is
-- -- FALSE. If it is not set, set it and set2 is TRUE
-- NewSets.CondInclude (s2.all, 1, set2);
--
-- -- All elements in s1 and not in s2 will be set in s3. {0}
-- NewSets.SetDifference (s1.all, s2.all, s3.all, NumBits);
--
-- -- How many elements does s3 have? (1)
-- setCount := NewSets.SetPopulation (s3.all, NumBits);
--
-- -- Exclusive OR -- In s1 or s2, but not in both s3 = {0,1,959}
-- NewSets.SetSymmetricDifference (s1.all, s2.all, s3.all, NumBits);
--
-- -- How many elements does s3 have? (3)
-- setCount := NewSets.SetPopulation (s3.all, NumBits);
--
-- -- s3 := NOT s3
-- NewSets.SetToCompliment (s3.all, s3.all, NumBits);
--
-- -- How many elements does s3 have? (957)
-- setCount := NewSets.SetPopulation (s3.all, NumBits);
--
-- -- Is s3 up through the last element equal to the empty set {} (NO)
-- empty := NewSets.EmptySet (s3.all, NumBits);
--
-- -- Remove the 3rd element from s3
-- NewSets.Exclude (s3.all, 2);
--
-- -- How many elements does s3 have? (956)
-- setCount := NewSets.SetPopulation (s3.all, NumBits);
--
-- -- s1 contains all elements up through last element
-- NewSets.SetToFull (s1.all, NumBits);
--
-- -- s2 contains no elements up through last element
-- NewSets.SetToEmpty (s2.all, NumBits);
--
-- -- How many elements does s1 have? (960)
-- setCount := NewSets.SetPopulation (s1.all, NumBits);
--
-- -- s3 := s1 UNION s2 up through last element
-- NewSets.SetUnion (s1.all, s2.all, s3.all, NumBits);
--
-- -- How many elements does s3 have? (960)
-- setCount := NewSets.SetPopulation (s3.all, NumBits);
--
-- -- s3 := s1 OR s2 up through 100 elements
-- NewSets.SetUnion (s1.all, s2.all, s3.all, 100);
--
-- -- How many elements does s3 have? (100)
-- setCount := NewSets.SetPopulation (s3.all, 100);
--
-- -- s3 := s1 and s2 up through last element
-- NewSets.SetIntersection (s1.all, s2.all, s3.all, NumBits);
--
-- -- How many elements does s3 have? (0)
-- setCount := SetPopulation (s3.all, NumBits);
--
-- ModSys.free_wordaccess (s1);
-- ModSys.free_wordaccess (s2);
-- ModSys.free_wordaccess (s3);
-- end SetDemo;
--
Send mail to
warren.merrill@inl.gov
with questions or comments about this web site.
Copyright © 1989-2006 Battelle Energy Alliance