?? arandor.c
字號(hào):
/*
Copyright (c) 2003, Dan Kranz and Arnold Rom
All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
* The names of its contributors may not be used to endorse or
promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <roots.h>
// #############################################################################
// # LGOR (SETA,CPL,SETB,EMPTY) #
// # #
// # The union of SETA with SETB replaces SETB. #
// # #
// # EMPTY is set TRUE if the resultant set is empty and is set FALSE #
// # otherwise. #
// # #
// # LGOR, LGAND, and LGEXCl have identical arguments! #
// # #
// # SETA and SETB are represented as bit-strings of byte-length CPL; i.e. #
// # each byte of SETA or SETB represents 8 set members. The presence of a #
// # set member is represented by a coresponding on-bit. #
// # #
// # CPL may exceed 256 bytes! #
// # #
// # EMPTY is a LOGICAL*4 variable. #
// #############################################################################
// small internal routines
static void sos(void) {RootsSOS("ARANDOR sos exit\n"); abort();}
void lgor(
BYTE *seta,
long *cpl,
BYTE *setb,
long *empty
)
// ---------------------------------------------------------
{ // lgor START
// ---------------------------------------------------------
// local data
long nLongs,nBytes,i,*la,*lb;
BYTE *a=seta, *b=setb;
if(*cpl<0) sos();
nLongs=*cpl/sizeof(long); nBytes=*cpl%sizeof(long);
// form setb= seta | setb
for(i=0; i<nLongs; i++,a+=sizeof(long),b+=sizeof(long))
{
lb=(long *)b;
la=(long *)a;
*lb|=*la;
}
for(i=0; i<nBytes; i++,a+=sizeof(BYTE),b+=sizeof(BYTE)) *b|=*a;
// determine empty flag
*empty=TRUE;
for(i=0; i<*cpl; i++) if(setb[i]) {*empty=FALSE; break;}
return;
// ---------------------------------------------------------
} // lgor END
// ---------------------------------------------------------
// #############################################################################
// # LGAND (SETA,CPL,SETB,EMPTY) #
// # #
// # The intersection of SETA with SETB replaces SETB. #
// # #
// # EMPTY is set .TRUE. if the resultant set is empty and is set .FALSE. #
// # otherwise. #
// #############################################################################
void lgand(
BYTE *seta,
long *cpl,
BYTE *setb,
long *empty
)
// ---------------------------------------------------------
{ // lgand START
// ---------------------------------------------------------
// local data
long nLongs,nBytes,i,*la,*lb;
BYTE *a=seta, *b=setb;
if(*cpl<0) sos();
nLongs=*cpl/sizeof(long); nBytes=*cpl%sizeof(long);
// form setb= seta & setb
for(i=0; i<nLongs; i++,a+=sizeof(long),b+=sizeof(long))
{
lb=(long *)b;
la=(long *)a;
*lb&=*la;
}
for(i=0; i<nBytes; i++,a+=sizeof(BYTE),b+=sizeof(BYTE)) *b&=*a;
// determine empty flag
*empty=TRUE;
for(i=0; i<*cpl; i++) if(setb[i]) {*empty=FALSE; break;}
return;
// ---------------------------------------------------------
} // lgand END
// ---------------------------------------------------------
// #############################################################################
// # LGEXCL (SETA,CPL,SETB,EMPTY) #
// # #
// # The members (on-bits) of SETA are removed form SETB and the result #
// # replaces SETB. #
// # #
// # EMPTY is set TRUE if the resultant set is empty and is set FALSE #
// # otherwise. #
// #############################################################################
void lgexcl(
BYTE *seta,
long *cpl,
BYTE *setb,
long *empty
)
// ---------------------------------------------------------
{ // lgexcl START
// ---------------------------------------------------------
// local data
long nLongs,nBytes,i,*la,*lb;
BYTE *a=seta, *b=setb;
if(*cpl<0) sos();
nLongs=*cpl/sizeof(long); nBytes=*cpl%sizeof(long);
// remove seta from setb
for(i=0; i<nLongs; i++,a+=sizeof(long),b+=sizeof(long))
{
lb=(long *)b;
la=(long *)a;
*lb&=~*la;
}
for(i=0; i<nBytes; i++,a+=sizeof(BYTE),b+=sizeof(BYTE)) *b&=~*a;
// determine empty flag
*empty=TRUE;
for(i=0; i<*cpl; i++) if(setb[i]) {*empty=FALSE; break;}
return;
// ---------------------------------------------------------
} // lgexcl END
// ---------------------------------------------------------
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -