//called at the time of buffer initialization
	RC initBufferPool(BM_BufferPool *const bm, const char *const pageFileName, 
		  const int numPages, ReplacementStrategy strategy, 
		  void *stratData){
		
		SM_FileHandle fileHandle;
		int i=1;
		//opening a file to be used by BM.
		if (openPageFile ((char *)pageFileName, &fileHandle) == RC_OK){
		bufferPoolInfo *bufferPool=initBufferPoolInfo(numPages,fileHandle);
		
		//setting buffer manager fields.
		bm->numPages=numPages;
		bm->pageFile=(char *)pageFileName;
		bm->strategy=strategy;//stores strategy to be used by BM when the page is to be replaced in frames.
		bufferPool->head=bufferPool->tail=getNewNode();
		bufferPool->head->pageFrameNo=0;
		
		//creating page frame node linked list with number of page frames = numPages
		while(i<numPages){
			bufferPool->tail->next = getNewNode();
			bufferPool->tail->next->previous = bufferPool->tail;
			bufferPool->tail = bufferPool->tail->next;
			bufferPool->tail->pageFrameNo = i;
			i++;
		}
		bufferPool->lastNode=bufferPool->tail;
		bm->mgmtData=bufferPool;//attaching bufferpool info to data of BM to be used by various functions of BM.
		return RC_OK;
	}else{
		RC_message="File to be opened doesn't exist";
		return RC_FILE_NOT_FOUND;
		}
		
	}
Exemplo n.º 2
0
void main(int argc, char*argv[]){

	FILE* fp= fopen(argv[1],"r");
	if(fp==NULL){
		printf("ERROR");
		exit(1);
	}

	int nNodes, nEdges;
	if(fscanf(fp,"%d%d",&nNodes, &nEdges)==EOF){
		printf("ERROR");
		exit(1);
	}

	int srcNode, destNode, dist;
	int i,j,k;
	list** adjacencyList= (list**)malloc(sizeof(list*)*nNodes);

	for( i=0; i< nNodes; i++)
		adjacencyList[i] = getNewNode(i,0);
	while(fscanf(fp,"%d%d%d",&srcNode, &destNode, &dist)!=EOF){	
		adjacencyList[srcNode]= append(adjacencyList[srcNode],
									destNode, 0);
		adjacencyList[destNode]= append(adjacencyList[destNode],
									 srcNode, 0);
	}
	// for(i=0; i< nNodes; i++){
	// 	printf("node %d: ",i);
	// 	printList(adjacencyList[i]->next);
	// }
	nodeColoring(adjacencyList,0, nNodes);
}
Exemplo n.º 3
0
//Insert min heap node
HuffmanNode* HuffmanMinHeap::insertminheap(int count){
	HuffmanNode *newnode=getNewNode();
	heapsize++;
	heapnodearray[heapsize-1]=newnode;
	decreaseMinHeapKey(heapsize-1,count);
	return newnode;
}
Exemplo n.º 4
0
static void addNodeToTable(UTHashTable *table,
                           MMRGBHex hexColor,
                           MMPoint offset)
{
	struct shiftNode *node = getNewNode(table);
	node->color = hexColor;
	node->offset = offset;
	UTHASHTABLE_ADD_INT(table, color, node, struct shiftNode);
}
Exemplo n.º 5
0
extern syntree_nid
syntreeNodeNumber(syntree_t* self, int number){
  node_t* newNode      = getNewNode(self);
  newNode->nodeType       = LEAF;
  newNode->content.number = number;

  //syntreePrint(self, newNode->id);
  //fprintf(stdout, " Number\n");
  return newNode->id;
}
Exemplo n.º 6
0
N *TokenizerImpl<N, P>::getBOSNode() {
  N *bosNode = getNewNode();
  std::memset(bosNode, 0, sizeof(N));
  bosNode->surface = const_cast<const char *>(BOS_KEY);  // dummy
  bosNode->feature = bos_feature_.get();
  bosNode->isbest = 1;
  bosNode->id = id_ - 1;
  bosNode->stat = MECAB_BOS_NODE;
  return bosNode;
}
Exemplo n.º 7
0
void List<NODETYPE>::insertAtBack(const NODETYPE &value) {
    ListNode<NODETYPE> *newPtr = getNewNode(value);

    if (isEmpty()) {
        firstPtr = lastPtr = newPtr;  // new list has only one node
    } else {
        lastPtr->nextPtr = newPtr;
        lastPtr = newPtr;
    }
    ++sz;
}
Exemplo n.º 8
0
void List<NODETYPE>::insertAtFront(const NODETYPE &value) {
    ListNode<NODETYPE> *newPtr = getNewNode(value);

    if (isEmpty()) {
        firstPtr = lastPtr = newPtr;  // new list only has one node
    } else {
        newPtr->nextPtr = firstPtr;  // point new node to previous list node
        firstPtr = newPtr;
    }
    ++sz;
}
Exemplo n.º 9
0
//Inserting data in BST, returns address of the root node
BstNode *Insert(BstNode* root, int data){
	if(root == NULL){
		root = getNewNode(data);
	}
	//if data inserted is lesser, insert to the left of tree
	else if(data <= root->data){
		root -> left = Insert(root -> left, data);//returns address of left
	}
	//vice versa
	else{
		root -> right = Insert(root -> right, data);//returns address of right 
	}
	return root;
}
Exemplo n.º 10
0
extern syntree_nid
syntreeNodeTag(syntree_t* self, syntree_nid id){
  node_t* capsule = getNewNode(self);
  nodeList_t* encapsulated = (nodeList_t*) malloc(sizeof(nodeList_t));
  encapsulated->elem = getNode(self, id);
  encapsulated->next = NULL;

  capsule->nodeType = LIST;
  capsule->content.children = encapsulated;

  //syntreePrint(self, capsule->id);
  //fprintf(stdout, " Tag\n");
  return capsule->id;
}
struct Node* insert(struct Node* root, int data)
{
    if (root == NULL)
    {
        root = getNewNode(data);
    }
    else if (data < root->data)
    {
        root->left = insert(root->left, data);
    }
    else
    {
        root->right = insert(root->right, data);
    }
    return root;
}
Exemplo n.º 12
0
// - Create and append node to back of list
// - Return address
Node* AdjList::appendNode(const vector<int> & initJoinedNodes)
{
    //Create and initialize new node
    Node *newPtr = getNewNode(initJoinedNodes);
    
    if( isEmpty() )
        firstPtr = lastPtr = newPtr;
    else
    {
        lastPtr->nextPtr = newPtr;
        newPtr->prevPtr = lastPtr;
        lastPtr = newPtr;
    }
    
    return newPtr;
}
Exemplo n.º 13
0
static void addNodeToTable(UTHashTable *table,
                           MMRGBHex hexColor,
                           MMPoint offset)
{
	if (table->nodes == NULL) {
		fprintf(stderr, "this is impossible");
	}
	struct shiftNode *node = (struct shiftNode *)getNewNode(table);
	//printf("getnewNode finished!\n");
	//printf("node->color=%d, offset=%d, %d\n", node->color, (node->offset).x, (node->offset).y);
	node->color = hexColor;
	node->offset = offset;
	//printf("i suspect here, or here?!\n");
	UTHASHTABLE_ADD_INT(table, color, node, struct shiftNode);
	//printf("i suspect here!\n");
}
Exemplo n.º 14
0
void insert(Trie_t *t, char string[]){
 node *node = t->root;
 int len = strlen(string);
 int i;
 int val;
 for(i =0; i<len;i++){
  val = (char)string[i]- (char)'a';
  if(!node->child[val]){
     node->child[val] = getNewNode(val);
     node->next = node->child[val];
  }
  node = node->child[val];
  if(i==len-1){
     node->flag = 1;
   }
 }
}
Exemplo n.º 15
0
struct Node* Insert(struct Node* root,int d){
    if(root==NULL){
        root=getNewNode(d);
        return root;
    }

    else{
        if(d <= root->data){
            root->left=Insert(root->left,d);
        }
        else{
            root->right=Insert(root->right,d);
        }
        return root;
    }

}
Exemplo n.º 16
0
void List :: insertAtFront( char value )
{
   ListNode *newPtr = getNewNode( value ); // new node

   if ( isEmpty() ) // List is empty
   {
	   firstPtr = lastPtr = newPtr; // new list has only one node
	   newPtr->prevPtr = NULL;
	   newPtr->nextPtr = NULL;
   }
   
   else // List is not empty
   {
      newPtr->nextPtr = firstPtr; // point new node to previous 1st node
      firstPtr->prevPtr = newPtr; 
	  firstPtr = newPtr;
   } // end else
} // end function insertAtFront
Exemplo n.º 17
0
bool List :: insertAfter(char previous, char newValue)
{
	ListNode *currPtr = firstPtr; // Used to traverse through list  

	if ( isEmpty() ) // List is empty
	{	
		cout << "\n";
		cout << "Cannot Insert. ";
		return true;
	}
		
	else
	{
		ListNode *valuePtr = getNewNode( newValue );

		while( currPtr->data != previous ) // While currPtr's data not equal to the previous
		{
			currPtr = currPtr->nextPtr;	// continue to traverse through the list

			if( currPtr == lastPtr && currPtr->data != previous ) 
			{
				cout << "The Node, " << previous << " does not exist. ";
				return false;
			}

			if(currPtr == lastPtr)
			{
				valuePtr->nextPtr = currPtr->nextPtr;
				valuePtr->prevPtr = currPtr;
				currPtr->nextPtr = valuePtr;
				lastPtr = valuePtr;
				return true;
			}
		} // end while

		ListNode *tempPtr;

		valuePtr->nextPtr = currPtr->nextPtr;
		valuePtr->prevPtr = currPtr;
		currPtr->nextPtr = valuePtr;
		tempPtr = valuePtr->nextPtr;
	} // end else
	return true;
} // end function insertAfter 
Exemplo n.º 18
0
extern syntree_nid
syntreeNodePair(syntree_t* self, syntree_nid id1, syntree_nid id2){
  node_t* capsule = getNewNode(self);
  capsule->nodeType         = LIST;
  capsule->content.children = NULL;

  nodeList_t* encapsulated1 = (nodeList_t*) malloc(sizeof(nodeList_t));
  nodeList_t* encapsulated2 = (nodeList_t*) malloc(sizeof(nodeList_t));
  encapsulated1->elem = getNode(self, id1);
  encapsulated2->elem = getNode(self, id2);

  capsule->content.children = encapsulated1;
  encapsulated1->next       = encapsulated2;
  encapsulated2->next       = NULL;

  //syntreePrint(self, capsule->id);
  //fprintf(stdout, " Pair\n");
  return capsule->id;
}
Exemplo n.º 19
0
void List :: insertAtBack( char value )
{
   ListNode *newPtr = getNewNode( value ); // new node

   if ( isEmpty() ) // List is empty
   {
	   firstPtr = lastPtr = newPtr; // new list has only one node
	   newPtr->nextPtr = NULL;
	   newPtr->prevPtr = NULL;
   }

   else // List is not empty
   {
      lastPtr->nextPtr = newPtr; // update previous last node
	  newPtr->prevPtr = lastPtr;
	  newPtr->nextPtr = NULL;
      lastPtr = newPtr; // new last node
   } // end else
} // end function insertAtBack
Exemplo n.º 20
0
huffNode * makeHuffman( int verbose )
{
  huffNode * ptCharFreq;

  huffNode * ptFirstLow = 0;
  huffNode * ptSecondLow = 0;

  huffNode * ptNewNode =0;

  huffNode * ptHuffRoot = 0;

  //huffNode * ptNewNode;
  huffNode ** pptCharFreqHeap;

  ptCharFreq = GlobalHuffCodes.ptCharFreq;

  pptCharFreqHeap  =  createPointerHeap( ptCharFreq, GlobalHuffCodes.pptCharFreqHeap, verbose );

  initializeRignBuffer( &tTheSecondQueue );

  GlobalHuffCodes.nNextNotleaf = 0;
  
  //3. While there is more than one node in the queues:
  while( !( peekHeap( pptCharFreqHeap ) == 0 && tTheSecondQueue.nSize == 1)  )
  {
    //1. Remove two nodes with the lowest weight from the queues.
    if( verbose == 1 ) printf("\n(D:1)");

    ptFirstLow = minFromQueues( verbose);

    if( verbose == 1 ) printf("\n(D:1 %c %d %d)",ptFirstLow->cCharacter,ptFirstLow->cCharacter,ptFirstLow->nFreq );

    if( verbose == 1 ) printf("\n(D:2)");

    ptSecondLow = minFromQueues( verbose);

    if( verbose == 1 ) printf("\n(D: initializing)");

    if( ptSecondLow != 0)
    {
        if( verbose == 1 ) printf("\n(D:2 %c %d %d)\n",ptSecondLow->cCharacter,ptSecondLow->cCharacter,ptSecondLow->nFreq );
        //2. Create a new internal node, with the two just-removed nodes as children 
        //(either node can be either child) and the sum of their weights as the new weight.
        ptNewNode = getNewNode(  verbose );

        if( ptNewNode == 0)
            return 0;

        ptNewNode->cCharacter = 0;
        ptNewNode->nFreq = ptFirstLow->nFreq + ptSecondLow->nFreq;
        ptNewNode->ptOneChild = ptFirstLow;
        ptNewNode->ptZeroChild =  ptSecondLow; //zeroes are less expensive :)
        ptNewNode->ptParent = 0;

        if( verbose == 1 ) printf("\n(D:new node initialized.)");

        //3. Update the parent links in the two just-removed nodes to point to the just-created parent node.
        ptFirstLow->ptParent = ptNewNode;
        ptSecondLow->ptParent = ptNewNode;
    }
    else
    {
        ptNewNode = getNewNode(  verbose );
        if( ptNewNode == 0)
            return 0;
        
        ptNewNode->ptZeroChild = ptFirstLow;
        ptNewNode->ptOneChild = 0;
        ptFirstLow->ptParent = ptNewNode;

        ptNewNode->nFreq = ptFirstLow->nFreq;
        ptNewNode->cCharacter = 0;

    }
     
     //4. Queue the new node into the second queue.
     if( putToRignBuffer(ptNewNode, &tTheSecondQueue ) == 1 )
     {

        fprintf(stderr,"\nError: ringbuffer full\n");
        if( verbose == 1 ) { printf("\nD: size:%d max:%d )", tTheSecondQueue.nSize, RINGBUFFERSIZE ); }

        return 0;
     }
     if( verbose == 1 ) printf("\n(D: iteration end)");
  }

  ptHuffRoot = getFromQueue( &tTheSecondQueue );  

  ptHuffRoot->ptParent = 0;
  GlobalHuffCodes.ptHuffRoot = ptHuffRoot;

  if( verbose == 1 ) printHeap( GlobalHuffCodes.pptCharFreqHeap ) ;

  return ptHuffRoot;
}
Exemplo n.º 21
0
void Initialize(Trie_t *trie){
  trie->root = getNewNode(0);
}
Exemplo n.º 22
0
//0 == success
int createPath( char * pcTemp, int nEndOfBinary, int verbose)
{
    int i;
    huffNode * ptCurrent = GlobalHuffCodes.ptHuffRoot;
    huffNode * ptNew = 0;

    int index = indexOf( pcTemp[0] );

    if( verbose == 1 )
       printf("\n(D: create path begin: string:%s)", pcTemp);

    if( GlobalHuffCodes.ptCharFreq[ index ].ptParent != 0 )
        return 1;

    
    for( i = 2; i < nEndOfBinary; i++ )
    {
        if( verbose == 1 )
            printf("\n(D:c%c)\n", pcTemp[i]);
        if( pcTemp[i] == '0' )
        {
            if( ptCurrent->ptZeroChild == 0 )
            {
                ptNew = getNewNode(  verbose );
                if( ptNew == 0) 
                    return 1;
                ptCurrent->ptZeroChild = ptNew;
                ptNew->ptParent = ptCurrent;
                ptNew->nFreq = 0;
                ptNew->cCharacter = 0;
                ptNew->ptOneChild = 0;
                ptNew->ptZeroChild = 0;
            }
            else if( ptCurrent->ptZeroChild->cCharacter != 0 )
                return 1;
            ptCurrent = ptCurrent->ptZeroChild;
        }
        else
        {
            if( ptCurrent->ptOneChild == 0 )
            {
                ptNew = getNewNode(  verbose );
                if( ptNew == 0) 
                    return 1;
                ptCurrent->ptOneChild = ptNew;
                ptNew->ptParent = ptCurrent;
                ptNew->nFreq = 0;
                ptNew->cCharacter = 0;
                ptNew->ptOneChild = 0;
                ptNew->ptZeroChild = 0;
            }
            else if( ptCurrent->ptOneChild->cCharacter != 0 )
                return 1;
            ptCurrent = ptCurrent->ptOneChild;
        }
    }

    if( pcTemp[nEndOfBinary ] == '0' )
    {
        ptCurrent->ptZeroChild = &GlobalHuffCodes.ptCharFreq[ index ];
        GlobalHuffCodes.ptCharFreq[ index ].ptParent = ptCurrent;
    }
    else
    {
        ptCurrent->ptOneChild = &GlobalHuffCodes.ptCharFreq[ index ];
        GlobalHuffCodes.ptCharFreq[ index ].ptParent = ptCurrent;
    }

    return 0;
}
Exemplo n.º 23
0
N *TokenizerImpl<N, P>::lookup(const char *begin, const char *end) {
  CharInfo cinfo;
  N *resultNode = 0;
  size_t mblen = 0;
  size_t clen = 0;

  end = static_cast<size_t>(end - begin) >= 65535 ? begin + 65535 : end;
  const char *begin2 = property_.seekToOtherType(begin, end, space_,
                                                 &cinfo, &mblen, &clen);

  for (std::vector<Dictionary *>::const_iterator it = dic_.begin();
       it != dic_.end(); ++it) {
    size_t n = (*it)->commonPrefixSearch(begin2,
                                         static_cast<size_t>(end - begin2),
                                         daresults_.get(), DRESULT_SIZE);

    for (size_t i = 0; i < n; ++i) {
      size_t size  = (*it)->token_size(daresults_[i]);
      const Token *token = (*it)->token(daresults_[i]);
      for (size_t j = 0; j < size; ++j) {
        N *newNode = getNewNode();
        read_node_info(**it, *(token + j), &newNode);
        newNode->token = (Token *)(token + j);
        newNode->length = daresults_[i].length;
        newNode->rlength = begin2 - begin + newNode->length;
        newNode->surface = begin2;
        newNode->stat = MECAB_NOR_NODE;
        newNode->char_type = cinfo.default_type;
        newNode->bnext = resultNode;
        resultNode = newNode;
      }
    }
  }

  if (resultNode && !cinfo.invoke)  return resultNode;

  const char *begin3 = begin2 + mblen;
  const char *group_begin3 = 0;

  if (begin3 > end) {
    ADDUNKNWON;
    return resultNode;
  }

  if (cinfo.group) {
    const char *tmp = begin3;
    CharInfo fail;
    begin3 = property_.seekToOtherType(begin3, end, cinfo,
                                       &fail, &mblen, &clen);
    if (clen <= max_grouping_size_) ADDUNKNWON;
    group_begin3 = begin3;
    begin3 = tmp;
  }

  for (size_t i = 1; i <= cinfo.length; ++i) {
    if (begin3 > end) break;
    if (begin3 == group_begin3) continue;
    clen = i;
    ADDUNKNWON;
    if (!cinfo.isKindOf(property_.getCharInfo(begin3, end, &mblen))) break;
    begin3 += mblen;
  }

  if (!resultNode) { ADDUNKNWON; }

  return resultNode;
}
Exemplo n.º 24
0
 void insert(int key)
 {
     INode *temp = getNewNode(key);
     root = meld_(root, temp);
     ++size_;
 }