/*
 * Copyright (c) 1996 by Satish Chandra, Brad Richards, Mark D. Hill, 
 * James R. Larus, and David A. Wood.
 *
 * Teapot is distributed under the following conditions:
 * 
 *     You may make copies of Teapot for your own use and modify those copies.
 * 
 *     All copies of Teapot must retain our names and copyright notice.
 * 
 *     You may not sell Teapot or distributed Teapot in conjunction with a
 *     commercial product or service without the expressed written consent of
 *     the copyright holders.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 * 
 */

# line 1 "bitvec.m"

Procedure BV_Clear(Var Vec: SHARER_LIST);
Begin
	Undefine Vec.Sh;
	Vec.Cnt := 0;
End;

Procedure BV_Include(Var Vec: SHARER_LIST; N: NODE);
Begin
	Vec.Sh[Vec.Cnt] := N;
	Vec.Cnt := Vec.Cnt + 1;
End;

Procedure BV_Delete(Var Vec: SHARER_LIST; N: NODE);
Var
	j : INTEGER;
	found : boolean;
	place : INTEGER;
Begin
	j := 0;
	found := false;
	While (j < Vec.Cnt) Do
		If (N = Vec.Sh[j]) Then
			place := j;
			found := true;
		Endif;
		j := j + 1;	
	End;
	If (found) Then
		Assert(!Isundefined(place)) "BV_Delete: place undefined";
		j := place;
		-- left shift
		While ((j+1) < Vec.Cnt) Do
			Vec.Sh[j] := Vec.Sh[j+1];
			j := j+1;
		End;
		Vec.Cnt := Vec.Cnt - 1;
		Undefine Vec.Sh[Vec.Cnt];
	Else
		Assert (false) "Attempt to delete something not there\n";
	Endif;
End;

Procedure BV_Undefine(Var Vec: SHARER_LIST);
Begin
	Undefine Vec;
End;

Function BV_IsMember(Vec: SHARER_LIST; N: NODE): boolean;
Var
	j : INTEGER;
Begin
	j := 0;
	While (j < Vec.Cnt) Do
		If (N = Vec.Sh[j]) Then
			return true;
		Endif;
		j := j + 1;
	End;
	return false;
End;

/*
 *------------------------------------------------------------------
 *
 * BV_PickMember --
 *
 *          Return any NODE included in the vector.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      None.
 *
 *------------------------------------------------------------------
 */
Function BV_PickMember(Vec: SHARER_LIST): NODE;
Var
Begin
	Assert(Vec.Cnt >= 0) "Attempt to pick nonexistent member";
	return Vec.Sh[0];
End;


