示例#1
0
/* A function to label a page as dirty.
 */
RC markDirty (BM_BufferPool *const bm, BM_PageHandle *const page) {
  // page->pageNum is dirty, mark it in buffer header
  BM_PoolInfo *pi = (BM_PoolInfo *)bm->mgmtData;
  int index = searchArray(page->pageNum, pi->map, pi->numPages);
  pi->dirtys[index] = true;
  return RC_OK;
}
示例#2
0
/* A function to unpin a page when a user finishes using it.
 */
RC unpinPage (BM_BufferPool *const bm, BM_PageHandle *const page) {
  // unpin the page, decrement fix count
  BM_PoolInfo *pi = (BM_PoolInfo *)bm->mgmtData;
  int index = searchArray(page->pageNum, pi->map, pi->numPages);
  pi->fixCounter[index]--;

  // printf("buffer_mgr: unpinning page (%d) with fixCounter (%d)\n", page->pageNum, pi->fixCounter[index]);

  // if (bm->strategy == RS_LRU) {
  //   pi->lru_stamp = update_lru(index, pi->lru_stamp, pi->numPages);
  // }
  return RC_OK;
}
示例#3
0
int main(int argc,char** argv)
{
	//Error checking for the number of argument//
	if (argc !=3)
	{
		printf("Insufficent arguments");
		return -1;
	}
	//Error checking for existance of input//
	int size=loadArray(argv[1]);
	if(size==0)
        {
                printf("Unable to open the input file");
                return -1;
        }
	//Declaration of variables//
	int id, ngrade,search;
	//Display output//
	printf("Student Record\n");
	printArray(size);
	//Search ID and rewritng new grade//
	printf("\nEnter the ID of the student to search:");
	scanf("%d",&id);
	printf("Enter a grade of the student:");
	scanf("%d",&ngrade);
	// Checking for the existance of the id//
	if((search=searchArray(size,id,ngrade))==0)
	{
		printf("Student with id %d is not present in the class\n");
	}
	//Write a new file with the new revision//
	else
	{
		int x=writeContent(argv[2],size);
		//Print new output//
		printf("\nUpdated student record\n");
		printArray(size);
	}
	sortArray(size);
	//Bonus Part Sorting array//
	printf("\nBonus part\nPrinting sorted student record\n");
	printArray(size);

	return 0;	

}
示例#4
0
bool searchMatrix(int** matrix, int matrixRowSize, int matrixColSize, int target) {
    int start = 0, end = matrixRowSize - 1;

    while (start < end) {
        int mid = (start + end) / 2;

        if (matrix[mid][0] == target) {
            return true;
        }

        if (matrix[mid][0] < target) {
            start = mid + 1;
        } else {
            end = mid - 1;
        }
    }

    return searchArray(&matrix[start], matrixColSize, target);
}
示例#5
0
/* A function to writes a page to the disk.
 */
RC forcePage (BM_BufferPool *const bm, BM_PageHandle *const page) {
  // writes page to disk

  // read fHandle pointer from buffer header
  // from buffer reader, get the pointer to page and store it in memPage
  // writeBlock(page->numPage, fHandle, memPage);
  RC rc_code;
  BM_PoolInfo *pi = (BM_PoolInfo *)bm->mgmtData;
  SM_FileHandle *fh = pi->fh;
  int index = searchArray(page->pageNum, pi->map, pi->numPages);
  rc_code = writeBlock(pi->map[index], fh, pi->frames[index]);
  NumWriteIO++;
  if (rc_code != RC_OK)
    return rc_code;

  pi->dirtys[index] = false;

  return RC_OK;
}
示例#6
0
//---------------------------------------------------------------------
void	componentConverter::getContainedEdges(	MIntArray& vtxIDs,
												MIntArray& result	)
//---------------------------------------------------------------------
{
//	result.clear();

	MFnMesh meshFn(mesh);
	MItMeshVertex vertIter(mesh);

	BPT_BA searchArray(meshFn.numEdges());
	
	MIntArray conEdges;
	

	
	unsigned int l = vtxIDs.length();
	int indexValue;
	for(unsigned i = 0;i < l;i++)
	{
		vertIter.setIndex(vtxIDs[i],tmp);
		vertIter.getConnectedEdges(conEdges);
		
		
		
		for(unsigned int x = 0; x < conEdges.length(); x++)
		{
			indexValue = conEdges[x];
			if( searchArray[indexValue] )
			{
				result.append(indexValue);
			}
			else
				searchArray.setBitTrue(indexValue);
		}
	}




}
示例#7
0
文件: labb3.c 项目: RLundh/labb3
int main()
{
    static int array[100];
    int initilized = 0;
    int sorted = 0;
    
    int loop = 1;
    while(loop == 1)
    {
        int choice;
        printf("Välj opperation:\n");
        printf("  1. Generera en ny Talföljd.\n");
        printf("  2. Sortera arrayen.\n");
        printf("  3. Min/Max/median.\n");
        printf("  4. Sök.\n");
        printf("  8. Print array.\n");
        printf("  9. Exit.\n");
        scanf("%d", &choice);
        
        switch(choice)
        {
            case 1:
                array = generateArray(array);
                initilized = 1;
                sorted = 0;
                printArray(array);
                break;
            case 2:
                if(initilized == 1)
                {
                    array = sortArray(array);
                    sorted = 1;
                    printArray(array);
                }
                else
                {
                    printf("Ej giltig Talföljd.\nGenerera en ny först.\n");
                }
                break;
            case 3:
                if(sorted == 1)
                {
                    valueOperations(array);
                }
                 else
                {
                    printf("Ej giltig Talföljd.\nGenerera en ny Sortera först.\n");
                }
                break;
            case 4:
                if(sorted == 1)
                {
                    int value;
                    printf("Vilket värde vill ni söka efter?\n");
                    scanf("%d", &value);
                    searchArray(array, value);
                }
                 else
                {
                    printf("Ej giltig Talföljd.\nSortera först.\n");
                }
            case 8:
                printArray(array);
                break;
            case 9:
                loop = 0;
                break;
            default:
                printf("Ej giltigt kommando.\n");
                break;
        }
            
    }
    return 1;
}
示例#8
0
	void next()
	{
		//LEXICAL ANALYSIS
	//	std::cout << "in next" << std::endl;

		type = -1;
		val = (char*)malloc(MAX_LINE_LEN);
	//	char c = fgetc(fp);
	//	std::cout << c << std::endl;
		while(c!=EOF)
		{
			if(c == '\n')
			{
				numLines++;	
				c = fgetc(fp);
				continue;
			}

			//CASE : WHITESPACE
			if(c == ' ' || c == '\t')
			{
				c = fgetc(fp);
				continue;
			}

			//CASE 1: NUM
			if(isdigit(c))
			{
				extractNum(c,val);
				type = 0;
			}

			//CASE 2: KEYWORD / IDENTIFIER / operator AND-OR
			else if(isalpha(c))
			{
				//get alphanum token
				getToken(c,val);
	
				if(searchArray(keywords,val,NUM_KEYWORDS) != -1)
					type = 1;
	
				else if(searchArray(boolSymbols,val,NUM_BOOLSYMBOLS) != -1)
					type = 12;
	
				else	//identifier
					type = 2;
			}

			else if(searchArray(mathSymbols,c,NUM_MATHSYMBOLS) != -1)
			{
				type = 6;
				val[0] = c;
				c = fgetc(fp);
			}	

			else if(searchArray(relationalSymbols,c,NUM_RELATIONALSYMBOLS) != -1)
			{
				type = 7;
				val[0] = c;
//				std::cout << val << std::endl;
				c = fgetc(fp);
			}	

			else if(searchArray(equalSymbols,c,NUM_EQUALSYMBOLS) != -1)
			{
				type = 8;
				val[0] = c;
				c = fgetc(fp);
			}	

			else if(searchArray(arraySymbols,c,NUM_ARRAYSYMBOLS) != -1)
			{
				type = 9;
				val[0] = c;
				c = fgetc(fp);
			}	
	
			else if(searchArray(blockSymbols,c,NUM_BLOCKSYMBOLS) != -1)
			{
				type = 10;
				val[0] = c;
				c = fgetc(fp);
			}

			else if(searchArray(parenSymbols,c,NUM_PARENSYMBOLS) != -1)
			{
				type = 11;
				val[0] = c;
				c = fgetc(fp);
			}

			else if(searchArray(boolSymbols,c,NUM_BOOLSYMBOLS) != -1)
			{
				type = 12;
				val[0] = c;
				c = fgetc(fp);
			}	

			//CASE 4: PUNCTUATION
			else if(searchArray(punctuation,c,NUM_PUNCTUATION) != -1)
			{
				//std::cout << "In PUNCT " <<  c << std::endl;
				type = 4;
				val[0] = c;
				c = fgetc(fp);
			}

			//CASE 5: CHAR
			else if(c == '\'')
			{
				c = fgetc(fp);
				if(c == '\\')
					c = fgetc(fp);

				type = 5;
				val[0] = c;
//				c = fgetc(fp);
				c = fgetc(fp);
			}

			//CASE : UNKNOWN
			else
			{
				type = 13;
				val[0] = c;
				c = fgetc(fp);
			}
			return;

		//	addToken(type,numLines,val);
		//	type = -1;
		//	memset(val,'\0',strlen(val));
		}
	}
示例#9
0
文件: BU4la.c 项目: apamburn/CS4490
int main(int argc, char* argv[])
{
	//read in file
	char str[MAX_LINE_LEN];
	FILE *fp;

	fp=fopen(argv[1],"r");
	if(fp==NULL)
	{
		fprintf(stderr,"Can't open input file!");
		exit(1);
	}

	//LEXICAL ANALYSIS
	int numLines = 0;
	int type = -1;
	char* val = (char*)malloc(MAX_LINE_LEN);
	while(fgets(str,MAX_LINE_LEN,fp)!=NULL)
	{
		char* curPos = str;
		while(*curPos != '\n' && strcmp(curPos,"") != 0)
		{
			//CASE : WHITESPACE
			if(*curPos == ' ' || *curPos == '\t')
			{
				curPos++;
				continue;
			}

			//CASE 1: NUM
			else if(isdigit(*curPos))
			{
				extractNum(curPos,val);
				type = 0;
			}

			//CASE 2: KEYWORD / IDENTIFIER / operator AND-OR
			else if(isalpha(*curPos))
			{
				//get alphanum token
				getToken(curPos,val);

				if(searchArray(keywords,val,NUM_KEYWORDS) != -1)
					type = 1;
		
				else if(searchArray(boolSymbols,val,NUM_BOOLSYMBOLS) != -1)
					type = 12;
		
				else	//identifier
					type = 2;
			}

			else if(searchArray(mathSymbols,*curPos,NUM_MATHSYMBOLS) != -1)
			{
				type = 6;
				val[0] = *curPos;
				curPos++;
			}	

			else if(searchArray(relationalSymbols,*curPos,NUM_RELATIONALSYMBOLS) != -1)
			{
				type = 7;
				val[0] = *curPos;
				curPos++;
			}	

			else if(searchArray(equalSymbols,*curPos,NUM_EQUALSYMBOLS) != -1)
			{
				type = 8;
				val[0] = *curPos;
				curPos++;
			}	

			else if(searchArray(arraySymbols,*curPos,NUM_ARRAYSYMBOLS) != -1)
			{
				type = 9;
				val[0] = *curPos;
				curPos++;
			}	
		
			else if(searchArray(blockSymbols,*curPos,NUM_BLOCKSYMBOLS) != -1)
			{
				type = 10;
				val[0] = *curPos;
				curPos++;
			}

			else if(searchArray(parenSymbols,*curPos,NUM_PARENSYMBOLS) != -1)
			{
				type = 11;
				val[0] = *curPos;
				curPos++;
			}

			else if(searchArray(boolSymbols,*curPos,NUM_BOOLSYMBOLS) != -1)
			{
				type = 12;
				val[0] = *curPos;
				curPos++;
			}	

			//CASE 4: PUNCTUATION
			else if(searchArray(punctuation,*curPos,NUM_PUNCTUATION) != -1)
			{
				type = 4;
				val[0] = *curPos;
				curPos++;
			}

			//CASE 5: CHAR
			else if(*curPos == '\'')
			{
				curPos++;
				if(*curPos == '\\')
					curPos++;

				type = 5;
				val[0] = *curPos;
				curPos = curPos+2;
			}

			//CASE : UNKNOWN
			else
			{
				type = 13;
				val[0] = *curPos;
				curPos++;
				//addToken(13,numLines,val);
			}

			addToken(type,numLines,val);
			type = -1;
			memset(val,'\0',strlen(val));
		}
		numLines++;
	}

	fclose(fp);

	printTokens();
	fflush(stdout);
	//END FILE READ	
}
示例#10
0
void ambientColor::update(float simulatedTime, bool useSimulateTime) {


	//FINDING THE RANGE ACCORDING TO THE TIME
	int iLow;
	int iHigh;

	vector<int>valuesColorTime;
	for (int i = 0;i < colors.size();i++) {
		valuesColorTime.push_back(convertTime(colors[i].getHour(), colors[i].getMinute(), colors[i].getSeconds()));
		//cout << "time convert" << convertTime(colors[i].getHour(), colors[i].getMinute(), colors[i].getSeconds()) << endl;
	}
	int currentTime = convertTime(ofGetHours(), ofGetMinutes(), ofGetSeconds());
	
	if (useSimulateTime)currentTime = simulatedTime;
	//cout << "simulated time" << simulatedTime << endl;
	
	int closestIndex = searchArray(valuesColorTime, currentTime);
	//cout << "currentTime converted" << currentTime<<endl;
	//cout << "closestIndex" << closestIndex << endl;
	if (valuesColorTime[closestIndex] > currentTime) {
		iHigh = closestIndex;
		iLow = closestIndex - 1;
		if (iLow < 0) { 
	
			iLow = colors.size() - 1; 

			//valuesColorTime[iLow] -= valuesColorTime[iHigh];
		}
	}
	else if (valuesColorTime[closestIndex] < currentTime) {
		iLow = closestIndex;
		iHigh = closestIndex + 1;
		if (iHigh > colors.size() - 1) { 
			iHigh = 0; 
			
			//valuesColorTime[iHigh] += valuesColorTime[iLow];
		}
	}
	else if (valuesColorTime[closestIndex] == currentTime) {
		currentColor = colors[closestIndex];
		return;
	}
	
	//cout << "iLow" << iLow << endl;
	//cout << "iHigh" << iHigh << endl;

	//cout << "val iLow" << valuesColorTime[iLow] << endl;
	//cout << "val iLow" << valuesColorTime[iLow] << endl;
	//cout << "val iHigh" << valuesColorTime[iHigh] << endl;
	//previousColor= colors[iLow];
	//nextColor = colors[iHigh];

	float tNorm = ofMap(currentTime, valuesColorTime[iLow], valuesColorTime[iHigh], 0.0, 1.0,true);
	if (valuesColorTime[iLow] > valuesColorTime[iHigh]) {
		tNorm = ofMap(currentTime, valuesColorTime[iHigh], valuesColorTime[iLow], 0.0, 1.0);
		//cout << "tnorm" << endl;
	}

	//cout << "tNorm" << tNorm;
	for (int i = 0;i < NUM_COLORS_IN_PALETTE;i++) {
		ofColor c1=colors[iLow].getCol(i);
		ofColor c2 = colors[iHigh].getCol(i);;

		//cout << "c1" << c1<<endl;
		//cout << "c2" << c2<<endl;
		currentColor.setCol(ofColor(ofLerp(c1.r, c2.r, tNorm), ofLerp(c1.g, c2.g, tNorm), ofLerp(c1.b, c2.b, tNorm)), i);
	}

}
示例#11
0
文件: lab8.c 项目: sts44b/cs1050
//call function main and gather inputs from the command line
int main (int argc, char* argv[]){
	
	//declare the variables to be used in this program
	int size, size2;
	int highest;
	int lowest;
	float avg;
	int findID;
	int id;
	int write;

	if (argc != 4)//check to make sure there are the appropriate number of parameters
	{
		printf("\nInsufficient arguments\n");
		return 0;
	}
   
	size = loadArray(argv[1]);//call function to load data from input file ints struct array

	if (size == 0){//if the input file cannout be opened quit program
      return 0;
	}
	
	highest = findHighestgrade(size);//call a function to find the highest grade in the class

	lowest = findLowestgrade(size);//call a function to find the lowest grade in the class

	avg = averageClassgrade(size);//call a funciton to calculate the average grade of the class
   
	printf("\n\nStudent record");
	printArray(size);//display the array of data gathered from the input file

	//display the results of the previous functions
	printf("\nThe student with the highest grade is %s with the grade %d", students[highest].name, students[highest].grade);
	printf("\nThe student with the lowest grade is %s with the grade %d\n", students[lowest].name, students[lowest].grade);
	printf("\nThe average grade for the class %.2f\n", avg);

	printf("\nEnter the ID of the student to search: ");
	scanf("%d", &id);//prompt user to enter an id number to search for
	
	findID = searchArray(size, id);//call function to find what student the id entered by the user pionts to

	if (findID == -1){
      printf("Student with the ID %d is not present in the class\n", id);//check to see if correct student number entered
	}
	else{
      printf("Student with the id %d is %s\n", students[findID].id, students[findID].name);//display the student searched for by the user
	}
	
	size2 = updateArray(argv[2], size);

   printf("\nUpdated student record");
   printArray(size + size2);

   sortArray(size + size2);

   printf("\nPrinting sorted student record");
   printArray(size + size2);

   write = writeContent(argv[3], (size + size2), highest, lowest, avg);//call the function to print data in the output file

   if (write == 0)
   {
      printf("\nUnable to open the output file\n");
   }
return 0; 
}//end function main