tpu/u_setvbi.pas
{ ppc386 -va -vh *.pas }
{ COMIENZO DE DESCRIPCION
Conjuntos como arreglos de bits. keywords: conjunto
FIN DE DESCRIPCION }
{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
{ $Id: u_setvbi.pas,v 1.1 2002/04/25 15:57:09 mstorti Exp mstorti $}
unit u_setvbi;
interface
uses u_cuchar;
type
tipo_elemento = tipo_univ ;
setvbi = object
private
CU : CUchar;
LL : packed array [1..Nuniv] of boolean;
public
procedure INSERTA (c: tipo_elemento);
procedure SUPRIME (c: tipo_elemento);
procedure ANULA;
procedure IMPRIME (s: string);
function MIEMBRO (c: tipo_elemento) : boolean;
procedure UNION (A, B: setvbi);
procedure INTERSECCION (A, B: setvbi);
procedure DIFERENCIA (A, B: setvbi);
end;
implementation
{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
procedure setvbi.INSERTA (c: tipo_elemento);
var
i: integer;
begin
if ( CU.INDICE (c,i) ) then LL [i] := true;
end; { INSERTA }
{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
procedure setvbi.SUPRIME (c: tipo_elemento);
var
i: integer;
begin
if ( CU.INDICE (c,i) ) then LL [i] := false;
end; { SUPRIME }
{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
procedure setvbi.ANULA;
var
i: integer;
begin
for i:=1 to Nuniv do LL [i]:=false;
end;
{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
procedure setvbi.IMPRIME (s: string);
var
i: integer;
begin
write (s);
for i := 1 to Nuniv do begin
if ( LL [i] ) then begin
CU.IMPRIME (i);
write(' ');
end ; {if}
end ; {for}
writeln;
end;
{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
procedure setvbi.UNION (A, B: setvbi);
var
i : integer;
begin
for i := 1 to Nuniv do LL [i] := A.LL [i] or B.LL [i] ;
end;
{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
procedure setvbi.INTERSECCION (A, B: setvbi);
var
i: integer;
begin
for i := 1 to Nuniv do LL [i] := A.LL [i] and B.LL [i] ;
end;
{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
procedure setvbi.DIFERENCIA (A, B: setvbi);
var
i: integer;
begin
for i := 1 to Nuniv do LL [i] := A.LL [i] and not B.LL [i];
end;
{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
function setvbi.MIEMBRO (c: tipo_elemento) : boolean;
var
i: integer;
begin
if ( CU.INDICE (c,i) ) then
MIEMBRO := LL [i]
else begin
MIEMBRO := false
end ; {if}
end;
end.
{-----+-----+-----+-----+-----+-----+-----+-----+-----+-----}
Generated by GNU enscript 1.6.1.