Ejemplo n.º 1
0
bool addRecursive(CuckooMap* map, uint64_t key, uint64_t value, int depth)
{
	if(depth > MAX_LOOP)
	{
		return false;
	}
	//if its empty in the first table, add it there
	if(getKey1(map, key) == NONE)
	{
		set1(map, key, value);
	}
	//if its empty in the second table, add it there
	else if(getKey2(map, key) == NONE)
	{
		set2(map, key, value);
	}
	//if both are occupied, randomly displace one and re-add the displaced one
	else if((xorshf96() & 1) == 0)
	{
		uint64_t pushedKey = getKey1(map, key);
		uint64_t pushedValue = getValue1(map, key);
		set1(map, key, value);
		return addRecursive(map, pushedKey, pushedValue, depth + 1);
	}
	else
	{
		uint64_t pushedKey = getKey2(map, key);
		uint64_t pushedValue = getValue2(map, key);
		set2(map, key, value);
		return addRecursive(map, pushedKey, pushedValue, depth + 1);
	}
	return true;
}
Ejemplo n.º 2
0
// Obtener el valor actual del sensor
char* Pir::getValue(int index) 
{
  s = String(_val[index],2);
	return getValue2(_title[index]);
	/*
  s = "|" + _title[index] + ":" + s;
  s.toCharArray(c,sizeof(c));
  return c;
	*/
}
Ejemplo n.º 3
0
/**
 * An internal function for checking cyclic reference dependency error.
 *
 * ==========
 * Returns 1 if cyclic dependency is found, 0 if otherwise
 */
static int isCyclicError(const Worksheet *worksheet, const char *visitedCells, CellReference *cellRef)
{
    pcre2_match_data *match_data = NULL;
    char *saveptr = NULL;
    int rc = 0;

    MatrixLocation *m = convertToMatrixLocation(cellRef);  
    
    char *cellValue = NULL;
    getValue2(worksheet, &cellValue, m->row, m->col);
    free(m);

    if (cellValue == NULL)
    {
        return 0;
    }

    // do work on working copy
    char *token = NULL;
    token = strtok_r(cellValue, " ", &saveptr);
    pcre2_code *re = getCellReferencePattern();
    while(token != NULL)
    {
        match_data = pcre2_match_data_create(20, NULL);
        int subjectLength = strlen(token);
        rc = pcre2_match(re, (PCRE2_SPTR) token, subjectLength, 0, 0, match_data, NULL); 

        if (rc > 0)
        {
            // search if current cellref is in the visited cells
            pcre2_code *searchVal = compilePattern(token);
            int isCyclicDependency = pcre2_match(searchVal, (PCRE2_SPTR) visitedCells, strlen(visitedCells), 0, 0, match_data, NULL);
            if (isCyclicDependency > 0)
            {
                free(cellValue);
                free(match_data);
                free(searchVal);
                free(re);
                return 1;
            }
            
            free(searchVal);

            //length of existing visitedCells + space character + length of cellRef to be appended + null terminator
            char *newVisitedCells = malloc(sizeof(char) * (strlen(visitedCells) + 1 + strlen(cellRef->cellReference)) + 1);
            strcpy(newVisitedCells, visitedCells);
            strcat(newVisitedCells, " ");
            strcat(newVisitedCells, cellRef->cellReference);
        
            CellReference *tokenCellRef = malloc(sizeof(CellReference));
            tokenCellRef->cellReference = token;

            if(isCyclicError(worksheet, (const char *) newVisitedCells, tokenCellRef))
            {        
                free(cellValue);
                free(newVisitedCells);
                free(match_data);
                free(re);
                return 1;
            }   
      
            free(newVisitedCells);
            free(tokenCellRef);
        }
        token = strtok_r(NULL, " ", &saveptr);
        free(match_data);
    }

    free(cellValue);
    free(re);
    return 0;
}
		void findgate(void)
{
    
            
    getValue2();
	while(value_front < 150 && value_4sens >150)
	{
	
	
	/*leftSpeed = forwardLeftSpeed - *kp;
    rightSpeed = forwardRightSpeed + *kp;

    velocity(leftSpeed, rightSpeed)*/
	
    right();
	if(value_2sens >150)
	{
		forward();
		return;
	}
	getValue2();
	
	}	
	
	while(value_front < 150 && value_2sens >150)
	{
		
		/*leftSpeed = forwardLeftSpeed - *kp;
    rightSpeed = forwardRightSpeed + *kp;

    velocity(leftSpeed, rightSpeed)*/
	left();
	
	if(value >150)
	{
		forward();
		return;

	getValue2();
	}	
	
    

    stop();
    _delay_ms(100);

    

  
}

void entergate(void)
{
	//follow line 
	
	
	if (centre>150 && sensorLeft >150 && sensorRight >150)
	{
		stop();
		_delay_ms(200);
		exit(); 
	}
}