Пример #1
0
int main(
    int argc,
    char **argv)
{
    olRoot root;
    olNode node;
    uint32 xNode;

    utStart();
    utInitLogFile("ordered_benchmark.log");
    olDatabaseStart();
    root = olRootAlloc();
    if(argc != 1) {
        utExit("Usage: benchmark");
    }
    for(xNode = 0; xNode < NUM_NODES; xNode++) {
        nodeCreate(root, xNode);
    }
    for(xNode = NUM_NODES; xNode < NUM_NODES << 1; xNode++) {
        nodeCreate(root, xNode);
        node = olRootGetFirstNode(root);
        olRootRemoveNode(root, node);
        olNodeFree(node);
    }
    olVerifyOrderedList(root);
    olReportStats(root);
    olSafeForeachRootNode(root, node) {
        olRootRemoveNode(root, node);
        olNodeFree(node);
    } olEndSafeRootNode;
Пример #2
0
int main() {
	Node head = nodeCreate(10);

	printf("2. The list and the linked list is now:\n");
	int array[] = {9,8,7,6,5,4,3,2,1};

	for(int i = 0; i < 9; i++) {
		head = listAppend(head, array[i]);
	}

	Node item = head;
	while(item->next != NULL) {
		printf("%d ", item->num);
		item = item->next;
	}
	printf("%d\n\n\n\n", item->num);

	head = partitionList(head, 9);

	item = head;
	while(item->next != NULL) {
		printf("%d ", item->num);
		item = item->next;
	}
	printf("%d\n\n\n\n", item->num);	

	return 0;
}
Пример #3
0
// loadFile, load input file into a stack
stack * loadFile(char *Filename, int * n)
{ 
  char split;
  double width, height;
  int success;
  FILE *fptr = fopen(Filename, "r");

  if(!fptr || feof(fptr))
  {
    printf("File loading failed: File does not exist or is empty.\n");
    return NULL;
  }

  stack * stackMem = NULL;
  success = fscanf(fptr, "%lf %c %lf %c", &width, &split, &height, &split);
  if(success){};
  node * leaf;

while(fscanf(fptr, "%c", &split) != EOF)
{
  if (split=='(')
  {
    success = fscanf(fptr, "%lf %c %lf %c", &width, &split, &height, &split);
    leaf = nodeCreate(width,height,'-',*n);
    stackMem = StackPush(stackMem, leaf);
    (*n)++;
  }
  else if (split=='H')
  {
     leaf = nodeCreate(0,0,split,*n);
     stackMem = StackPush(stackMem, leaf);
     (*n)++;
  }
  else if (split=='V')
  {
    leaf = nodeCreate(0,0,split,*n);
    stackMem = StackPush(stackMem, leaf);
    (*n)++;
  }
else
  printf("\n");
}
fclose(fptr);
return stackMem;
}
Пример #4
0
Node listAppend(Node head, int number) {  //2.向list的尾巴增加一个node
	Node node = nodeCreate(number);
	Node item = head;
	while(item->next != NULL) {
		item = item->next;
	}
	item->next = node;
	return head;
}
Пример #5
0
int main() {
	Node head1 = nodeCreate(3);
	Node head2 = nodeCreate(3);

	int array1[] = {8,7,8,9,2};
	for(int i = 0; i < 2; i++) {
		head1 = listAppend(head1, array1[i]);
	}
	int array2[] = {4,5,3};
	for(int i = 0; i < 2; i++) {
		head2 = listAppend(head2, array2[i]);
	}

	printf("1.1 list 1 and the linked list is now:\n");

	Node item = head1;
	while(item->next != NULL) {
		printf("%d ", item->num);
		item = item->next;
	}
	printf("%d\n\n\n\n", item->num);

	printf("1.2 list 2 and the linked list is now:\n");

	item = head2;
	while(item->next != NULL) {
		printf("%d ", item->num);
		item = item->next;
	}
	printf("%d\n\n\n\n", item->num);

	Node head = addTwoLists(head1, head2);

	item = head;
	while(item->next != NULL) {
		printf("%d ", item->num);
		item = item->next;
	}
	printf("%d\n\n\n\n", item->num);

	return 0;
}
Пример #6
0
int commandExecuterNewEntity(CommandExecuter commandExecuter,Command command){
	CommandExecuterInternal* internal=(CommandExecuterInternal*)commandExecuter;
	Node node;
        StringHashMap attributesMap=commandGetAttributes(command,ATTRIBUTES);
        int lock=commandGetInt(command,LOCK)==TRUE?TRUE:FALSE;
	int result= nodeCreate(internal->registry,commandGetInt(command,ENTITY_ID),commandGetInt(command,SCHEMA_ID),lock,&node,internal->sessionMetaData->id);
        if(result==VALID){
            stringHashmapPutAll(node->attributes,attributesMap);
        }
        stringHashmapFree(attributesMap);
        return result;
}
Пример #7
0
/*------------*/
void treeCreate(int npoin,double x[],double y[],double rad)
{
  int i,j;
  double xfind;
  double yfind;
  double rfind2;
  node* inode;

  inode = nodeCreate(x[0],y[0]);
  mytree.root = inode;
  id = id + 1;

  /* put remaining points into tree */
  for(i=1;i<npoin;i++)
    {
      inode = nodeCreate(x[i],y[i]);

      nodeInsert(mytree.root,inode);
      id = id + 1;
    }
	
  /* search for a point */
  xfind = 0.34;
  yfind = 0.1;
  node* nget = NULL;
  nodeGet(mytree.root,&nget,xfind,yfind);

  if(nget != NULL){

    xfind = nget->x;
    yfind = nget->y;
    rfind2 = nget->norm2;
  }
  else{
    rfind2 = xfind*xfind + yfind*yfind;
  }

  nodeSeperation(mytree.root,xfind,yfind,rfind2,rad);
}
Пример #8
0
// buildTree, build tree from stack
void buildTree(stack * head, node * root, node ** topHead, int n)
{
  if(head==NULL || root == NULL)
  {
    printf("Error, Tree is NULL\n");
    return;
  }
  while(head)
  {
    root -> left = nodeCreate(NODE->width, NODE->height, NODE->split, NODE->index-1);
    root = root -> left;
    head = head->next;
  }
}
Пример #9
0
int main() {
	Node head = nodeCreate(1);
	printf("1. head is %d\n\n\n\n", head->num);

	printf("2. The list and the linked list is now:\n");
	int array[] = {10, 3, 10, 7, 2, 11, 5, 9, 11, 6, 0, 6, 11, 6};

	for(int i = 0; i < 9; i++) {
		head = listAppend(head, array[i]);
	}

	Node item = head;
	while(item->next != NULL) {
		printf("%d ", item->num);
		item = item->next;
	}
	printf("%d\n\n\n\n", item->num);

	printf("3. Now we are testing the nodDel() function.\n");
	Node target = listSearch(head, 1);
	head = nodeDel(head, target);

	printf("4.\n");

	// printf("3. Now we are testing the delDups() function.\n");
	// head = delDups(head);
	item = head;
	if(head == NULL)
	{
		printf("The list is empty");
	}
	else
	{
		while(item->next != NULL) {
			printf("%d ", item->num);
			item = item->next;
		}
		printf("%d\n\n\n\n", item->num);		
	}

	return 0;
}
Пример #10
0
List listCreate(CopyListElement copyElement, FreeListElement freeElement) {
	if (!copyElement || !freeElement) {
		return NULL;
	}

	List ptr = malloc(sizeof(struct List_t));
	if (!ptr) {
		return NULL;
	}

	ptr->head = nodeCreate(NULL, NULL);
	if (!ptr->head) {
		free(ptr);
		return NULL;
	}
	ptr->current = NULL;
	ptr->size = 0;
	ptr->copyElement = copyElement;
	ptr->freeElement = freeElement;
	return ptr;
}
Пример #11
0
int main() {
    Node head = nodeCreate(1);
    printf("1. head is %d\n\n\n\n", head->num);

    printf("2. The list and the linked list is now:\n");
    int array[] = {4, 3, 2, 7, 2, 6, 5, 9, 5, 6, 0, 6, 11, 6};

    for(int i = 0; i < 14; i++) {
        head = listAppend(head, array[i]);
    }

    Node item = head;
    while(item->next != NULL) {
        printf("%d ", item->num);
        item = item->next;
    }
    printf("%d\n\n\n\n", item->num);

    printf("3. Now we are testing listSort() function.\n");
    Node sorted;
    sorted = listSort(head);
    printf("The list after sorting is:");
    item = sorted;
    while(item->next != NULL) {
        printf("%d ", item->num);
        item = item->next;
    }
    printf("%d\n\n\n\n", item->num);

    printf("4. Now we are testing deleting the duplicated element.\n");
    Node headFin = removeDup(sorted);
    item = headFin;
    while(item->next != NULL) {
        printf("%d ", item->num);
        item = item->next;
    }
    printf("%d\n", item->num);

    return 0;
}
Пример #12
0
int main() {
	Node head = nodeCreate(1);
	printf("1. head is %d\n\n\n\n", head->num);

	printf("2. The list and the linked list is now:\n");
	int array[] = {10, 3, 10, 7, 2, 9, 5, 9, 11, 6, 0, 6, 11, 6};

	for(int i = 0; i < 9; i++) {
		head = listAppend(head, array[i]);
	}

	Node item = head;
	while(item->next != NULL) {
		printf("%d ", item->num);
		item = item->next;
	}
	printf("%d\n\n\n\n", item->num);

	Node target = listSearch(head, 11);

	_Bool isDel = NodeDelWithNoReturnValue(target);
	if(isDel == true) 
	{
		item = head;
		while(item->next != NULL) {
			printf("%d ", item->num);
			item = item->next;
		}
		printf("%d\n\n\n\n", item->num);		
	}
	else
	{
		printf("can not delete\n");
	}

	return 0;
}
Пример #13
0
void fileHelperLoad(FileHelper fileHelper) {
    FileHelperInternal *m = (FileHelperInternal *) fileHelper;
    fileHelperCheckCreate(m->filePath);
    int sizeOfInt = sizeof(int);
    struct direct **schemasIds = {0};
    struct direct *schenaId;
    int size = scandir(m->filePath, &schemasIds, 0, alphasort);
    // loop all schemas
    int i;
    for (i = 0; i < size; i++) {
        schenaId = (struct direct *) schemasIds[i];
        char *schemaIdString = schenaId->d_name;
        int schemaId = atoi(schemaIdString);
        if (schemaId != 0) {
            printf("schema %s\n", schenaId->d_name);
            struct direct **pagesIds = {0};
            struct direct *pageStruct;
            char endOdString = '\0';
            int pageDirLength = strlen(m->filePath);
            int schemaIdStringLength = strlen(schemaIdString);
            char slesh = '/';
            char *pageDir = (char *) memoryAlloc(pageDirLength + 1 + schemaIdStringLength + 1);
            memcpy(pageDir, m->filePath, pageDirLength);
            memcpy(pageDir + pageDirLength, &slesh, 1);
            memcpy(pageDir + pageDirLength + 1, schemaIdString, schemaIdStringLength);
            memcpy(pageDir + pageDirLength + 1 + schemaIdStringLength, &endOdString, 1);


//			cleanBuffer(pageDir);
//			strcat(pageDir,m->filePath);
//			strcat(pageDir,"/");
//			strcat(pageDir,schemaIdString);
            HashMap childrenRelations = hashmapCreate(SMALL_CONTAINER_SIZE);
            Registry registry = registryCreate();
            hashmapPut(m->registryMap, schemaId, registry);
            PageManager pageManager = pageManagerCreate(schemaId, pageDir);
            hashmapPut(m->managers, schemaId, pageManager);
            int size = scandir(pageDir, &pagesIds, 0, alphasort);
            int h;
            //loop pages
            for (h = 0; h < size; h++) {
                //scandir (pageDir, &pagesIds, 0, alphasort);
                pageStruct = (struct direct *) pagesIds[h];
                char *pageString = pageStruct->d_name;
                int pageId = atoi(pageString);
                if (pageId != 0) {
                    printf("page %s\n", pageStruct->d_name);
                    // create file path.

                    //int i=0;
                    int pageDirLength = strlen(pageDir);
                    int pageStringLength = strlen(pageString);
                    char slesh = '/';
                    char *filePath = (char *) memoryAlloc(pageDirLength + 1 + pageStringLength + 1);
                    memcpy(filePath, pageDir, pageDirLength);
                    memcpy(filePath + pageDirLength, &slesh, 1);
                    memcpy(filePath + pageDirLength + 1, pageString, pageStringLength);
                    memcpy(filePath + pageDirLength + 1 + pageStringLength, &endOdString, 1);
                    FILE *fp;
                    long len;
                    // Create pointer to file.
                    fp = fopen(filePath, "rb");
                    if (fp == NULL) {
                        printf("couldn't open the properties file");
                    }
                    fseek(fp, 0, SEEK_END);                // Go to end
                    len = ftell(fp);                        // Get position at end (length)
                    // Read data to buffer
                    char *buffer = memoryAlloc(sizeof(char) * len); // Create buffer
                    char *pointerToFreeBuffer = buffer;
                    fseek(fp, 0, SEEK_SET);                // Go to the beginning.
                    int result = fread(buffer, len, 1, fp);                // Read into buffer
                    if (result < 0) {
                        printf("Fail to read file : %s", buffer);
                    }
                    fclose(fp);
                    int order = 0;
                    long index = 0;
                    long step = 0;
                    while (index < len) {
                        char *start = buffer;
                        int id;
                        int schemaId;
                        int numberOfAttributes;
                        int childrenSize;
                        int attributeSize;
                        memcpy(&schemaId, buffer + SIZE_OF_INT * 0, SIZE_OF_INT);
                        memcpy(&id, buffer + SIZE_OF_INT * 1, SIZE_OF_INT);
                        memcpy(&numberOfAttributes, buffer + SIZE_OF_INT * 2, SIZE_OF_INT);
                        buffer += SIZE_OF_INT * 3;
                        Node node;
                        nodeCreate(registry, id, schemaId, FALSE, &node);
                        int h;
                        for (h = 0; h < numberOfAttributes; h++) {
                            memcpy(&attributeSize, buffer, SIZE_OF_INT);
                            Attribute attribute = attributeDeserializeLocal(buffer);
                            buffer += attributeSize;
                            stringHashmapPut(node->attributes, attribute->name, attribute->nameLength, attribute);
                        }
                        memcpy(&childrenSize, buffer, SIZE_OF_INT);
                        Array children = arrayCreate(childrenSize);
                        hashmapPut(childrenRelations, id, children);
                        int i;
                        buffer += SIZE_OF_INT;
                        int childrenIdBuffer;
                        for (i = 0; i < childrenSize; i++) {
                            memcpy(&childrenIdBuffer, buffer + SIZE_OF_INT, SIZE_OF_INT);
                            void *bufferElement = memoryAlloc(childrenIdBuffer + SIZE_OF_INT * 2);
                            memcpy(bufferElement, buffer, SIZE_OF_INT * 2 + childrenIdBuffer);
                            arrayInsertObject(children, bufferElement);
                            buffer += SIZE_OF_INT * 2 + childrenIdBuffer;
                        }
                        step = buffer - start;
                        index += step;
                        pageManagerRegister(pageManager, pageId, id, index - step, index, order, filePath);
                        order++;
                    }
                    // Free the file buffer
                    memoryFree(pointerToFreeBuffer);
                }
            }
            if (size > 0) {
                while (size) {
                    size = size - 1;
                    free(pagesIds[size]);
                }
                free(pagesIds);
            }
            hashmapIterate(childrenRelations, &updateChildren, registry);
            hashmapFree(childrenRelations);
        }
    }
    if (size > 0) {
        while (size) {
            size = size - 1;
            free(schemasIds[size]);
        }
        free(schemasIds);
    }

}
Пример #14
0
int validationManagerValidateOnCoreExecuteInternalRecurcive(ValidationManager validationManager,ArrayList commands,int administrator,int dept){
    ValidationManagerStruct* internal=(ValidationManagerStruct*)validationManager;
                if(commands!=NULL&&dept<arrayListSize(commands)){
        Command command=arrayListGetValueAt(commands,dept);
        int coreManagerId=commandGetInt(command,CORE_MANAGER_ID);
	int sessionId=commandGetInt(command,SESSION_ID);
	int transaction=commandGetInt(command,TRANSACTION);
        int schimaId=commandGetInt(command,SCHEMA_ID);
        int type=commandGetInt(command,COMMAND_TYPE);
        int version=commandGetInt(command,VERSION);
        int entityId=commandGetInt(command,ENTITY_ID);
        
        VALIDATE_TRANSACTION(transaction);
	VALIDATE_CORE_MANAGER_ID(coreManagerId);
	VALIDATE_SESSION_ID(sessionId);
	if(IS_CREATE_NEW_ENTITY(type)){                
                int lock=commandGetInt(command,LOCK);
                StringHashMap newAttributesMap=commandGetAttributes(command,ATTRIBUTES);
                VALIDATE(registryValidateNodeCreate(internal->registry,entityId));
                Node node;
                nodeCreate(internal->registry,entityId,schimaId,lock,&node);
                stringHashmapPutAll(node->attributes,newAttributesMap);
                stringHashmapFree(newAttributesMap);
                int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1);
                if( VALID!= result){
                    registryDeleteNode(internal->registry,node);
                    return result;
                }
        char* buf;
        int length=nodeSerialize(node,&buf);
        commandPush(command,SERIALIZED_NODE,BYTE_ARRAY,buf,length);
        memoryFree(buf);
	}
	if(IS_ADD_CHILD_ENTITY_TO_PARENT_ENTITY(type)){
                char* arcName;
		int childEntityId=commandGetInt(command,ENTITY_CHILD_ID);
                int arcNameLenght=commandGetString(command,ARC_NAME,&arcName);
                Node parent;
                registryGetNode(internal->registry,entityId,&parent);
                Node child;
                registryGetNode(internal->registry,childEntityId,&child);
                VALIDATE(registryValidateAddChild(parent,child,arcName,arcNameLenght,sessionId));
                registryAddChild(internal->registry,parent,child,arcName,arcNameLenght);
                int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1);
                if( VALID!= result){
                    registryRemoveChild(internal->registry,parent,arcName,arcNameLenght);
                    return result;
                }
                char* buf;
                int length=nodeSerialize(parent,&buf);
                commandPush(command,SERIALIZED_NODE,BYTE_ARRAY,buf,length);
                memoryFree(buf);
	}
	if(IS_REMOVE_CHILD_ENTITY_FROM_PARENT_ENTITY(type)){
                char* arcName;
		int childEntityId=commandGetInt(command,ENTITY_CHILD_ID);
                int arcNameLenght=commandGetString(command,ARC_NAME,&arcName);
		Node parent;
                registryGetNode(internal->registry,entityId,&parent);
                Node child;
                registryGetNode(internal->registry,childEntityId,&child);
                VALIDATE(registryValidateRemoveChild(parent,arcName,arcNameLenght,sessionId));
                registryRemoveChild(internal->registry,parent,arcName,arcNameLenght);
                int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1);
                if( VALID!= result){
                    registryAddChild(internal->registry,parent,child,arcName,arcNameLenght);
                    return result;
                }
        char* buf;
        int length=nodeSerialize(parent,&buf);
        commandPush(command,SERIALIZED_NODE,BYTE_ARRAY,buf,length);
        memoryFree(buf);
	}
	if(IS_LOCK_ENTITY(type)){
                int lock=commandGetInt(command,LOCK);
                int forceLock=commandGetInt(command,FORCE_LOCK);
                Node node;
                registryGetNode(internal->registry,entityId,&node);
		VALIDATE(registryValidateUpdateLock(node,lock,sessionId,forceLock,administrator));
                registryUpdateLock(internal->registry,node,lock,sessionId);
                int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1);
                if( VALID!= result){
                    int revertedLock=lock==TRUE?FALSE:TRUE;                    		
                    registryUpdateLock(internal->registry,node,revertedLock,sessionId);
                    return result;
                }
	}
        if(IS_DELETE_ENTITY(type)){
                int lock=commandGetInt(command,LOCK);
                Node node;
                VALIDATE(registryGetNode(internal->registry,entityId,&node));
		VALIDATE(registryValidateDeleteNode(node,sessionId));
		registryDeleteNode(internal->registry,node);
                int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1);
                if( VALID!= result){
                    nodeCreate(internal->registry,entityId,schimaId,lock,&node);                    
                    return result;
                }                
        }
        if(IS_ADD_ATTRIBUTE(type)){
                StringHashMap newAttributesMap=commandGetAttributes(command,ATTRIBUTES);
                Node node;
                registryGetNode(internal->registry,entityId,&node);
                VALIDATE(registryValidateUpdate(node,sessionId));
                Array array;
                stringHashmapToArray(newAttributesMap,&array);
                int lenght=arrayGetLength(array);
                int i;
                StringHashMap toRemove = stringHashmapCreate(SMALL_CONTAINER_SIZE);                
                for(i=0;i<lenght;i++){
                    Attribute newAttribute=(Attribute)arrayGetObject(array,i);
                    Attribute oldAttribute;
                    stringHashmapGet(node->attributes,newAttribute->name,newAttribute->nameLength,(Object) &oldAttribute);
                    if(oldAttribute!=NULL){
                        stringHashmapPut(toRemove,newAttribute->name,newAttribute->nameLength,oldAttribute);
                        stringHashmapRemove(node->attributes,newAttribute->name,newAttribute->nameLength);
                    }
                    stringHashmapPut(node->attributes,newAttribute->name,newAttribute->nameLength,(Object)newAttribute);
                }
                arrayFree(array);
                int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1);                
                if(result!=VALID){
                    stringHashmapToArray(newAttributesMap,&array);
                    lenght=arrayGetLength(array);                    
                    for(i=0;i<lenght;i++){
                        Attribute newAttribute=(Attribute)arrayGetObject(array,i);                       
                        stringHashmapRemove(node->attributes,newAttribute->name,newAttribute->nameLength);
                        attributeFree(newAttribute,TRUE);                  
                    }                 
                    stringHashmapPutAll(node->attributes,toRemove);  
                    arrayFree(array);
                    stringHashmapFree(toRemove);
                }else{
                    stringHashmapToArray(toRemove,&array);
                    lenght=arrayGetLength(array);
                    for(i=0;i<lenght;i++){
                        Attribute oldAttribute=(Attribute)arrayGetObject(array,i);
                        stringHashmapRemove(toRemove,oldAttribute->name,oldAttribute->nameLength);
                        attributeFree(oldAttribute,TRUE);                                           
                    }
                    arrayFree(array);
                    stringHashmapFree(toRemove);                    
                }
                stringHashmapFree(newAttributesMap);     
                char* buf;
                int length=nodeSerialize(node,&buf);
                commandPush(command,SERIALIZED_NODE,BYTE_ARRAY,buf,length);
                memoryFree(buf);
        }
        if(IS_REMOVE_ATTRIBUTE(type)){
                StringHashMap toRemoveAttributeMap=commandGetAttributes(command,ATTRIBUTES);
                Node node;
                registryGetNode(internal->registry,entityId,&node);
                VALIDATE(registryValidateUpdate(node,sessionId));
                Array array;
                stringHashmapToArray(toRemoveAttributeMap,&array);
                int lenght=arrayGetLength(array);
                int i;
                StringHashMap oldAttributes = stringHashmapCreate(SMALL_CONTAINER_SIZE);
                for(i=0;i<lenght;i++){
                    Attribute toRemoveAttribute=(Attribute)arrayGetObject(array,i);
                    Attribute oldAttribute;
                    stringHashmapGet(node->attributes,toRemoveAttribute->name,toRemoveAttribute->nameLength,(Object) &oldAttribute);
                    if(oldAttribute!=NULL){
                        stringHashmapPut(oldAttributes,toRemoveAttribute->name,toRemoveAttribute->nameLength,(Object)oldAttribute);
                        stringHashmapRemove(node->attributes,toRemoveAttribute->name,toRemoveAttribute->nameLength);
                    }                    
                }   
                 arrayFree(array);
                int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1);                
                if(result!=VALID){
                    stringHashmapToArray(oldAttributes,&array);
                    lenght=arrayGetLength(array);                    
                    for(i=0;i<lenght;i++){
                        Attribute oldAttribute=(Attribute)arrayGetObject(array,i);                       
                        stringHashmapPut(node->attributes,oldAttribute->name,oldAttribute->nameLength,(Object)oldAttribute);            
                    }    
                     arrayFree(array);
                    stringHashmapToArray(toRemoveAttributeMap,&array);
                    lenght=arrayGetLength(array);                    
                    for(i=0;i<lenght;i++){
                        Attribute toRemoveAttribute=(Attribute)arrayGetObject(array,i);                       
                        stringHashmapPut(toRemoveAttributeMap,toRemoveAttribute->name,toRemoveAttribute->nameLength,(Object)toRemoveAttribute);            
                        attributeFree(toRemoveAttribute,TRUE);                        
                    }
                     arrayFree(array);
                    stringHashmapFree(toRemoveAttributeMap);                    
                }else{
                    stringHashmapToArray(oldAttributes,&array);
                    lenght=arrayGetLength(array);                    
                    for(i=0;i<lenght;i++){
                        Attribute oldAttribute=(Attribute)arrayGetObject(array,i);                       
                        stringHashmapRemove(oldAttributes,oldAttribute->name,oldAttribute->nameLength);            
                        attributeFree(oldAttribute,TRUE);                        
                    }   
                     arrayFree(array);
                    stringHashmapToArray(toRemoveAttributeMap,&array);
                    lenght=arrayGetLength(array);
                    for(i=0;i<lenght;i++){
                        Attribute toAddAttribute=(Attribute)arrayGetObject(array,i);                       
                        stringHashmapPut(toRemoveAttributeMap,toAddAttribute->name,toAddAttribute->nameLength,(Object)toAddAttribute);            
                        attributeFree(toAddAttribute,TRUE);                        
                    }
                     arrayFree(array);
                    stringHashmapFree(toRemoveAttributeMap);                    
                }        
        char* buf;
        int length=nodeSerialize(node,&buf);
        commandPush(command,SERIALIZED_NODE,BYTE_ARRAY,buf,length);
        memoryFree(buf);
        }
        if(IS_UPDATE_ENTITY(type)){
                StringHashMap newAttributesMap=commandGetAttributes(command,ATTRIBUTES);
                Node node;
                registryGetNode(internal->registry,entityId,&node);
                StringHashMap oldAttributesMap=stringHashmapCreate(SMALL_CONTAINER_SIZE);                
                stringHashmapPutAll(oldAttributesMap,node->attributes);
                Array array;
                stringHashmapToArray(node->attributes,&array);
                int lenght=arrayGetLength(array);
                int i;                
                for(i=0;i<lenght;i++){
                    Attribute toRemoveAttribute=(Attribute)arrayGetObject(array,i);                                        
                    stringHashmapRemove(node->attributes,toRemoveAttribute->name,toRemoveAttribute->nameLength);                    
                }    
                stringHashmapPutAll(node->attributes,newAttributesMap);
                int result=validationManagerValidateOnCoreExecuteInternalRecurcive(validationManager,commands,administrator,dept+1);                
                if(result!=VALID){
                    stringHashmapToArray(node->attributes,&array);
                    lenght=arrayGetLength(array);
                    for(i=0;i<lenght;i++){
                        Attribute toRemoveAttribute=(Attribute)arrayGetObject(array,i);                                            
                        stringHashmapRemove(node->attributes,toRemoveAttribute->name,toRemoveAttribute->nameLength);                        
                        attributeFree(toRemoveAttribute,TRUE);
                    }
                    stringHashmapPutAll(node->attributes,oldAttributesMap);
                    stringHashmapFree(newAttributesMap);
                    stringHashmapFree(oldAttributesMap);
                }else{
                    stringHashmapToArray(oldAttributesMap,&array);
                    lenght=arrayGetLength(array);
                    for(i=0;i<lenght;i++){
                        Attribute oldAttribute=(Attribute)arrayGetObject(array,i);                       
                        stringHashmapRemove(oldAttributesMap,oldAttribute->name,oldAttribute->nameLength);            
                        attributeFree(oldAttribute,TRUE);                        
                    }                 
                    stringHashmapFree(oldAttributesMap);
                    stringHashmapFree(newAttributesMap);
                }
        char* buf;
        int length=nodeSerialize(node,&buf);
        commandPush(command,SERIALIZED_NODE,BYTE_ARRAY,buf,length);
        memoryFree(buf);
        }
        
    }
    return VALID;
}
Пример #15
0
int main(int argc, char * * argv)
{
if (argc != 3)
{
  printf("usage: ./proj4 input output\n");
  return EXIT_FAILURE;
}

int index = 0;
double x = 0, y=0; 

// Build binary tree
stack * root = loadFile(argv[1], &index);
node * head = nodeCreate(root->stackNode->width, root->stackNode->height, root->stackNode->split, root->stackNode->index-1); //= buildTree(root);
root = StackPop(root);
buildTree(root, head, &head, index);
node * tree = NULL;
tree = nodeArrange(tree, &head);

// Packing
clock_t timeStart = clock();
assignCutline(tree);
setCoord(tree);
clock_t timeEnd = clock();
double packTime = (double) (timeEnd - timeStart) / CLOCKS_PER_SEC;
searchNode(tree, &x, &y, 1);
//printPostorderFull(tree);

//Reset output file and save output
FILE * fptr = fopen(argv[2], "w");
saveTree(tree, argv[2]);

// Screen dump
printf("Preorder: ");
printPreorder(tree);
printf("\n\nInorder: ");
printInorder(tree);
printf("\n\nPostorder: ");
printPostorder(tree);
printf("\n\nWidth: %le", tree->width);
printf("\nHeight: %le", tree->height);
printf("\n\nX-coordinate: %le", x);
printf("\nY-coordinate: %le", y); 
printf("\n");

// Rerooting
box * minBox = malloc(sizeof(box));
minBox->width = tree->width;
minBox->height = tree->height;

timeStart = clock();
// ------------------------------------ to run cases without rerooting, comment out the following lines
while (tree->right->split!='-')
{
tree = reroot(tree, minBox);
decideMin(minBox, tree);
//printPostorderFull(tree);
}
// ------------------------------------
timeEnd = clock();
double rootTime = (double) (timeEnd - timeStart) / CLOCKS_PER_SEC;


printf("\nElapsed Time: %le", packTime);
printf("\n\nBest width: %le", minBox->width);
printf("\nBest height: %le\n", minBox->height);
printf("\nElapsed Time for re-routing: %le\n", rootTime);

// Free stack
while(root!=NULL){
  root = StackPop(root);
}

// Memory management
free(root);
free(minBox);
deleteTree(head);
deleteTree(tree);
fclose(fptr);

return EXIT_SUCCESS;
}