예제 #1
0
파일: main.c 프로젝트: f2008700/BITS
int main()
{
	int i,size=15;
	ElementList E;
	Element e1;
	e1.id=2000;
	e1.regstatus=0;
	for(i=0;i<size;i++)
	{
			E[i].id=i;
			E[i].regstatus=(i%3); //0= Success, 1 = Conflict, 2 = Deny
	}
	// R containing All (size number) registered student records
	ListHead ks, kd, kc;
	ks=createList();
	kd=createList();
	kc=createList();	 				
	for (i = 0; i < size; i++) {
		if  (E[i].regstatus == 0) {
	  		insertAtTail (E[i], ks);
		} else if  (E[i].regstatus == 1) {
			insertAtHead (E[i], kc);
		} else {
			insertAtHead (E[i], kd);
		}
	}
	printf("\n\nSUCCESS LIST\n");
	printList(ks);

	printf("\n\nCONFLICT LIST\n");
	printList(kc);

	printf("\n\nDENY LIST\n");
	printList(kd);


	deleteFromHead(ks);
	deleteFromTail(kc);
	deleteFromHead(kd);

	printf("\n\nSUCCESS LIST After Deletion\n");
	printList(ks);

	printf("\n\nCONFLICT LIST After Deletion\n");
	printList(kc);

	printf("\n\nDENY LIST After Deletion\n");
	printList(kd);
	

}
예제 #2
0
int main()
{
	LIST *list1, *list2;
	list1=createList(10);
	list2=createList(10);
	int j;
	for(j=0; j<12; j++)
		insertAtHead(list1,j+1);
	printList(list1);

//	for(j=0; j<12; j++)
//		insertAtTail(list2,j+1);
//	printList(list2);

	deleteFromHead(list1);
	deleteFromHead(list1);
	deleteFromHead(list1);
	deleteFromHead(list1);
	printList(list1);
	for(j=0; j<6; j++)
		insertAtTail(list1,99);
	printList(list1);
	printf("\n");
	return 0;
}
예제 #3
0
void kma_free(void* ptr, kma_size_t size)
{
  size = roundUp(size);
  kma_page_t *page = *((kma_page_t **) BASEADDR(ptr));
  if (diff(size) == 8) { //if 8196, free the page
    free_page(page);
    PAGE_COUNT--;
  } else {
    page->size += size;
    if (page->size == PAGESIZE - sizeof(kma_page_t*)) {
      derefPage(page->ptr, size); //if page is made of free buffers, derefence the buffer in freelist
      free_page(page);
      PAGE_COUNT--;
    } else {  //not all free, give the buffer back to freelist
      insertAtHead(ptr, size);
    }
  }
  //free everything
  if(PAGE_COUNT == 1) {
    free_page(FREEPAGE);
    INIT = FALSE;
    PAGE_COUNT = 0;
    FREE_LIST_HEAD = NULL;
  }
}
예제 #4
0
BM_Frame *findFIFO(BM_BufferPool *const bm) {

    // Retrieve management data
    BM_MgmtData *mgmtData = bm->mgmtData;
    RC fifoResult = RC_OK;
    BM_Frame *frame = NULL;

    BM_Node *head = mgmtData->head;
    
    // Do we have a head or do we need to create a list?
    if(head == NULL){
        head = newNode(&mgmtData->framePool[0]);
        int i;
        for (i = 0; i < bm->numPages; i++) {
            BM_Frame *checkFrame = &mgmtData->framePool[i];
            frame = &mgmtData->framePool[i];
            insertAtHead(&head, frame);
        }
        mgmtData->head = head;
    }

    //in use
    frame = removeFromTail(head)->frame;
    while(frame->fixCount == 1){
        insertAtHead(&head, frame);
        frame = removeFromTail(head)->frame;
    }

    //must write data before using
    if (frame->isDirty && frame->fixCount == 0) {
        RC writeBlockResult = writeBlock(frame->pageNum, &mgmtData->fh, frame->memPage);

        mgmtData->ioWrites++;
        frame->isDirty = FALSE;
    }

    return frame;
}
예제 #5
0
RC initBufferPool(BM_BufferPool *const bm, const char *const pageFileName, const int numPages, ReplacementStrategy strategy, void *stratData)
{
    // Initialize buffer pool
    bm->pageFile = (char *)malloc(strlen(pageFileName) + 1);
    strcpy(bm->pageFile, pageFileName);
    bm->numPages = numPages;
    bm->strategy = strategy;

    // Initialize management data for buffer pool
    BM_MgmtData *mgmtData;
    mgmtData = MAKE_MGMTDATA();
    mgmtData->ioWrites = 0;
    mgmtData->ioReads = 0;
    mgmtData->head = NULL;

    // Open page file for buffer mgmt
    openPageFile(bm->pageFile, &mgmtData->fh);
    
    // Initialize frame pool
    mgmtData->framePool = MAKE_FRAME_POOL(numPages);

    int i;
    for (i = 0; i < numPages; i++) {
        mgmtData->framePool[i].frameID = i;
        mgmtData->framePool[i].isDirty = FALSE;
        mgmtData->framePool[i].fixCount = 0;
        mgmtData->framePool[i].pageNum = NO_PAGE;
        mgmtData->framePool[i].memPage = (SM_PageHandle)malloc(PAGE_SIZE);
    }

    // For LRU and FIFO
    BM_Node *head = newNode(&mgmtData->framePool[0]);
    BM_Frame *frame = NULL;

    for(i = 1; i < bm->numPages; i++){
        frame = &mgmtData->framePool[i];
        insertAtHead(&head, frame);
    }
    mgmtData->head = head;

    bm->mgmtData = mgmtData;

    return RC_OK;
}
예제 #6
0
int main()
{
	int i;
	LINKED_LIST myListHead=getNode();
	myListHead->next=NULL;

	for(i=0;i<10;i++)
	{
		LINKED_LIST tempNode=getNode();
		tempNode->key=i;
		insertAtHead(myListHead,tempNode);
	}


	printLinkedList(myListHead);


	LINKED_LIST searchElement;
	searchElement=getNode();

	searchElement=listSearch(myListHead,4);	

	printf("\n\nSearchedElement:%d\n",searchElement->key);

	LINKED_LIST lastNode;
	searchElement=getNode();

	searchElement=findLastNode(myListHead);	

	printf("\n\nLastNode:%d\n",searchElement->key);


	LINKED_LIST toDeleteElement;
	toDeleteElement=getNode();
	toDeleteElement=listSearch(myListHead,6);
	int deletedElement=deleteNode(myListHead,toDeleteElement);
	
	printf("\nElementDeleted=%d\n",deletedElement);	
	printLinkedList(myListHead);
	


	return 0;
}
예제 #7
0
파일: dll.c 프로젝트: tnesbit450/learning
int main()
{
	int userInput;
	struct Node* head;
	struct Node* tail;
	head = NULL;
	tail = NULL;
	
	printWelcomeMsg();
	
	userInput = 0;
	while (userInput != -1) {
		userInput = getSelection("Enter your selection: ");		
		if(userInput == 1) {
			userInput = getSelection("Enter the value to append to head: ");
			insertAtHead(&head, &tail, userInput);
		} else if (userInput == 2) {
			userInput = getSelection("Enter the value to append to tail: ");
			insertAtTail(&tail, &head, userInput);
		} else if (userInput == -1) {
			printExitMessage();
			scanf("%d", &userInput);
			printf("\n");
			if (userInput == 1) {
				printForward(tail);
			} else if (userInput == 2) {
				printReverse(head);
			} else {
				printf("\nExiting without displaying output.");
			}
			return 0;
		}
		else {
			printf("You've made an error. Please try again.\n\n");
		}
	}

	printForward(tail);
	
	return 0;
}
예제 #8
0
void movetoHead(BM_Node **head, BM_Frame *frame){
    BM_Node *temp = *head;

    while (temp->next != NULL) {
        if (temp->next->frame->pageNum == frame->pageNum)
            break;
        temp = temp->next;
    }

    if(temp->next == NULL)
        return;

    //found frame in list, currently in temp
    BM_Node *node = temp->next;
    if(node->prev != NULL)
        node->prev->next = node->next;
    if(temp->next != NULL)  
        node->next->prev = node->prev;

    insertAtHead(head, frame);
}
예제 #9
0
RC pinPage(BM_BufferPool *const bm, BM_PageHandle *const page, const PageNumber pageNum) {
    // Retrieve management data
    BM_MgmtData *mgmtData = bm->mgmtData;

    BM_Frame *frame = NULL;

    // Check for existing frame for this page
    int i;
    for (i = 0; i < bm->numPages; i++) {
        if (pageNum == (&mgmtData->framePool[i])->pageNum) {
            frame = &mgmtData->framePool[i];
            break;
        }
    }
    //printf("Passed check for existing frame");
    //printf("%s", frame);

    // Did we find a frame for this page?
    // If so, update the replacement strategy
    if (frame != NULL) {
        // Update LRU
        if (bm->strategy == RS_LRU) {
            movetoHead(&mgmtData->head, frame);
        }

        frame->fixCount++;
        page->pageNum = pageNum;
        page->data = &frame->memPage[0];
        return RC_OK;
    }
    // If we made it this far, we need to find a free frame
    
    //printf("About to go into find free frame");
    frame = findFreeFrame(bm);

    //printf("Passed find free frame");
    //printf("%s", frame);

    // Check to see if the buffer is full
    if (frame == NULL) {
        //printf("Fail for # %d ", pageNum);
        return RC_BUFFER_FRAME_POOL_FULL;
    }

    //printf("passed buffer frame pool full");

    // Add page to buffer
    if (pageNum >= mgmtData->fh.totalNumPages) {
        //printf("we had to check for capacity");
        RC capacityCheck = ensureCapacity(pageNum + 1, &mgmtData->fh);

        if (capacityCheck != RC_OK) {
            return capacityCheck;
        }
    }

    //printf("passed buffer frame capacity check");
    
    RC resultReadBlock = readBlock(pageNum, &mgmtData->fh, &frame->memPage[0]);
    if (resultReadBlock != RC_OK) {
        return resultReadBlock;
    }

    mgmtData->ioReads++;

    // Mark frame as used
    frame->fixCount++;
    frame->pageNum = pageNum;
    page->pageNum = pageNum;
    page->data = &frame->memPage[0];

    if(bm->strategy == RS_LRU || bm->strategy == RS_FIFO){
        insertAtHead(&mgmtData->head, frame);
    }

    return RC_OK;
}
예제 #10
0
int main()
{
	LIST *list1;
	list1=createList(10);
	insertAtHead(list1,1);
	insertAtHead(list1,2);
	printList(list1);

	insertAtTail(list1,2);
	insertAtTail(list1,3);
	insertAtTail(list1,4);
	insertAtTail(list1,5);
	insertAtTail(list1,6);
	insertAtTail(list1,7);
	insertAtTail(list1,8);
	insertAtTail(list1,9);
	insertAtTail(list1,10);
	insertAtTail(list1,11);
	printList(list1);

	int res, j;
	for(j=0; j<12; j++)
	{
		res=deleteFromHead(list1);
		if(res>0)
			printf("\nDeleted:\t%d",res);
	}
	printList(list1);

	for(j=0; j<12; j++)
	{
		insertAtHead(list1,j+1);
	}
	printList(list1);

	for(j=0; j<12; j++)
	{
		insertAtTail(list1,j+1);
	}
	printList(list1);

	printf("\nDeleted:\t%d",deleteFromHead(list1));
	printf("\nDeleted:\t%d",deleteFromHead(list1));
	printf("\nDeleted:\t%d",deleteFromHead(list1));
	printList(list1);
	printf("\nDeleted:\t%d",deleteFromTail(list1));
	printf("\nDeleted:\t%d",deleteFromTail(list1));
	printf("\nDeleted:\t%d",deleteFromTail(list1));
	printList(list1);

	for(j=0; j<12; j++)
	{
		res=deleteFromTail(list1);
		if(res>0)
			printf("\nDeleted:\t%d",res);
	}
	printList(list1);

	for(j=0; j<12; j++)
	{
		insertAtTail(list1,j+1);
	}
	printList(list1);

	printf("\n");
	return 0;
}
예제 #11
0
void stack::push( const NODE* itemToPush )
{
  insertAtHead( itemToPush ); // Inserts at the top of the stack.
}