예제 #1
0
파일: main.c 프로젝트: schod005/ClassWork
int main(){

	srand(time(0));
	//Creating memory managers
	mm_t *MM = malloc(sizeof(mm_t));
	mm_init(MM,1500,sizeof(node));
	
	mm_t *MM2 = malloc(sizeof(mm_t));
	mm_init(MM2,3,sizeof(dl_list));
	
	//Creating Lists
    dl_list *dl_1 = mm_get(MM2);
    dl_list *dl_2 = mm_get(MM2);
    dl_list *dl_3 = mm_get(MM2);
    
    dl_list_init(dl_1);
    dl_list_init(dl_2);
    dl_list_init(dl_3);
	
	int i;
	for(i = 0; i<500; i++)
		insert_item(dl_1,i,MM);
	
	print_list(dl_1);
	
	for(i = 0; i<500; i++)
		insert_item(dl_2,rand()%500,MM);

	print_list(dl_2);
	
	for(i = 0; i<500; i++)
		insert_item(dl_3,get_element(dl_1,i)+get_element(dl_2,i),MM);
		
	print_list(dl_3);
	
	//Deleting items from list 1
	for(i = 0; i<100; i++)
		delete_item(dl_1,get_element(dl_3,i),MM);
	
	print_list(dl_1);
	
	//Joining lists
	join_lists(dl_2,dl_1);
	join_lists(dl_3,dl_2);
	
	print_list(dl_3);
	
	empty_list(dl_3,MM);
	
	//Deallocating and freeing
	mm_put(MM,dl_1);
	mm_put(MM,dl_2);
	mm_put(MM,dl_3);
	free(MM);
	free(MM2);

    return 0;
}
예제 #2
0
int Redirect_List(const char* path, void* buffer, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info* file_info) {
    const char* userPath = UserDir();
    List* L;
    if(userPath == NULL) {
        L = ListFiles(rootDir, path);
    } else {
        List* lists[3];
        lists[0] = ListFiles(userPath, path);
        lists[1] = ListFiles(rootDir, path);
        lists[2] = NULL;
        free((void*)userPath);
        L = join_lists(lists);
    }
    for (int i=0; i<L->length; i++) {
        struct stat st;
        memset(&st, 0, sizeof(st));
        if(stat(L->str[i], &st) == -1) {
            List_free(L);
            return -errno;
        }
        const char* name = last_term(L->str[i]);
        int result = filler(buffer, name, &st, 0);
        free((void*)name);
        if(result != 0) break;
    }
    List_free(L);
    return 0;
}
예제 #3
0
//
// Listing directories
//
List* ListFiles(const char* base, const char* path) {
    List* Packages = ls(base);
    List* SubDirs[Packages->length+1];
    SubDirs[Packages->length] = NULL;
    for(int i=0; i<Packages->length; i++) {
        const char* array[5] = {base, Packages->str[i], "/", path, NULL};
        const char* subPath = join(array);
        SubDirs[i] = ls_fullpath(subPath);
        free((void*)subPath);
    }
    free((void*)Packages);
    return join_lists(SubDirs);
}
예제 #4
0
파일: main.c 프로젝트: THook/Repo
int		main(void)
{
	int		i;

	i = NBR_PHILO;
	while (i--)
	{
		if (create_fork())
			return (1);
		if (create_philo())
			return (1);
	}
	join_lists();
	fill_o_phils();
	// test id mutex
//	thread_init();
	return (0);
}
예제 #5
0
파일: lk-tree.c 프로젝트: jpcoles/jcode
pTree *tree_remove(struct pqNode *p, pTree *head)
{
    _DA_ fprintf(err, "remove() [id=%i]\n", ID(p));

    /**/ assert (p->node != NULL);
    /**/ assert (p->node->cell.list != NULL);

    pTree *node = p->node;
    struct pqNode *list = node->cell.list;
    struct pqNode *item, *temp;

    /*========================================================================
     * Find the particle in the list. item will point to the correct place on 
     * exit. Notice that there is no check for loop termination other than the 
     * assert. It is a serious error if the particle is not in the list.
     *======================================================================*/
    for (item = temp = list; item != p; temp = item, item = item->neighbor)
        assert(item != NULL);

    if (item == list) node->cell.list = list->neighbor; /* first item in list */
    else              temp->neighbor  = item->neighbor;

    node->cell.count--;                 /**/ assert(node->cell.count >= 0);

#if 0
    for (; node != NULL; node = node->pParent)
    {
        node->cell.fMass -= MASS(p);    /**/ assert(node->cell.fMass >= -1e-3);
    }
#endif

    node = p->node;

    pTree *parent = node->pParent;

    /*========================================================================
     * If we are not at the root node then examine the sibling to see if we
     * can merge the children it back into the parent.
     *======================================================================*/
    if (parent != NULL)
    {
        /**/ assert(parent->cell.count == 0);
        /**/ assert(HAS_CHILDREN(parent));

        pTree *sibling = (parent->pLeft == node) ? parent->pRight : parent->pLeft;

        /* node doesn't have children because p is in node */ assert(NO_CHILDREN(node));   

        if (NO_CHILDREN(sibling)) 
        {
            if (node->cell.count + sibling->cell.count <= MAX_PIC)
            {
                _DA_ fprintf(err, "Merging children [id=%i]\n", ID(p));

                //parent->cell.fMass = sibling->cell.fMass + node->cell.fMass;
                parent->cell.count = sibling->cell.count + node->cell.count;
                parent->cell.list  = join_lists(sibling->cell.list, node->cell.list);

                int c=0;
                for (temp = parent->cell.list; temp != NULL; temp = temp->neighbor)
                {
                    temp->node = parent;
                    c++;
                }

                /**/ assert(c == node->cell.count + sibling->cell.count);

                parent->pLeft      = NULL;
                parent->pRight     = NULL;

                if (head == node) head = parent;

                free_node(sibling); sibling = NULL;
                free_node(node);    node = NULL;
            }
        }
    }

    p->node = NULL;

    free(item); 

    return head;
}