Example #1
0
void IDLMRecord::IsDoOnce(bool value)
    {
    SETBIT(IDLF.value, fIsDoOnce, value);
    }
Example #2
0
void WRLDRecord::IsNeedsWaterAdjustment(bool value)
    {
    SETBIT(PNAM.value, fIsNeedsWaterAdjustment, value);
    }
void main(void){
  __disable_interrupt();
  //Anolog mux channel select output
  DDRA = 0x3B;
  
  DDRB = 0xFF;          //initialize LCD
  SETBIT(PORTB, 0);     //deselect slave
  init_lcd_dog();
  clear_dsp();
  
  DDRD = 0x01;                  //  initialize PortD for interrupt
  PORTD = 0x02;
  
  SETBIT(DDRD, 7);    //enable buzzer output
  SETBIT(PORTD, 7);   //disable buzzer
  
  EIMSK = 0x0F;                 // enable individual interrupt
  EICRA = 0x53;
  
  __enable_interrupt();
  
  //infinite loop -- approximately 1 second for each loop
  while(1){
    if(present_state == Limit){
      __EEGET(temp_limit,channel_display);
      if(flag & (1 << 0)){
        temp_int = ((signed int)(temp_limit)*9)/5 + 32;
        unit_temp = 'F';
      }else{
        temp_int = (signed int)temp_limit;
        unit_temp = 'C';
      }
      
      clear_dsp();
      printf("Limit: %d ",temp_int);
      putchar(unit_temp);
      update_lcd_dog();
      
    }else{
      for(channel_conv = 0; channel_conv < 8; channel_conv++){
        DG528_driver(channel_conv);       //select channel
        for(i = 0; i < 10; i++){  //conv for each channel 10 times
          channel_voltage[channel_conv][i%8] = ADC161_conv();
        }
      }
      
      if(present_state == Auto){
        if(current_time == 3){
          current_time = 0;     //reset timer;
          channel_display = (channel_display + 1)%8;
        }else
          current_time ++ ;
      }else
        current_time = 0;      //always reset timer on man state
      
      if(present_state == Alert && counter == 0)
        CLEARBIT(PORTD, 7);
      else{
        SETBIT(PORTD, 7);
        if(counter > 0)
          counter --;
      }
      //summing ADC reading for a particular channel
      adc_sum = 0;
      for(i = 0; i<8; i++)
        adc_sum += (unsigned long int)channel_voltage[channel_display][i];
      
      //average the sum and look up the temperature in the table  
      temperature = tb_lookup(((unsigned int)(adc_sum >> 3)));
      
      if(flag & (1 << 0)){
        temperature = (temperature* 9)/5 + 320;
        unit_temp = 'F';
      }else
        unit_temp = 'C';
      if(temperature < 0)
         temp_tenth = (0 - temperature)%10;
      else
         temp_tenth = temperature%10;
      temperature = temperature/10;
      clear_dsp();
      printf("%s: %d.%d ", a[channel_display], temperature, temp_tenth);
      putchar(unit_temp);
      update_lcd_dog();
      __EEGET(temp_limit, channel_display);
       if(flag & (1 << 0))
          temp_int = ((signed int)(temp_limit)*9)/5 + 32;
       else
         temp_int = (signed int)temp_limit;
       
       if(((temp_int != 0) && 
          (temp_int <= temperature)) || present_state == Alert)
      {
        index = 16;
        printf("LIMIT EXCEEDED!!");
        update_lcd_dog();
        SETBIT(PORTD, 0);
        CLEARBIT(PORTD, 0);
      }
      __delay_cycles(8000000);    //delay_for_1 second
    }
  }
}
Example #4
0
void WRLDRecord::IsNoLODWater(bool value)
    {
    SETBIT(DATA.value, fIsNoLODWater, value);
    }
Example #5
0
void WRLDRecord::IsUseClimateData(bool value)
    {
    SETBIT(PNAM.value, fIsUseClimateData, value);
    }
Example #6
0
void bfilter_add(const bloom_filter* bFilter, const unsigned* input)
{
	SETBIT(bFilter->filter, *input % bFilter->num_buckets);
}
Example #7
0
int dht_get(void) {
    int res;

    sample_count++;
    if(sample_count < DHT_INTERVAL) {
        return FALSE;
    }
    sample_count = 0;

    DPUTS(label); DPUTS("read "); DPUTS("start"); DCR;

    SETBIT(DHT_DDR, DHT_PIN);       /* set to output */
    CLEARBIT(DHT_OUTP, DHT_PIN);    /* output low */

    /* This might need to be adjusted for dht11 and 22
     * Longer delay (50ms) seems to work fine on 11, but not 22. */

    _delay_ms(20);                  /* min 18ms */
    SETBIT(DHT_OUTP, DHT_PIN);      /* and high */

    CLEARBIT(DHT_DDR, DHT_PIN);     /* set for input */

    /* set up prescalar for timer0 */
    DHT_PRESCALE_REG |= \
        (DHT_CS00 << CS00) | \
        (DHT_CS01 << CS01) | \
        (DHT_CS02 << CS02);

    if((res = dht_wait_for_value(0, DHT_FORTY)) > DHT_FORTY) {
        DPUTS(label); DPUTS("fail:"); DPUTS("0"); DCR;
        return FALSE;
    }

    if((res = dht_wait_for_value(1, DHT_HUNDRED)) > DHT_HUNDRED) {
        DPUTS(label); DPUTS("fail:"); DPUTS("1"); DCR;
        return FALSE;
    }

    if(dht_wait_for_value(0, DHT_HUNDRED) > DHT_HUNDRED) {
        DPUTS(label); DPUTS("fail:"); DPUTS("2"); DCR;
        return FALSE;
    }

    for(int i=0; i<5; i++) {
        for(int j=0; j<8; j++) {
            if(dht_wait_for_value(1, DHT_EIGHTY) > DHT_EIGHTY) {
                DPUTS(label); DPUTS("fail:"); DPUTS("3"); DCR;
                return FALSE;
            }

            if(dht_wait_for_value(0, DHT_EIGHTY) > DHT_FORTY) {
                SETBIT(dht_data[i], 7-j);
            } else {
                CLEARBIT(dht_data[i], 7-j);
            }
        }
    }

    /* should check the checksum */
    uint8_t data = dht_data[0] + dht_data[1] + \
        dht_data[2] + dht_data[3];

    if (data != dht_data[4]) {
        DPUTS(label); DPUTS("fail:"); DPUTS("4"); DCR;
        return FALSE;
    }

    DPUTS(label);
    for(int i=0; i<5; i++) {
        DPUTBYTEX(dht_data[i]); DPUTS(" ");
    }
    DCR;

    /* /\* DHT11 format *\/ */
    /* if(DHT_SENSOR_MODEL == SENSOR_MODEL_DHT11) { */
    /*     DPRINTF("Humidity:    %0d.%02d percent\n\r", dht_data[0], dht_data[1]); */
    /*     DPRINTF("Temperature: %0d.%02d degrees C\n\r", dht_data[2], dht_data[3]); */
    /* } */

    /* if(DHT_SENSOR_MODEL == SENSOR_MODEL_DHT22) { */
    /*     uint16_t h, t; */
    /*     h = dht_data[0] << 8 | dht_data[1]; */
    /*     t = dht_data[2] << 8 | dht_data[3]; */

    /*     /\* DHT22 (tenths) *\/ */
    /*     DPRINTF("Hum: %0.2f\n\r", (float)h/10.0); */
    /*     DPRINTF("Temp: %0.2f\n\r", ((float)t/10.0) * (9.0/5.0) + 32); */
    /* } */

    DPUTS(label); DPUTS("read "); DPUTS("end"); DCR;
    return TRUE;
}
Example #8
0
void IPCTRecord::IsObjectParallax(bool value)
{
    if (!DODT.IsLoaded()) return;
    SETBIT(DODT->flags, fIsParallax, value);
}
Example #9
0
void IPCTRecord::IsObjectAlphaTesting(bool value)
{
    if (!DODT.IsLoaded()) return;
    SETBIT(DODT->flags, fIsAlphaTesting, value);
}
Example #10
0
void PGRERecord::IsPopIn(bool value)
    {
    if(!XESP.IsLoaded()) return;
    SETBIT(XESP->flags, fIsPopIn, value);
    }
Example #11
0
void IPCTRecord::IsNoDecalData(bool value)
{
    if (!DATA.IsLoaded()) return;
    SETBIT(DATA->flags, fIsNoDecalData, value);
}
Example #12
0
void PGRERecord::IsOppositeParent(bool value)
    {
    if(!XESP.IsLoaded()) return;
    SETBIT(XESP->flags, fIsOppositeParent, value);
    }
/*! 
 * \brief Tag messages in the board
 * \param[in] node address of CommQueue node
 * \return Return Code
 * 
 * This routine is to be executed during the firs communication stage
 * (::MB_COMM_OLD_PRE_TAGGING).
 * 
 * Pre:
 * - node->mb is valid
 * - board->locked == ::MB_TRUE
 * - board->syncCompleted == ::MB_FALSE
 * - node->stage == ::MB_COMM_OLD_PRE_TAGGING
 * - node->flag_fdrFallback = ::MB_FALSE
 * - node->flag_shareOutbuf = ::MB_FALSE
 * - node->incount == \c NULL
 * - node->outcount == \c NULL
 * - node->inbuf == \c NULL
 * - node->outbuf == \c NULL
 * - node->sendreq == \c NULL
 * - node->recvreq == \c NULL
 * - node->board == \c NULL
 * 
 * Steps:
 * -# Get pointer to board object and cache it in node->board
 * -# Allocate memory for node->outcount
 * -# If node->mb->filter == \c NULL or node->board->data->count_current = 0
 *  -# set node->outcount[*] = node->board->data->count_current
 *  -# set node->flag_shareOutbuf = ::MB_TRUE
 * -# If node->board->filter != \c NULL
 *  -# Use node->board->filter to build tag table in node->board->tt
 *  -# Allocate memory for node->outcount
 *  -# Initialise values in node->outcount[] based on contents of node->board->tt.
 *     Keep count of outcount total as we go along. If total > node->board->data->count_current, 
 *     fallback to full data replication
 *   - clear tag table
 *   - set node->outcount[*] = node->board->data->count_current
 *   - set node->flag_fdrFallback = ::MB_TRUE
 *   - set node->flag_shareOutbuf = ::MB_TRUE
 * -# set node->stage to ::MB_COMM_OLD_READY_FOR_PROP
 * 
 * Post:
 * - node->stage == ::MB_COMM_OLD_READY_FOR_PROP
 * - node->outcount != \c NULL
 * - node->board != \c NULL
 * - if (node->board->filter != NULL)
 *  - if (node->flag_fdrFallback == ::MB_TRUE) node->board->tt == \c NULL
 *  - if (node->flag_fdrFallback == ::MB_FALSE) node->board->tt != \c NULL
 * - if node->board->filter == \c NULL or node->fdr_fallback == \c ::MB_TRUE
 *  - node->flag_shareOutbuf == ::MB_TRUE
 */
int MBI_CommRoutine_OLD_TagMessages(struct MBIt_commqueue *node) {
    
    char window;
    int rc, i, j, c, w, p;
    int total_tagged, mcount;
    void *msg;
    MBIt_TagTable *tt;
    pl_address_node *pl_itr;
    
    /* check that initial values are set properly */
    assert(node->stage == MB_COMM_OLD_PRE_TAGGING);
    assert(node->flag_fdrFallback == MB_FALSE);
    assert(node->flag_shareOutbuf == MB_FALSE);
    assert(node->incount == NULL);
    assert(node->outcount == NULL);
    assert(node->inbuf == NULL);
    assert(node->outbuf == NULL);
    assert(node->recvreq == NULL);
    assert(node->sendreq == NULL);
    assert(node->board == NULL);

    /* get reference to board object and cache ptr in node */
    node->board = (MBIt_Board *)MBI_getMBoardRef(node->mb);
    assert(node->board != NULL);
    if (node->board == NULL) return MB_ERR_INVALID;
    
    P_INFO("COMM: Preparing (Board %d) for sync process", node->mb);
    
    /* check board state */
    assert(node->board->locked == MB_TRUE);
    assert(node->board->syncCompleted == MB_FALSE);
    
    /* get message count */
    /* ignore messages that have already been synced */
    mcount = (int)node->board->data->count_current - 
             (int)node->board->synced_cursor;
  
    /* allocate memory for outcount */
    node->outcount = (int *)calloc((size_t)MBI_CommSize, sizeof(int)); 
    assert(node->outcount != NULL);
    if (node->outcount == NULL) return MB_ERR_MEMALLOC;
    
    /* determined number of messages to send to remote procs */
    if (mcount == 0 || MBI_CommSize == 1) /* nothing to send */
    {
        /* outcount already initialised to 0 (calloc) */
        /*for (i = 0; i < MBI_CommSize; i++) node->outcount[i] = 0;*/
    }
    else if (node->board->filter == (MBIt_filterfunc)NULL) /* no filter */
    {   
        /* send all messages to all procs (except self) */
        for (i = 0; i < MBI_CommSize; i++)
        {
            node->outcount[i] = (i == MBI_CommRank) ? 0 : mcount;
        }
        
        /* outgoing buffer can be shared */
        node->flag_shareOutbuf = MB_TRUE;
        
    }
    else /* filter assigned */
    {        
        P_INFO("COMM: (Board %d) is filtered. Tagging messages", (int)node->mb);
        /* create tag_table and assign to board */
        rc = tt_create(&tt, mcount, MBI_CommSize);
        assert(rc == TT_SUCCESS);
        if (rc != TT_SUCCESS)
        {
            if (rc == TT_ERR_MEMALLOC) return MB_ERR_MEMALLOC;
            else return MB_ERR_INTERNAL;
        }
        node->board->tt = tt; /* assign to board */
        
        /* initialise counters */
        i = j = 0;
        total_tagged = 0;
        
        /* loop thru messages and fill up tag table */
        for (pl_itr = PL_ITERATOR(node->board->data); pl_itr; pl_itr = pl_itr->next)
        {
            assert(i < (int)node->board->data->count_current);
            
            /* skip messages that have already been synced */
            if (i < (int)node->board->synced_cursor) 
            {
                i++;
                continue;
            }
            
            /* get reference to message from iterator */
            msg = PL_NODEDATA(pl_itr);
            assert(msg != NULL);
            if (msg == NULL) return MB_ERR_INTERNAL;
            
            /* c : offset within byte buffer (window)
             * w : window offset within table row
             */
            c = w = 0;
            SETZEROS(window);
            
            /* run filter on message per MPI task */
            for (p = 0; p < MBI_CommSize; p++)
            {
                if (p != MBI_CommRank)
                {   
                    /* if message accepted by filter */
                    if (1 == (*node->board->filter)(msg, p))
                    {
                        /* set bit within our byte buffer */
                        SETBIT(window, c);
                        
                        /* update outcount */
                        node->outcount[p]++;
                        total_tagged++;

                    }
                }
                
                
                /* move index within window */
                c++;
                
                /* when window full, write to table and shift window */
                if (c == 8)
                {
                    /* write byte buffer to table */
                    rc = tt_setbyte(node->board->tt, j, w, window);
                    assert(rc == TT_SUCCESS);
                    
                    /* move window */
                    w += 1;
                    
                    /* reset byte buffer */
                    SETZEROS(window);
                    c = 0;
                }
            }
            
            /* write remaining byte buffer */
            if (w < (int)node->board->tt->row_size)
            {
                rc = tt_setbyte(node->board->tt, j, w, window);
                assert(rc == TT_SUCCESS);
            }
            
            /* increment counter */
            i++;
            j++;
        }
        assert(node->outcount[MBI_CommRank] == 0);
        
        /* Should we fall back to full data replication? */
        if (total_tagged > mcount)
        {
            P_INFO("COMM: (Board %d) Tagged messages <%d> exceeds message count <%d>. "
                    "Delegating filtering to recipient", 
                    (int)node->mb, total_tagged, mcount);
            /* we don't need the tagtable any more */
            node->board->tt = NULL;
            rc = tt_delete(&tt);
            assert(rc == TT_SUCCESS);
            
            /* send all messages to all remote procs */
            node->flag_fdrFallback = MB_TRUE; /* fallback to full data replication */
            node->flag_shareOutbuf = MB_TRUE; /* use shared buffer */
            for (i = 0; i < MBI_CommSize; i++)
            {
                if (node->outcount[i] != 0) node->outcount[i] = mcount;
            }
        }
    }
    
    /* move on to next stage */
    P_INFO("COMM: (Board %d) moving to MB_COMM_OLD_READY_FOR_PROP stage", node->mb);
    node->stage = MB_COMM_OLD_READY_FOR_PROP;
    return MB_SUCCESS;
    
}
Example #14
0
void IDLMRecord::IsRunInSequence(bool value)
    {
    SETBIT(IDLF.value, fIsRunInSequence, value);
    }
Example #15
0
uint32_t testAudioLineIn(void)
{
   uint32_t rtn = ERR_NO_ERROR;
   int16_t msec, sec, sample;
   int32_t dat;

   // enable the audio clocks, verifying each bit is properly set.
   SETBIT(MCASP->XGBLCTL, XHCLKRST);
   while (!CHKBIT(MCASP->XGBLCTL, XHCLKRST)) {}
   SETBIT(MCASP->RGBLCTL, RHCLKRST);
   while (!CHKBIT(MCASP->RGBLCTL, RHCLKRST)) {}

   SETBIT(MCASP->XGBLCTL, XCLKRST);
   while (!CHKBIT(MCASP->XGBLCTL, XCLKRST)) {}
   SETBIT(MCASP->RGBLCTL, RCLKRST);
   while (!CHKBIT(MCASP->RGBLCTL, RCLKRST)) {}

   SETBIT(MCASP->XGBLCTL, XSRCLR);
   while (!CHKBIT(MCASP->XGBLCTL, XSRCLR)) {}
   SETBIT(MCASP->RGBLCTL, RSRCLR);
   while (!CHKBIT(MCASP->RGBLCTL, RSRCLR)) {}

   /* Write a 0, so that no underrun occurs after releasing the state machine */
   MCASP->XBUF11 = 0;

   SETBIT(MCASP->XGBLCTL, XSMRST);
   while (!CHKBIT(MCASP->XGBLCTL, XSMRST)) {}
   SETBIT(MCASP->RGBLCTL, RSMRST);
   while (!CHKBIT(MCASP->RGBLCTL, RSMRST)) {}

   SETBIT(MCASP->XGBLCTL, XFRST);
   while (!CHKBIT(MCASP->XGBLCTL, XFRST)) {}
   SETBIT(MCASP->RGBLCTL, RFRST);
   while (!CHKBIT(MCASP->RGBLCTL, RFRST)) {}

   // wait for transmit ready and send a dummy byte.
   while(!CHKBIT(MCASP->SRCTL11, XRDY)) {}
   MCASP->XBUF11 = 0;

   // loop audio
   for (sec = 0; sec < 15; sec++)
   {
      for (msec = 0; msec < 1000; msec++)
      {
         for (sample = 0; sample < 48; sample++)
         {
            // wait for recv ready and send a sample to the left channel.
            while (!CHKBIT(MCASP->SRCTL11, XRDY)) {}
   			MCASP->XBUF11 = dat;
            dat = MCASP->XBUF12;

            // wait for recv ready and send a sample to the right channel.
            while (!CHKBIT(MCASP->SRCTL11, XRDY)) {}
   			MCASP->XBUF11 = dat;
            dat = MCASP->XBUF12;
            //printf("you received %d\n", dat);
         }
      }
   }
   return (rtn);
}
Example #16
0
void ALCHRecord::IsFood(bool value)
    {
    SETBIT(ENIT.value.flags, fIsFood, value);
    }
Example #17
0
/*
 *	_hash_getovflpage()
 *
 *	Find an available overflow page and return it.	The returned buffer
 *	is pinned and write-locked, and has had _hash_pageinit() applied,
 *	but it is caller's responsibility to fill the special space.
 *
 * The caller must hold a pin, but no lock, on the metapage buffer.
 * That buffer is left in the same state at exit.
 */
static Buffer
_hash_getovflpage(Relation rel, Buffer metabuf)
{
	HashMetaPage metap;
	Buffer		mapbuf = 0;
	Buffer		newbuf;
	BlockNumber blkno;
	uint32		orig_firstfree;
	uint32		splitnum;
	uint32	   *freep = NULL;
	uint32		max_ovflpg;
	uint32		bit;
	uint32		first_page;
	uint32		last_bit;
	uint32		last_page;
	uint32		i,
				j;

	/* Get exclusive lock on the meta page */
	_hash_chgbufaccess(rel, metabuf, HASH_NOLOCK, HASH_WRITE);

	_hash_checkpage(rel, metabuf, LH_META_PAGE);
	metap = HashPageGetMeta(BufferGetPage(metabuf));

	/* start search at hashm_firstfree */
	orig_firstfree = metap->hashm_firstfree;
	first_page = orig_firstfree >> BMPG_SHIFT(metap);
	bit = orig_firstfree & BMPG_MASK(metap);
	i = first_page;
	j = bit / BITS_PER_MAP;
	bit &= ~(BITS_PER_MAP - 1);

    /*CS3223*/

	/* outer loop iterates once per bitmap page */
	for (;;)
	{
		BlockNumber mapblkno;
		Page		mappage;
		uint32		last_inpage;

		/* want to end search with the last existing overflow page */
		splitnum = metap->hashm_ovflpoint;
		max_ovflpg = metap->hashm_spares[splitnum] - 1;
		last_page = max_ovflpg >> BMPG_SHIFT(metap);
		last_bit = max_ovflpg & BMPG_MASK(metap);

		if (i > last_page)
			break;

		Assert(i < metap->hashm_nmaps);
		mapblkno = metap->hashm_mapp[i];

		if (i == last_page)
			last_inpage = last_bit;
		else
			last_inpage = BMPGSZ_BIT(metap) - 1;

		/* Release exclusive lock on metapage while reading bitmap page */
		_hash_chgbufaccess(rel, metabuf, HASH_READ, HASH_NOLOCK);

		mapbuf = _hash_getbuf(rel, mapblkno, HASH_WRITE, LH_BITMAP_PAGE);
		mappage = BufferGetPage(mapbuf);
		freep = HashPageGetBitmap(mappage);

		for (; bit <= last_inpage; j++, bit += BITS_PER_MAP)
		{
			if (freep[j] != ALL_SET)
				goto found;
		}

		/* No free space here, try to advance to next map page */
		_hash_relbuf(rel, mapbuf);
		i++;
		j = 0;					/* scan from start of next map page */
		bit = 0;

		/* Reacquire exclusive lock on the meta page */
		_hash_chgbufaccess(rel, metabuf, HASH_NOLOCK, HASH_WRITE);
	}

	/*
	 * No free pages --- have to extend the relation to add an overflow page.
	 * First, check to see if we have to add a new bitmap page too.
	 */
	if (last_bit == (uint32) (BMPGSZ_BIT(metap) - 1))
	{
		/*
		 * We create the new bitmap page with all pages marked "in use".
		 * Actually two pages in the new bitmap's range will exist
		 * immediately: the bitmap page itself, and the following page which
		 * is the one we return to the caller.	Both of these are correctly
		 * marked "in use".  Subsequent pages do not exist yet, but it is
		 * convenient to pre-mark them as "in use" too.
		 */
		bit = metap->hashm_spares[splitnum];
		_hash_initbitmap(rel, metap, bitno_to_blkno(metap, bit), MAIN_FORKNUM);
		metap->hashm_spares[splitnum]++;
	}
	else
	{
		/*
		 * Nothing to do here; since the page will be past the last used page,
		 * we know its bitmap bit was preinitialized to "in use".
		 */
	}

	/* Calculate address of the new overflow page */
	bit = metap->hashm_spares[splitnum];
	blkno = bitno_to_blkno(metap, bit);

	/*
	 * Fetch the page with _hash_getnewbuf to ensure smgr's idea of the
	 * relation length stays in sync with oursit.  XXX It's annoying to do this
	 * with metapage write lock held; would be better to use a lock that
	 * doesn't block incoming searches.
	 */
	newbuf = _hash_getnewbuf(rel, blkno, MAIN_FORKNUM);

	metap->hashm_spares[splitnum]++;

	/*
	 * Adjust hashm_firstfree to avoid redundant searches.	But don't risk
	 * changing it if someone moved it while we were searching bitmap pages.
	 */
	if (metap->hashm_firstfree == orig_firstfree)
		metap->hashm_firstfree = bit + 1;

	/* Write updated metapage and release lock, but not pin */
	_hash_chgbufaccess(rel, metabuf, HASH_WRITE, HASH_NOLOCK);

	return newbuf;

found:
	/* convert bit to bit number within page */
	bit += _hash_firstfreebit(freep[j]);

	/* mark page "in use" in the bitmap */
	SETBIT(freep, bit);
	_hash_wrtbuf(rel, mapbuf);

	/* Reacquire exclusive lock on the meta page */
	_hash_chgbufaccess(rel, metabuf, HASH_NOLOCK, HASH_WRITE);

	/* convert bit to absolute bit number */
	bit += (i << BMPG_SHIFT(metap));

	/* Calculate address of the recycled overflow page */
	blkno = bitno_to_blkno(metap, bit);

	/*
	 * Adjust hashm_firstfree to avoid redundant searches.	But don't risk
	 * changing it if someone moved it while we were searching bitmap pages.
	 */
	if (metap->hashm_firstfree == orig_firstfree)
	{
		metap->hashm_firstfree = bit + 1;

		/* Write updated metapage and release lock, but not pin */
		_hash_chgbufaccess(rel, metabuf, HASH_WRITE, HASH_NOLOCK);
	}
	else
	{
		/* We didn't change the metapage, so no need to write */
		_hash_chgbufaccess(rel, metabuf, HASH_READ, HASH_NOLOCK);
	}

	/* Fetch, init, and return the recycled page */
	return _hash_getinitbuf(rel, blkno);
}
Example #18
0
void ALCHRecord::IsNoAutoCalc(bool value)
    {
    SETBIT(ENIT.value.flags, fIsNoAutoCalc, value);
    }
Example #19
0
/*
** This routine runs an extensive test of the Bitvec code.
**
** The input is an array of integers that acts as a program
** to test the Bitvec.  The integers are opcodes followed
** by 0, 1, or 3 operands, depending on the opcode.  Another
** opcode follows immediately after the last operand.
**
** There are 6 opcodes numbered from 0 through 5.  0 is the
** "halt" opcode and causes the test to end.
**
**    0          Halt and return the number of errors
**    1 N S X    Set N bits beginning with S and incrementing by X
**    2 N S X    Clear N bits beginning with S and incrementing by X
**    3 N        Set N randomly chosen bits
**    4 N        Clear N randomly chosen bits
**    5 N S X    Set N bits from S increment X in array only, not in bitvec
**
** The opcodes 1 through 4 perform set and clear operations are performed
** on both a Bitvec object and on a linear array of bits obtained from malloc.
** Opcode 5 works on the linear array only, not on the Bitvec.
** Opcode 5 is used to deliberately induce a fault in order to
** confirm that error detection works.
**
** At the conclusion of the test the linear array is compared
** against the Bitvec object.  If there are any differences,
** an error is returned.  If they are the same, zero is returned.
**
** If a memory allocation error occurs, return -1.
*/
int sqlite3BitvecBuiltinTest(int sz, int *aOp){
  Bitvec *pBitvec = 0;
  unsigned char *pV = 0;
  int rc = -1;
  int i, nx, pc, op;
  void *pTmpSpace;

  /* Allocate the Bitvec to be tested and a linear array of
  ** bits to act as the reference */
  pBitvec = sqlite3BitvecCreate( sz );
  pV = sqlite3MallocZero( (sz+7)/8 + 1 );
  pTmpSpace = sqlite3_malloc64(BITVEC_SZ);
  if( pBitvec==0 || pV==0 || pTmpSpace==0  ) goto bitvec_end;

  /* NULL pBitvec tests */
  sqlite3BitvecSet(0, 1);
  sqlite3BitvecClear(0, 1, pTmpSpace);

  /* Run the program */
  pc = 0;
  while( (op = aOp[pc])!=0 ){
    switch( op ){
      case 1:
      case 2:
      case 5: {
        nx = 4;
        i = aOp[pc+2] - 1;
        aOp[pc+2] += aOp[pc+3];
        break;
      }
      case 3:
      case 4: 
      default: {
        nx = 2;
        sqlite3_randomness(sizeof(i), &i);
        break;
      }
    }
    if( (--aOp[pc+1]) > 0 ) nx = 0;
    pc += nx;
    i = (i & 0x7fffffff)%sz;
    if( (op & 1)!=0 ){
      SETBIT(pV, (i+1));
      if( op!=5 ){
        if( sqlite3BitvecSet(pBitvec, i+1) ) goto bitvec_end;
      }
    }else{
      CLEARBIT(pV, (i+1));
      sqlite3BitvecClear(pBitvec, i+1, pTmpSpace);
    }
  }

  /* Test to make sure the linear array exactly matches the
  ** Bitvec object.  Start with the assumption that they do
  ** match (rc==0).  Change rc to non-zero if a discrepancy
  ** is found.
  */
  rc = sqlite3BitvecTest(0,0) + sqlite3BitvecTest(pBitvec, sz+1)
          + sqlite3BitvecTest(pBitvec, 0)
          + (sqlite3BitvecSize(pBitvec) - sz);
  for(i=1; i<=sz; i++){
    if(  (TESTBIT(pV,i))!=sqlite3BitvecTest(pBitvec,i) ){
      rc = i;
      break;
    }
  }

  /* Free allocated structure */
bitvec_end:
  sqlite3_free(pTmpSpace);
  sqlite3_free(pV);
  sqlite3BitvecDestroy(pBitvec);
  return rc;
}
Example #20
0
	int
main (

int		argc,
char **		argv
)
{
int			i;
int			nedges;
int			nmasks;
int			fpsave;
bitmap_t *		edge_mask;
bitmap_t *		all_fsets_mask;
bitmap_t *		no_fsets_mask;
int			count;
char			tbuf [20];
char			title [128];
struct cinfo		cinfo;

	fpsave = set_floating_point_double_precision ();

	setbuf (stdout, NULL);

	decode_params (argc, argv);

	init_tables ();

	read_phase_1_data (&cinfo);

	edge_mask	= cinfo.initial_edge_mask;

	convert_cpu_time (cinfo.p1time, tbuf);
	printf (" %% Phase 1: %s seconds\n", tbuf);

	/* Prepare for plotting all terminals. */
	define_Plot_Terminals (cinfo.pts, &cinfo.scale);

	nedges = cinfo.num_edges;
	nmasks = cinfo.num_edge_masks;

	all_fsets_mask = NEWA (nmasks, bitmap_t);
	no_fsets_mask = NEWA (nmasks, bitmap_t);
	for (i = 0; i < nmasks; i++) {
		all_fsets_mask [i] = 0;
		no_fsets_mask [i] = 0;
	}
	for (i = 0; i < nedges; i++) {
		SETBIT (all_fsets_mask, i);
	}

	if (Print_Points) {
		if ((cinfo.description NE NULL) AND
		    (cinfo.description [0] NE '\0')) {
			strcpy (title, cinfo.description);
		}
		else {
			sprintf (title, "%lu points", (int32u) cinfo.num_verts);
		}
		overlay_plot_subset (title, no_fsets_mask, &cinfo, BIG_PLOT);
	}
	if (Print_Full_Sets) {
		plot_full_sets (all_fsets_mask, &cinfo, SMALL_PLOT);
	}
	if (Print_Grouped_Full_Sets) {
		plot_full_sets_grouped (all_fsets_mask, &cinfo, SMALL_PLOT);
	}

	if (Print_Overlaid_Full_Sets) {
		sprintf (title,
			 "All FSTs:  %lu points,  %s seconds",
			 (int32u) cinfo.num_verts, tbuf);
		overlay_plot_subset (title, edge_mask, &cinfo, BIG_PLOT);
	}

	restore_floating_point_precision (fpsave);

	exit (0);
}
Example #21
0
void WRLDRecord::IsNoFastTravel(bool value)
    {
    SETBIT(DATA.value, fIsNoFastTravel, value);
    }
Example #22
0
	struct constraint *
add_cutset_to_list (

bitmap_t *		cutset,		/* IN - new cutset to add */
struct constraint *	cutlist,	/* IN - list to add to */
double *		x,		/* IN - current LP solution */
bitmap_t *		vert_mask,	/* IN - set of valid terminals */
bitmap_t *		edge_mask,	/* IN - set of valid hyperedges */
struct cinfo *		cip		/* IN - compatibility info */
)
{
int			i;
int			j;
int			nedges;
int			nmasks;
int			num_in_cut;
int			count;
int *			vp1;
int *			vp2;
struct constraint *	p;
struct constraint **	hookp;
bitmap_t *		cut_edges;
double			z;

	nedges	= cip -> num_edges;
	nmasks	= cip -> num_edge_masks;

	cut_edges = NEWA (nmasks, bitmap_t);
	memset (cut_edges, 0, nmasks * sizeof (*cut_edges));

	count = 0;
	z = 0.0;
	for (i = 0; i < cip -> num_edges; i++) {
		if (NOT BITON (edge_mask, i)) continue;
		num_in_cut = 0;
		vp1 = cip -> edge [i];
		vp2 = cip -> edge [i + 1];
		while (vp1 < vp2) {
			j = *vp1++;
			if (BITON (cutset, j)) {
				++num_in_cut;
			}
		}
		if (num_in_cut <= 0) {
			/* this hyperedge resides entirely	*/
			/* outside of the cut...  doesn't span!	*/
			continue;
		}
		if (num_in_cut >= cip -> edge_size [i]) {
			/* this hyperedge resides entirely	*/
			/* within the cut...  doesn't span!	*/
			continue;
		}
		SETBIT (cut_edges, i);
		++count;
		z += x [i];
	}

	/* Check for an all-zero cutset.  These occasionally	*/
	/* happen because of numeric issues...			*/

	if (count <= 0) {
		/* Empty cutset!  OOOPS! */
#if 1
		tracef (" %% WARNING!  empty cutset!\n");
#endif
		free ((char *) cut_edges);
		return (cutlist);
	}

	if (z >= 1.0 - FUZZ) {
#if 1
		tracef (" %% WARNING!  bogus cutset!\n");
#endif
		free ((char *) cut_edges);
		return (cutlist);
	}

	/* If this new cutset is a superset of an existing one,	*/
	/* then there is nothing to add, and nothing to delete.	*/
	for (p = cutlist; p NE NULL; p = p -> next) {
		if (is_subset (p -> mask, cut_edges, nmasks)) {
			free (cut_edges);
			return (cutlist);
		}
	}

	/* Delete all current cutsets which have this new one	*/
	/* as a subset.						*/
	hookp = &cutlist;
	while ((p = *hookp) NE NULL) {
		if (p -> type NE CT_CUTSET) {
			hookp = &(p -> next);
		}
		else if (is_subset (cut_edges, p -> mask, nmasks)) {
			*hookp = p -> next;
			free ((char *) (p -> mask));
			free ((char *) p);
		}
		else {
			hookp = &(p -> next);
		}
	}

	p = NEW (struct constraint);
	p -> next	= NULL;
	p -> iteration	= 0;
	p -> type	= CT_CUTSET;
	p -> mask	= cut_edges;
	*hookp = p;

	return (cutlist);
}
Example #23
0
void WRLDRecord::IsUseLandData(bool value)
    {
    SETBIT(PNAM.value, fIsUseLandData, value);
    }
Example #24
0
int splitQuotedStr (
                     char *str,
                     char *delims,
                     uint flgs,
                     int maxWrdCnt,
                     char *(**words)
                  ) {
  int wrdcnt = 0;
  uint flags = 0;

  char *Buffer = (char *)malloc(sizeof(char) * (strlen(str) + 1));
  char *bufPos = Buffer;
  char *ptr;
  char *p;

  //take the given flags... for now it's only FL_DLMFLD
  if (GETBIT(flgs, FL_DLMFLD))
      SETBIT(flags, FL_DLMFLD);

  if (!(*words))
     *words=(char **)malloc(sizeof(char*));

  for (ptr = str; *ptr && (GETBIT(flags, FL_MAXWRD) == 0); ptr++) {
    if ((*ptr == '\\') && (GETBIT(flags, FL_ESC)==0)) {
       SETBIT(flags, FL_ESC);
       #ifdef DEBUG
          fprintf(stderr, "Continue due to escape-char\n");
       #endif
       continue;
    }
    if (*ptr == '\"') {
        //Wenn 1. das vorhergehende Zeichen kein \ ist
        // und 2. wir nicht inmitten eines '-Wortes sind (singlequote)
       if ((GETBIT(flags, FL_ESC) == 0) &&
           (GETBIT(flags, FL_SQOT) == 0) ) {
           //...dann beginnt oder endet hier nun ein "-Wort (dblquote)
         SWPBIT(flags, FL_DQOT);
         SETBIT(flags, FL_QOTCHGD); //indikator für quote-grenze setzen
       }
    }
    if (*ptr == '\'') {
        //Wenn 1. das vorhergehende Zeichen kein \ ist
        // und 2. wir nicht inmitten eines "-Wortes sind (dblquote)
       if ((GETBIT(flags, FL_ESC) == 0) &&
           (GETBIT(flags, FL_DQOT) == 0) ) {
           //...dann beginnt oder endet hier nun ein '-Wort (singlequote)
         SWPBIT(flags, FL_SQOT);
         SETBIT(flags, FL_QOTCHGD); //indikator für wort-grenze setzen
       }
    }

    //so, nun sollte alles geklaert sein. wenn wir nicht inmitten eines
    //wortes sind, dann schauen wir mal, ob wir es mit einem
    //delimiter zu tun haben dem auch kein escape-Zeichen vorangeht:
    if (
            (GETBIT(flags, FL_SQOT) == 0)
         && (GETBIT(flags, FL_DQOT) == 0)
         && (GETBIT(flags, FL_ESC)  == 0)
       ) {
        for (p = delims; *p; p++)
           if (*ptr == *p) {
               SETBIT(flags, FL_DLM);
           }
    }

    //So, nun sind wir fast fertig: Wenn wir nicht auf einem delimiter stehen,
    //dann kopieren wir das aktuelle Zeichen in den puffer
    if (GETBIT(flags, FL_DLM) == 0)  {
      if (GETBIT(flags, FL_QOTCHGD) == 0) {
         *bufPos++ = *ptr;
         *bufPos = '\0';
      }
    } else {
        //Irgendwie müssen wir hier nun den Delimiter bearbeiten.
        if (GETBIT(flags, FL_DLMFLD) == 1) {
            //wenn delimiterfolding (FL_DLMFLD) aktiv ist, dann
            //dürfen wir keine leeren Wörter ausgeben:
            if (strlen(Buffer))
                SETBIT(flags, FL_WRDFIN);
        } else {
            //ansonsten ist uns das egal was in dem Wort steht.
            SETBIT(flags, FL_WRDFIN);
        }
        //ggf beginnen wir nun ein neues Wort und resetten den Buffer fuer
        //das naechste Wort:
        if (GETBIT(flags, FL_WRDFIN)) {
           *words = (char **)realloc(*(words), (wrdcnt + 1) * sizeof(char *));
           ((*words)[wrdcnt++]) = strdup(Buffer);
           bufPos = Buffer;
           *bufPos = '\0';
           //wenn maxWordCount definiert (>0) und erreicht ist, dann
           //setzen wir mal das Flag zum Iterationsabbruch
           if ((maxWrdCnt > 0) && (wrdcnt == maxWrdCnt)) {
              SETBIT(flags, FL_MAXWRD);
              #ifdef DEBUG
                 fprintf(stderr, "Break due to maxWrdCnt == %d\n", maxWrdCnt);
              #endif
           }
        }
    }

    #ifdef DEBUG
    fprintf(stderr, "%3d: %c: (0x%x = %d%d%d%d%d%d%d%d) %s\n",
                     wrdcnt, *ptr, (int)flags,
                     GETBIT(flags, FL_MAXWRD),
                     GETBIT(flags, FL_WRDFIN),
                     GETBIT(flags, FL_DLMFLD),
                     GETBIT(flags, FL_DLM),
                     GETBIT(flags, FL_QOTCHGD),
                     GETBIT(flags, FL_SQOT),
                     GETBIT(flags, FL_DQOT),
                     GETBIT(flags, FL_ESC),
                     Buffer
    );
    splitQuotedStr_DebugFlags(flags);
    #endif

    //Iterations-Abschluss:
    //nun alle noetigen Flags für den nächsten Durchlauf neu initialisieren
    CLRBIT(flags, FL_WRDFIN);
    CLRBIT(flags, FL_DLM);
    CLRBIT(flags, FL_ESC);
    CLRBIT(flags, FL_QOTCHGD); //indikator für wort-grenze setzen
  } //for ptr...

  //Wenn bereits innerhalb der Iteration die max. Anzahl von Wörtern erreicht
  //wurde, dann brauchen wir uns um ggf gelesenen Rest nicht mehr kuemmern:
  if (GETBIT(flags, FL_MAXWRD) == 0) {
    //...ansonsten schauen wir uns das doch gleich mal etwas genauer an...
    //es sei: das letzte Wort speichern, wenn was im Buffer ist, oder,
    //wenn Delimiterfolding inaktiv ist.
    if (
         strlen(Buffer) || ((GETBIT(flags, FL_DLMFLD) == 0) &&
                             GETBIT(flags, FL_WRDFIN == 1))
       ) {
       #ifdef DEBUG
          fprintf(stderr, "at the end: create last word from buffer.\n");
       #endif
       *(words) = (char **)realloc(*(words), (wrdcnt + 1) * sizeof(char*));
       ((*words)[wrdcnt++]) = strdup(Buffer);
    }
  }
  #ifdef DEBUG
   fprintf(stderr, "final flag-status: ");
   splitQuotedStr_DebugFlags(flags);
  #endif
  //so, zum Schluss noch etwas housekeeping...
  free(Buffer);
  if (GETBIT(flags, FL_DQOT) == 0 && GETBIT(flags, FL_SQOT) == 0) {
      return (wrdcnt);
  } else {
      int i = 0;
      for (i = 0; i < wrdcnt; i++)
        free((*words)[i]);
      return (-1);
  }
}
Example #25
0
void WRLDRecord::IsUseImageSpaceData(bool value)
    {
    SETBIT(PNAM.value, fIsUseImageSpaceData, value);
    }
Example #26
0
static cmph_uint8 bmz_traverse_critical_nodes(bmz_config_data_t *bmz, cmph_uint32 v, cmph_uint32 * biggest_g_value, cmph_uint32 * biggest_edge_value, cmph_uint8 * used_edges, cmph_uint8 * visited)
{
        cmph_uint32 next_g;
	cmph_uint32 u;   /* Auxiliary vertex */
	cmph_uint32 lav; /* lookahead vertex */
	cmph_uint8 collision;
	vqueue_t * q = vqueue_new((cmph_uint32)(graph_ncritical_nodes(bmz->graph)) + 1);
	graph_iterator_t it, it1;

	DEBUGP("Labelling critical vertices\n");
	bmz->g[v] = (cmph_uint32)ceil ((double)(*biggest_edge_value)/2) - 1;
	SETBIT(visited, v);
	next_g    = (cmph_uint32)floor((double)(*biggest_edge_value/2)); /* next_g is incremented in the do..while statement*/
	vqueue_insert(q, v);
	while(!vqueue_is_empty(q))
	{
		v = vqueue_remove(q);
		it = graph_neighbors_it(bmz->graph, v);		
		while ((u = graph_next_neighbor(bmz->graph, &it)) != GRAPH_NO_NEIGHBOR)
		{		        
               	        if (graph_node_is_critical(bmz->graph, u) && (!GETBIT(visited,u)))
			{
			        collision = 1;
			        while(collision) // lookahead to resolve collisions
				{
 				        next_g = *biggest_g_value + 1; 
					it1 = graph_neighbors_it(bmz->graph, u);
					collision = 0;
					while((lav = graph_next_neighbor(bmz->graph, &it1)) != GRAPH_NO_NEIGHBOR)
					{
  					        if (graph_node_is_critical(bmz->graph, lav) && GETBIT(visited,lav))
						{
   						        if(next_g + bmz->g[lav] >= bmz->m)
							{
							        vqueue_destroy(q);
								return 1; // restart mapping step.
							}
							if (GETBIT(used_edges, (next_g + bmz->g[lav]))) 
							{
							        collision = 1;
								break;
							}
						}
					}
 					if (next_g > *biggest_g_value) *biggest_g_value = next_g;
				}		
				// Marking used edges...
				it1 = graph_neighbors_it(bmz->graph, u);
				while((lav = graph_next_neighbor(bmz->graph, &it1)) != GRAPH_NO_NEIGHBOR)
				{
                 		        if (graph_node_is_critical(bmz->graph, lav) && GETBIT(visited, lav))
					{
                   			        SETBIT(used_edges,(next_g + bmz->g[lav]));
						if(next_g + bmz->g[lav] > *biggest_edge_value) *biggest_edge_value = next_g + bmz->g[lav];
					}
				}
				bmz->g[u] = next_g; // Labelling vertex u.
				SETBIT(visited,u);
			        vqueue_insert(q, u);
			}			
	        }
		 
	}
	vqueue_destroy(q);
	return 0;
}
Example #27
0
int ParseEPD (char *p)
/**************************************************************************
 *   
 *  Parses an EPD input line.  A few global variables are updated e.g.
 *  current board, side to move, en passant, castling status, etc.
 *
 **************************************************************************/
{
   int r, c, sq;
   char *str_p;

   r = 56;
   c = 0;
   memset (&board, 0, sizeof (board));

   while (p && *p != ' ')
   {
     sq = r + c;
     switch (*p)
     {
        case 'P' :  SETBIT (board.b[white][pawn], sq);
		    SETBIT (board.blockerr90, r90[sq]);
		    SETBIT (board.blockerr45, r45[sq]);
		    SETBIT (board.blockerr315, r315[sq]);
		    board.material[white] += ValueP;
		    break;	
        case 'N' :  SETBIT (board.b[white][knight], sq);
		    SETBIT (board.blockerr90, r90[sq]);
		    SETBIT (board.blockerr45, r45[sq]);
		    SETBIT (board.blockerr315, r315[sq]);
		    board.material[white] += ValueN;
		    break;	
        case 'B' :  SETBIT (board.b[white][bishop], sq);
		    SETBIT (board.blockerr90, r90[sq]);
		    SETBIT (board.blockerr45, r45[sq]);
		    SETBIT (board.blockerr315, r315[sq]);
		    board.material[white] += ValueB;
		    break;	
        case 'R' :  SETBIT (board.b[white][rook], sq);
		    SETBIT (board.blockerr90, r90[sq]);
		    SETBIT (board.blockerr45, r45[sq]);
		    SETBIT (board.blockerr315, r315[sq]);
		    board.material[white] += ValueR;
		    break;	
        case 'Q' :  SETBIT (board.b[white][queen], sq);
		    SETBIT (board.blockerr90, r90[sq]);
		    SETBIT (board.blockerr45, r45[sq]);
		    SETBIT (board.blockerr315, r315[sq]);
		    board.material[white] += ValueQ;
		    break;	
        case 'K' :  SETBIT (board.b[white][king], sq);
		    SETBIT (board.blockerr90, r90[sq]);
		    SETBIT (board.blockerr45, r45[sq]);
		    SETBIT (board.blockerr315, r315[sq]);
		    break;	
        case 'p' :  SETBIT (board.b[black][pawn], sq);
		    SETBIT (board.blockerr90, r90[sq]);
		    SETBIT (board.blockerr45, r45[sq]);
		    SETBIT (board.blockerr315, r315[sq]);
		    board.material[black] += ValueP;
		    break;	
        case 'n' :  SETBIT (board.b[black][knight], sq);
		    SETBIT (board.blockerr90, r90[sq]);
		    SETBIT (board.blockerr45, r45[sq]);
		    SETBIT (board.blockerr315, r315[sq]);
		    board.material[black] += ValueN;
		    break;	
        case 'b' :  SETBIT (board.b[black][bishop], sq);
		    SETBIT (board.blockerr90, r90[sq]);
		    SETBIT (board.blockerr45, r45[sq]);
		    SETBIT (board.blockerr315, r315[sq]);
		    board.material[black] += ValueB;
		    break;	
        case 'r' :  SETBIT (board.b[black][rook], sq);
		    SETBIT (board.blockerr90, r90[sq]);
		    SETBIT (board.blockerr45, r45[sq]);
		    SETBIT (board.blockerr315, r315[sq]);
		    board.material[black] += ValueR;
		    break;	
        case 'q' :  SETBIT (board.b[black][queen], sq);
		    SETBIT (board.blockerr90, r90[sq]);
		    SETBIT (board.blockerr45, r45[sq]);
		    SETBIT (board.blockerr315, r315[sq]);
                    board.material[black] += ValueQ;
		    break;	
        case 'k' :  SETBIT (board.b[black][king], sq);
		    SETBIT (board.blockerr90, r90[sq]);
		    SETBIT (board.blockerr45, r45[sq]);
		    SETBIT (board.blockerr315, r315[sq]);
		    break;	
        case '/' :  r -= 8;
	 	    c = -1;
		    break;
        default  :  break;
     }
     if (isdigit (*p))
        c += (*p - '0');
     else
        c++;

     /* 
      * Special case, a trailing "/" is accepted on the
      * end of the board settings.
      */

     if (r == -8 && p[1] == ' ')
	     r = 0;

     if (r < 0 || c > 8) return EPD_ERROR;
     if (c == 8 && p[1] != '/' && p[1] != ' ') return EPD_ERROR;
     p++;
   }

   board.pmaterial[white] = board.material[white] - 
				nbits(board.b[white][pawn]) * ValueP;
   board.pmaterial[black] = board.material[black] - 
				nbits(board.b[black][pawn]) * ValueP;
   board.king[white] = leadz (board.b[white][king]);
   board.king[black] = leadz (board.b[black][king]);
   UpdateFriends (); 
   UpdateCBoard ();
   UpdateMvboard ();

   /*  Get side to move  */
   if (!++p) return EPD_ERROR;
   if      (*p == 'w') board.side = white; 
   else if (*p == 'b') board.side = black;
   else return EPD_ERROR;

   /* Isn't this one cute? */
   if (!++p || *p != ' ' || !++p) return EPD_ERROR;
  
   /*  Castling status  */
   while (p && *p != ' ') {
      if      (*p == 'K') board.flag |= WKINGCASTLE;
      else if (*p == 'Q') board.flag |= WQUEENCASTLE;
      else if (*p == 'k') board.flag |= BKINGCASTLE;
      else if (*p == 'q') board.flag |= BQUEENCASTLE;
      else if (*p == '-') { p++; break; }
      else return EPD_ERROR;
      p++;
   }
   if (!p || *p != ' ' || !++p) return EPD_ERROR;

   /*
    * En passant square, can only be '-' or [a-h][36]
    * In fact, one could add more sanity checks here.
    */
   if (*p != '-') {
      if (!p[1] || *p < 'a' || *p > 'h' ||
	  !(p[1] == '3' || p[1] == '6')) return EPD_ERROR;
      board.ep = (*p - 'a') + (p[1] - '1')*8;
      p++;
   } else {
      board.ep = -1;
   }

   solution[0] = '\0';
   id[0] = '\0';

   if (!++p) return EPD_SUCCESS;

   /* The opcodes are optional, so we should not generate errors here */

   /*  Read in best move; "bm" operator */
   str_p = strstr(p, "bm");
   if (str_p) sscanf (str_p, "bm %63[^;];", solution); 

   /*  Read in the description; "id" operator */
   str_p = strstr(p, "id");
   if (str_p) sscanf (p, "id %31[^;];", id);

   phase = PHASE;

   return EPD_SUCCESS;
}
Example #28
0
static cmph_uint8 bmz_traverse_critical_nodes_heuristic(bmz_config_data_t *bmz, cmph_uint32 v, cmph_uint32 * biggest_g_value, cmph_uint32 * biggest_edge_value, cmph_uint8 * used_edges, cmph_uint8 * visited)
{
        cmph_uint32 next_g;
	cmph_uint32 u;   /* Auxiliary vertex */
	cmph_uint32 lav; /* lookahead vertex */
	cmph_uint8 collision;
	cmph_uint32 * unused_g_values = NULL;
	cmph_uint32 unused_g_values_capacity = 0;
	cmph_uint32 nunused_g_values = 0;
	vqueue_t * q = vqueue_new((cmph_uint32)(0.5*graph_ncritical_nodes(bmz->graph))+1);
	graph_iterator_t it, it1;

	DEBUGP("Labelling critical vertices\n");
	bmz->g[v] = (cmph_uint32)ceil ((double)(*biggest_edge_value)/2) - 1;
	SETBIT(visited, v);
	next_g    = (cmph_uint32)floor((double)(*biggest_edge_value/2)); /* next_g is incremented in the do..while statement*/
	vqueue_insert(q, v);
	while(!vqueue_is_empty(q))
	{
		v = vqueue_remove(q);
		it = graph_neighbors_it(bmz->graph, v);		
		while ((u = graph_next_neighbor(bmz->graph, &it)) != GRAPH_NO_NEIGHBOR)
		{		        
               	        if (graph_node_is_critical(bmz->graph, u) && (!GETBIT(visited,u)))
			{
			        cmph_uint32 next_g_index = 0;
			        collision = 1;
			        while(collision) // lookahead to resolve collisions
				{
				        if (next_g_index < nunused_g_values) 
					{
					        next_g = unused_g_values[next_g_index++];						
					}
					else    
					{
					        next_g = *biggest_g_value + 1; 
						next_g_index = UINT_MAX;
					}
					it1 = graph_neighbors_it(bmz->graph, u);
					collision = 0;
					while((lav = graph_next_neighbor(bmz->graph, &it1)) != GRAPH_NO_NEIGHBOR)
					{
  					        if (graph_node_is_critical(bmz->graph, lav) && GETBIT(visited,lav))
						{
   						        if(next_g + bmz->g[lav] >= bmz->m)
							{
							        vqueue_destroy(q);
								free(unused_g_values);
								return 1; // restart mapping step.
							}
							if (GETBIT(used_edges, (next_g + bmz->g[lav]))) 
							{
							        collision = 1;
								break;
							}
						}
					}
					if(collision && (next_g > *biggest_g_value)) // saving the current g value stored in next_g.
					{
					        if(nunused_g_values == unused_g_values_capacity)
						{
   						        unused_g_values = (cmph_uint32 *)realloc(unused_g_values, (unused_g_values_capacity + BUFSIZ)*sizeof(cmph_uint32));
						        unused_g_values_capacity += BUFSIZ;  							
						} 
						unused_g_values[nunused_g_values++] = next_g;							

					}
 					if (next_g > *biggest_g_value) *biggest_g_value = next_g;
				}	
				next_g_index--;
				if (next_g_index < nunused_g_values) unused_g_values[next_g_index] = unused_g_values[--nunused_g_values];

				// Marking used edges...
				it1 = graph_neighbors_it(bmz->graph, u);
				while((lav = graph_next_neighbor(bmz->graph, &it1)) != GRAPH_NO_NEIGHBOR)
				{
                 		        if (graph_node_is_critical(bmz->graph, lav) && GETBIT(visited, lav))
					{
                   			        SETBIT(used_edges,(next_g + bmz->g[lav]));
						if(next_g + bmz->g[lav] > *biggest_edge_value) *biggest_edge_value = next_g + bmz->g[lav];
					}
				}
				bmz->g[u] = next_g; // Labelling vertex u.
				SETBIT(visited, u);
			        vqueue_insert(q, u);
			}			
	        }
		 
	}
	vqueue_destroy(q);
	free(unused_g_values);
	return 0;  
}
Example #29
0
void FURNRecord::IsAnim17(bool value)
    {
    SETBIT(MNAM.value, fIsAnim17, value);
    }
Example #30
0
void CELLRecord::IsLightFogPowerInherited(bool value)
    {
    SETBIT(LNAM.value, fIsFogPowerInherited, value);
    }