with Text_IO; use Text_io; package body INTEGER_SETS is -- array INTEGER of BOOLEAN package IIO is new Text_IO.Integer_io(integer); --need integer output use iio; N:constant integer:=500; subtype ELEMENT is INTEGER range 1..N; type DATA is array(ELEMENT) of boolean; -- INTEGER_SET is access DATA ALL_FALSE:constant DATA:=DATA'(1..N=>false); function Member(I:INTEGER; ISIN:INTEGER_SET) return boolean is begin return ISIN.all(I); exception when CONSTRAINT_ERROR => return FALSE; -- ISIN=NULL --or I is outside range. end Member; function Empty(ISIN:INTEGER_SET) return boolean is --Empty(NULL_SET); begin --return ISIN.all/=all_false; for i in ISIN.all'range loop if ISIN.all(I) then return false; end if; end loop; return true; exception when CONSTRAINT_ERROR => return TRUE; -- ISIN=NULL end Empty; function "="(LEFT,RIGHT:INTEGER_SET) return boolean is EL:BOOLEAN:=Empty(LEFT); ER:BOOLEAN:=Empty(RIGHT); begin if EL or ER then return EL and ER; else return LEFT.all=RIGHT.all; end if; end "="; function Full(ISIN:INTEGER_SET) return boolean is begin return FALSE; end Full; procedure Make_Empty(S:out INTEGER_SET) is -- after S=NULL_SET begin S:=NULL; end; function Max(S:INTEGER_SET) return integer is begin for i in reverse S.all'range loop if S.all(I) then return I; end if; end loop; raise EMPTY_GET; exception when CONSTRAINT_ERROR => raise EMPTY_GET; end Max; function Min (S:INTEGER_SET) return integer is begin for i in S.all'range loop if S.all(I) then return I; end if; end loop; raise EMPTY_GET; exception when CONSTRAINT_ERROR => raise EMPTY_GET; end Min; procedure Put(S:in INTEGER_SET) is -- output set to standard output NOT_FIRST:BOOLEAN:=false; begin Put('{'); if not Empty(S) then for I in S.all'range loop if S.all(I) then if NOT_FIRST then Put(','); end if; NOT_FIRST:=TRUE; Put(I); end if; end loop; end if; Put('}'); end Put; procedure NORMALIZE(S:in out INTEGER_SET)is dummy:integer; begin dummy:=S.all'FIRST; return; exception when CONSTRAINT_ERROR => S:= new DATA'(ELEMENT=>FALSE);return; end NORMALIZE; procedure Put(I:INTEGER; INTO:in out INTEGER_SET) is begin NORMALIZE(INTO); INTO.all(I):=true; end Put; procedure Getmin(I: out integer; FROM:in out INTEGER_SET) is M:integer:=Min(FROM); begin Take(M,FROM); I:=M; end Getmin; procedure Get(I: out integer; FROM:in out INTEGER_SET) is begin Getmin(I,FROM); end Get; procedure Getmax(I: out integer; FROM:in out INTEGER_SET) is M:integer:=max(FROM); begin Take(M,FROM); I:=M; end Getmax; procedure Take(I: INTEGER; FROM:in out INTEGER_SET) is begin FROM.all(I):=FALSE; end Take; end INTEGER_SETS;