with Text_IO; use Text_io; --generic -- type ELEMENT is (<>); -- SIZE:integer:=500; -- with procedure Put(X:ELEMENT) is <>; package body SET_OF is -- array ELEMENT of BOOLEAN MAXEL:constant ELEMENT:=ELEMENT'VAL(SIZE); subtype INDEX is ELEMENT range ELEMENT'first..MAXEL; type DATA is array(INDEX) of boolean; -- Osets is access DATA ALL_FALSE:constant DATA:=DATA'(INDEX=>false); function Member(I:ELEMENT; ISIN:ESET) 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:ESET) 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 Full(ISIN:ESET) return boolean is begin return FALSE; end Full; procedure Empty(S:out ESET) is -- after S=NULL_SET begin S:=NULL; end; function Max(S:ESET) return ELEMENT 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:ESET) return ELEMENT 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 ESET) 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 ESET)is dummy:ELEMENT; begin dummy:=S.all'FIRST; return; exception when CONSTRAINT_ERROR => S:= new DATA'(ELEMENT=>FALSE);return; end NORMALIZE; procedure Put(I:ELEMENT; INTO:in out ESET) is begin NORMALIZE(INTO); INTO.all(I):=true; end Put; procedure Getmin(I: out ELEMENT; FROM:in out ESET) is M:ELEMENT:=Min(FROM); begin Take(M,FROM); I:=M; end Getmin; procedure Get(I: out ELEMENT; FROM:in out ESET) is begin Getmin(I,FROM); end Get; procedure Getmax(I: out ELEMENT; FROM:in out ESET) is M:ELEMENT:=max(FROM); begin Take(M,FROM); I:=M; end Getmax; procedure Take(I: ELEMENT; FROM:in out ESET) is begin FROM.all(I):=FALSE; end Take; end SET_OF;