예제 #1
0
파일: dag_node.c 프로젝트: nkremerh/cctools
struct dag_node *dag_node_create(struct dag *d, int linenum)
{
	struct dag_node *n;

	n = malloc(sizeof(struct dag_node));
	memset(n, 0, sizeof(struct dag_node));
	n->d = d;
	n->linenum = linenum;
	n->state = DAG_NODE_STATE_WAITING;
	n->nodeid = d->nodeid_counter++;
	n->variables = hash_table_create(0, 0);

	n->source_files = list_create(0);
	n->target_files = list_create(0);

	n->remote_names = itable_create(0);
	n->remote_names_inv = hash_table_create(0, 0);

	n->descendants = set_create(0);
	n->ancestors = set_create(0);

	n->ancestor_depth = -1;

	n->resources_requested = rmsummary_create(-1);
	n->resources_measured  = NULL;

	n->resource_request = CATEGORY_ALLOCATION_FIRST;

	return n;
}
예제 #2
0
파일: dag.c 프로젝트: badi/cctools
struct dag_node *dag_node_create(struct dag *d, int linenum)
{
	struct dag_node *n;

	n = malloc(sizeof(struct dag_node));
	memset(n, 0, sizeof(struct dag_node));
	n->d = d;
	n->linenum = linenum;
	n->state = DAG_NODE_STATE_WAITING;
	n->nodeid = d->nodeid_counter++;
	n->variables = hash_table_create(0, 0);

	n->source_files = list_create(0);
	n->target_files = list_create(0);

	n->remote_names = itable_create(0);
	n->remote_names_inv = hash_table_create(0, 0);

	n->descendants = set_create(0);
	n->ancestors = set_create(0);

	n->ancestor_depth = -1;

	n->resources = make_rmsummary(-1);

	if(verbose_parsing && d->nodeid_counter % PARSING_RULE_MOD_COUNTER == 0)
	{
		fprintf(stdout, "\rRules parsed: %d", d->nodeid_counter + 1);
		fflush(stdout);
	}

	return n;
}
예제 #3
0
파일: sets.c 프로젝트: jleffler/soq
static void test_ops(void)
{
    Set *s1 = set_create();
    Set *s2 = set_create();
    Set *s3 = set_create();

    if (s1 == 0 || s2 == 0 || s3  == 0)
        err_syserr("Out of memory\n");

    load_set(s1, 1, 3, 4, 6);
    dump_set("S1", s1);

    load_set(s2, 2, 5, 7, 9);
    dump_set("S2", s2);

    set_union(s1, s2, s3);
    dump_set("S1 union S2", s3);

    set_empty(s3);
    set_intersect(s1, s2, s3);
    dump_set("S1 intersect S2", s3);

    set_empty(s3);
    set_difference(s1, s2, s3);
    dump_set("S1 minus S2", s3);

    set_empty(s3);
    set_difference(s2, s1, s3);
    dump_set("S2 minus S1", s3);

    set_destroy(s1);
    set_destroy(s2);
    set_destroy(s3);
}
예제 #4
0
int main(int argc, char *argv[])
{
    int i, size = 100, *x;
    struct set *s, *t, *u;
    
    if (argc > 1)
	size = atoi(argv[1]);
    
    srand(time(NULL));

    s = set_create(size, sizeof(int), cmpint);
    t = set_create(size, sizeof(int), cmpint);
    if (s == NULL || t == NULL){
	printf("Unable to create the test set\n");
	return 1;
    }

    printf("Inserting into first set...\n");
    for (i = 0; i < size; i++){
	int y = rand() % size;

	printf("%d ", y);
	set_insert(s, &y);
    }
    printf("\n\n");

    printf("The set contains:\n");
    for (set_reset(s), x = set_next(s); x != NULL; x = set_next(s)) 
	printf("%d ", *x);
    printf("\n\n");

    printf("Inserting into second set...\n");
    for (i = 0; i < size; i++){
	int y = rand() % size;

	printf("%d ", y);
	set_insert(t, &y);
    }
    printf("\n\n");

    printf("The set contains:\n");
    for (set_reset(t), x = set_next(t); x != NULL; x = set_next(t)) 
	printf("%d ", *x);
    printf("\n\n");

    u = set_union(s, t);
    printf("The union of the two sets is:\n");
    for (set_reset(u), x = set_next(u); x != NULL; x = set_next(u)) 
	printf("%d ", *x);
    printf("\n\n");
    set_destroy(u);

    u = set_diff(s, t);
    printf("The difference of the two sets is:\n");
    for (set_reset(u), x = set_next(u); x != NULL; x = set_next(u)) 
	printf("%d ", *x);
    printf("\n\n");
    
    return 0;
}
예제 #5
0
파일: dag.c 프로젝트: dcbradley/cctools
struct dag_node *dag_node_create(struct dag *d, int linenum)
{
	struct dag_node *n;

	n = malloc(sizeof(struct dag_node));
	memset(n, 0, sizeof(struct dag_node));
	n->d = d;
	n->linenum = linenum;
	n->state = DAG_NODE_STATE_WAITING;
	n->nodeid = d->nodeid_counter++;
	n->variables = hash_table_create(0, 0);

	n->source_files = list_create(0);
	n->target_files = list_create(0);

	n->remote_names = itable_create(0);
	n->remote_names_inv = hash_table_create(0, 0);

	n->descendants = set_create(0);
	n->ancestors = set_create(0);

	n->ancestor_depth = -1;

	return n;
}
예제 #6
0
파일: dag.c 프로젝트: nkremerh/cctools
struct dag *dag_create()
{
	struct dag *d = malloc(sizeof(*d));

	memset(d, 0, sizeof(*d));
	d->nodes = 0;
	d->filename = NULL;
	d->node_table = itable_create(0);
	d->local_job_table = itable_create(0);
	d->remote_job_table = itable_create(0);
	d->files = hash_table_create(0, 0);
	d->inputs = set_create(0);
	d->outputs = set_create(0);
	d->nodeid_counter = 0;
	d->export_vars  = set_create(0);
	d->special_vars = set_create(0);
	d->completed_files = 0;
	d->deleted_files = 0;

	d->categories   = hash_table_create(0, 0);
	d->default_category = makeflow_category_lookup_or_create(d, "default");

	d->allocation_mode = CATEGORY_ALLOCATION_MODE_FIXED;

	/* Add GC_*_LIST to variables table to ensure it is in
	 * global DAG scope. /
	hash_table_insert(d->variables,"GC_PRESERVE_LIST"   , dag_variable_create(NULL, ""));
	hash_table_insert(d->variables,"GC_COLLECT_LIST"  , dag_variable_create(NULL, ""));
	hash_table_insert(d->variables,"MAKEFLOW_INPUTS"   , dag_variable_create(NULL, ""));
	hash_table_insert(d->variables,"MAKEFLOW_OUTPUTS"  , dag_variable_create(NULL, ""));
	*/

	/* Declare special variables */
	set_insert(d->special_vars, "CATEGORY");
	set_insert(d->special_vars, "SYMBOL");          /* Deprecated alias for CATEGORY */
	set_insert(d->special_vars, RESOURCES_CORES);
	set_insert(d->special_vars, RESOURCES_MEMORY);
	set_insert(d->special_vars, RESOURCES_DISK);
	set_insert(d->special_vars, RESOURCES_GPUS);

	/* export all variables related to resources */
	set_insert(d->export_vars, "CATEGORY");
	set_insert(d->export_vars, RESOURCES_CORES);
	set_insert(d->export_vars, RESOURCES_MEMORY);
	set_insert(d->export_vars, RESOURCES_DISK);
	set_insert(d->export_vars, RESOURCES_GPUS);

	memset(d->node_states, 0, sizeof(int) * DAG_NODE_STATE_MAX);
	return d;
}
예제 #7
0
파일: settings.c 프로젝트: vible/rcmbot
/* Creates a new setting with the default value if it doesnt exist */
struct settings* set_default(struct settings *set, char *name, char *value)
{
        if (!set_find(set, name))
                return (set_create(set, name, value));

        return set;
}
예제 #8
0
int
main(int argc, char **argv)
{
	struct set *set;
	const char *str1 = "test1";
	const char *str2 = "test2";
	const char *str3 = "test3";

	set = set_create(badhash, string_key_equals);

	/* Unlike the hash table equivalent of this test, use an extra
	 * string so that the rehash happens at the right time.
	 */
	set_add(set, str1);
	set_add(set, str2);
	set_add(set, str3);
	set_remove(set, str2);
	set_add(set, str3);
	set_remove(set, str3);
	assert(!set_contains(set, str3));

	set_destroy(set, NULL);

	return 0;
}
예제 #9
0
파일: set.c 프로젝트: depp/uniset
struct set *
set_complement(struct set *x)
{
    struct set *z = set_create(x->length + 1);
    struct range *restrict xp = x->r, *xe = x->r + x->length;
    struct range *restrict zp = z->r;
    if (xp == xe) {
        zp->first = 0;
        zp->last = 0x10ffff;
        ++zp;
    } else {
        if (xp->first != 0) {
            zp->first = 0;
            zp->last = xp->first - 1;
            ++zp;
        }
        zp->first = xp->last + 1;
        ++xp;
        while (xp != xe) {
            zp->last = xp->first - 1;
            ++zp;
            zp->first = xp->last + 1;
            ++xp;
        }
        if (zp->first <= 0x10ffff) {
            zp->last = 0x10ffff;
            ++zp;
        }
    }
    z->length = zp - z->r;
    free(x);
    return z;
}
예제 #10
0
파일: bfs.c 프로젝트: wqferr/P-A-T-H
void _solver_bfs_init(solver *s) {
	bfs_data *data = malloc(sizeof(*data));
	data->visited = set_create(sizeof(vec2), &vec2ref_hash, &vec2ref_comp);
	data->queue = list_create(sizeof(vec2));
	data->parent = map_create(
		sizeof(vec2), sizeof(vec2), &vec2ref_hash, &vec2ref_comp);
	solver_set_data(s, data);
}
예제 #11
0
파일: dag.c 프로젝트: badi/cctools
struct dag *dag_create()
{
	struct dag *d = malloc(sizeof(*d));

	if(!d) {
		debug(D_DEBUG, "makeflow: could not allocate new dag : %s\n", strerror(errno));
		return NULL;
	} else {
		memset(d, 0, sizeof(*d));
		d->nodes = 0;
		d->filename = NULL;
		d->node_table = itable_create(0);
		d->local_job_table = itable_create(0);
		d->remote_job_table = itable_create(0);
		d->file_table = hash_table_create(0, 0);
		d->completed_files = hash_table_create(0, 0);
		d->symlinks_created = list_create();
		d->variables = hash_table_create(0, 0);
		d->local_jobs_running = 0;
		d->local_jobs_max = 1;
		d->remote_jobs_running = 0;
		d->remote_jobs_max = MAX_REMOTE_JOBS_DEFAULT;
		d->nodeid_counter = 0;
		d->collect_table = set_create(0);
		d->export_vars  = set_create(0);
		d->special_vars = set_create(0);

		d->task_categories = hash_table_create(0, 0);

		/* Add GC_*_LIST to variables table to ensure it is in
		 * global DAG scope. */
		hash_table_insert(d->variables, GC_COLLECT_LIST,  dag_variable_create(NULL, ""));
		hash_table_insert(d->variables, GC_PRESERVE_LIST, dag_variable_create(NULL, ""));

		/* Declare special variables */
		set_insert(d->special_vars, RESOURCES_CATEGORY);
		set_insert(d->special_vars, RESOURCES_CORES);
		set_insert(d->special_vars, RESOURCES_MEMORY);
		set_insert(d->special_vars, RESOURCES_DISK);
		set_insert(d->special_vars, RESOURCES_GPUS);

		memset(d->node_states, 0, sizeof(int) * DAG_NODE_STATE_MAX);
		return d;
	}
}
예제 #12
0
파일: sets.c 프로젝트: jleffler/soq
static void test_set(void)
{
    Set *set = set_create();
    if (set == 0)
        err_syserr("Out of memory\n");
    load_set(set, 1, 3, 4, 6);
    dump_set("S0", set);
    set_destroy(set);
}
예제 #13
0
파일: set.c 프로젝트: depp/uniset
struct set *
set_range(unsigned int first, unsigned int last)
{
    struct set *s = set_create(1);
    assert(first <= last);
    assert(last <= 0x10ffff);
    s->r[0].first = first;
    s->r[0].last = last;
    s->length = 1;
    return s;
}
예제 #14
0
/* The run footprint of a node is defined as its target size and
 * the size of it inputs. It is the cost needed to run this node. */
void dag_node_footprint_determine_run_footprint(struct dag_node *n)
{
	set_delete(n->footprint->run_files);
	n->footprint->run_files = set_create(0);
	set_insert_list(n->footprint->run_files, n->source_files);
	set_insert_list(n->footprint->run_files, n->target_files);
	set_insert_set(n->footprint->run_files, n->footprint->terminal_files);
	set_insert_set(n->footprint->run_files, n->footprint->coexist_files);

	n->footprint->run_footprint = dag_file_set_size(n->footprint->run_files);
}
예제 #15
0
/*@ 
   set_copy - copy a set

Input arguments:
+ s - The set to be copied

Output arguments:
None

Returns:
A copy of the input set
@*/
struct set *set_copy(const struct set * const s)
{
    struct set *tmp;

    tmp = set_create(s->maxsize, s->elemsize, s->cmp);
    if (tmp == NULL)
	return NULL;

    memcpy(tmp->buf, s->buf, s->size*s->elemsize);
    tmp->size = s->size;

    return tmp;
}
예제 #16
0
파일: set.c 프로젝트: Baguage/cctools
struct set *set_duplicate(struct set *s)
{
	struct set *s2;

	s2 = set_create(0);
	set_first_element(s);
	const void *element;
	while((element = set_next_element(s)))
		set_insert(s2, element);

	return s2;

}
예제 #17
0
파일: dfs.c 프로젝트: arshadansari27/aoa
void main() {
    int i, j, k1, k2, w, count;
    Set *s_visited;
    Graph *g = init_graph(10);
    for(i = 0; i < 10; i++) {
        k1 = (int) rand() % 10;
        k2 = (int) rand() % 10;
        w = (int) rand() % 100 + 1;
        add_edge(g, k1, k2, w);
    }
    graph_display(g);
    s_visited = set_create();
    printf("Depth first traveral\n***********************\n");
    depth_first_traversal(g, 0, s_visited);
}
예제 #18
0
/*
 * Builds a new set with a balanced tree, given a sorted list.
 * Destroys the list before returning the new set.
 */
static set_t *buildset(list_t *list, cmpfunc_t cmpfunc)
{
    set_t *set = set_create(cmpfunc);
    int size = list_size(list);

    if (size > 0) {
        treenode_t *last;
        buildtree(list, size, &(set->first), &(set->root), &last);
        set->size = size;
    }
    list_destroy(list);

	if (DEBUG_CHECKSET)
        checkset(set);
    return set;
}
예제 #19
0
파일: set.c 프로젝트: depp/uniset
struct set *
set_intersect(struct set *x, struct set *y)
{
    struct set *z;
    struct range *restrict xp = x->r, *xe = x->r + x->length;
    struct range *restrict yp = y->r, *ye = y->r + y->length;
    struct range *tp, *te, *restrict zp;
    unsigned int limit;
    if (x->length == 0) {
        free(y);
        return x;
    } else if (y->length == 0) {
        free(x);
        return y;
    }
    z = set_create(x->length + y->length);
    zp = z->r;
    while (xp != xe && yp != ye) {
        if (xp->first > yp->first) {
            tp = xp; te = xe;
            xp = yp; xe = ye;
            yp = tp; ye = te;
        }
        limit = xp->last;
        ++xp;
        while (yp != ye && yp->first <= limit) {
            zp->first = yp->first;
            if (yp->last <= limit) {
                zp->last = yp->last;
                ++zp;
                ++yp;
            } else {
                zp->last = limit;
                ++zp;
                limit = yp->last;
                ++yp;
                tp = xp; te = xe;
                xp = yp; xe = ye;
                yp = tp; ye = te;
            }
        }
    }
    z->length = zp - z->r;
    free(x);
    free(y);
    return z;
}
예제 #20
0
파일: db_set.c 프로젝트: BogdanStroe/cubrid
/*
 * db_col_create() - This is the primary function for constructing a new
 *    collection. Type should be DB_TYPE_SET, DB_TYPE_MULTISET, or
 *    DB_TYPE_SEQUENCE. Size should always be specified if known before
 *    hand as it will significantly improve performance when incrementally
 *    building collections. Domain is optional. If NULL, it is assumed that
 *    this is a "wildcard" collection and can contain elements of any domain.
 *    The elements already existing in the collection should be within the
 *    supplied domain.If a domain is supplied, the type argument is ignored.
 * return : collection (NULL if error)
 * type(in): one of the DB_TYPE_ collection types
 * size(in): initial size to preallocate (zero if unknown)
 * domain(in): fully specified domain (optional)
 *
 * note : The collection handle returned must be freed using the db_col_free()
 *    function when the collection handle is no longer necessary.
 */
DB_COLLECTION *
db_col_create (DB_TYPE type, int size, DB_DOMAIN * domain)
{
  DB_COLLECTION *col;

  CHECK_CONNECT_NULL ();

  if (domain != NULL)
    {
      col = set_create_with_domain (domain, size);
    }
  else
    {
      col = set_create (type, size);
    }

  return col;
}
예제 #21
0
int main(int argc, char **argv)
{
	int i = 0;
	int arg_data_index = 0;
	struct cmdline_opt options;
	set_t *set;

	arg_data_index = parse_args(argc, argv, &options);

	set = set_create();

	for (i = arg_data_index; i < argc; i++) {
		process_datafile(argv[i], set, &options);
	}

	set_destroy(set);

	return EXIT_SUCCESS;
}
예제 #22
0
int main( int argc, char*argv[] )
{
	set * p_set = NULL;

	test_set_output( TEST_OUTPUT_BOTH );

	p_set = set_create();

	if ( test_assert_true ( p_set != NULL, "set creation" ) )
	{
		/* create a set with 35 elements */
		int i, *test_search;
		for( i=0; i<35; i++ )
		{
			int * test_element = (int*) malloc( sizeof(int) );
			*test_element = i;
			set_push_element( p_set, (void*) test_element );

			if ( ! test_assert_true( p_set->size == (i + 1) , "set element pushing") )
				break;

		}		

		test_search = (int*) malloc( sizeof(int) );

		/* search for an existing element */
		*test_search = 10;
		test_assert_true( set_contains( p_set, test_search, &test_set_int_compare ), "set search existing" ); 
		
		/* search for a non-existing element */
		*test_search = 56;
		test_assert_true( !set_contains( p_set, test_search, &test_set_int_compare ), "set search non-existing" ); 

		sn_free( (void**) &test_search );

		set_free( &p_set );
		
	}

	
	exit(0);
	
}
예제 #23
0
struct list *catalog_query_sort_hostlist(const char *hosts) {
	const char *next_host;
	char *n;
	struct catalog_host *h;
	struct list *previously_up = list_create();
	struct list *previously_down = list_create();

	if(string_null_or_empty(hosts)) {
		next_host = CATALOG_HOST;
	} else {
		next_host = hosts;
	}

	if(!down_hosts) {
		down_hosts = set_create(0);
	}

	do {
		int port;
		char host[DOMAIN_NAME_MAX];
		h = xxmalloc(sizeof(*h));
		next_host = parse_hostlist(next_host, host, &port);

		h->host = xxstrdup(host);
		h->url = string_format("http://%s:%d/query.json", host, port);
		h->down = 0;

		set_first_element(down_hosts);
		while((n = set_next_element(down_hosts))) {
			if(!strcmp(n, host)) {
				h->down = 1;
			}
		}
		if(h->down) {
			list_push_tail(previously_down, h);
		} else {
			list_push_tail(previously_up, h);
		}
	} while (next_host);

	return list_splice(previously_up, previously_down);
}
예제 #24
0
/*@ 
   set_union - find the difference of two sets

Input arguments:
+ s - The first set
- t - The second set

Output arguments:
None

Returns:
A new set that contains all the elements of s not in t,
NULL otherwise.

Notes:
s and t must contain the same types of elements
@*/
struct set *set_diff(struct set *s, struct set *t)
{
    void * e;
    struct set *tmp;

    /* Try to make sure that these two sets contain the same types */
    if (s->cmp != t->cmp || s->elemsize != t->elemsize)
	return NULL;
    
    tmp = set_create(s->maxsize+t->maxsize, s->elemsize, s->cmp);
    if (tmp == NULL)
	return NULL;

    /* Insert all the elements of s not in t */
    for (set_reset(s), e = set_next(s); e != NULL; e = set_next(s)){
	if (!set_exists(t, e))
	    set_insert(tmp, e);
    }

    return tmp;
}
예제 #25
0
파일: set.c 프로젝트: Baguage/cctools
static int set_double_buckets(struct set *s)
{
	struct set *sn = set_create(2 * s->bucket_count);

	if(!sn)
		return 0;

	/* Move elements to new set */
	void *element;
	set_first_element(s);
	while( (element = set_next_element(s)) )
		if(!set_insert(sn, element))
		{
			set_delete(sn);
			return 0;
		}

	/* Delete all elements */
	struct entry *e, *f;
	int i;
	for(i = 0; i < s->bucket_count; i++) {
		e = s->buckets[i];
		while(e) {
			f = e->next;
			free(e);
			e = f;
		}
	}

	/* Make the old point to the new */
	free(s->buckets);
	s->buckets      = sn->buckets;
	s->bucket_count = sn->bucket_count;
	s->size         = sn->size;

	/* Delete reference to new, so old is safe */
	free(sn);

	return 1;
}
예제 #26
0
int
main(int argc, char **argv)
{
	struct set *set;
	struct set_entry *entry;
	int size = 10000;
	uint32_t keys[size];
	uint32_t i, random_value;

	set = set_create(key_value, uint32_t_key_equals);

	for (i = 0; i < size; i++) {
		keys[i] = i;

		set_add(set, keys + i);
	}

	/* Test the no-predicate case. */
	entry = set_random_entry(set, NULL);
	assert(entry);

	/* Check that we're getting different entries and that the predicate
	 * works.
	 */
	for (i = 0; i < 100; i++) {
		entry = set_random_entry(set, uint32_t_key_is_even);
		assert(entry);
		assert((key_value(entry->key) & 1) == 0);
		if (i == 0 || key_value(entry->key) != random_value)
			break;
		random_value = key_value(entry->key);
	}
	assert(i != 100);

	set_destroy(set, NULL);

	return 0;
}
예제 #27
0
파일: settings.c 프로젝트: vible/rcmbot
/* Loads all settings from file */
struct settings *set_load_file(char *filename)
{
        FILE *file;
        char buffer[512];
        char *value;
        char *n;
        struct settings *set = NULL;

        file = fopen(filename, "r");

        if (!file) {
                debug_print("Couldnt open file");
                return NULL;
        }

        while (fgets(buffer, 512, file)) {
                n = strchr(buffer, '=');

                if (!n)
                        continue;

                value = strtok(buffer, "=");
                value = strtok(NULL, "\n");
                n[0] = '\0';

                n = strchr(value, '\n');

                if (n)
                        n[0] = '\0';

                set = set_create(set, buffer, value);
        }

        fclose(file);

        return set;
}
예제 #28
0
/* The descendant footprint of a node is defined as a balance between
 * the widest point of the children branches, while still maintaining
 * the existance of the sibling branches. The assumption is that by
 * knowing the larget size needed, all other branches can be executed
 * within that designated size, so we only need to add the residual
 * size of a branch to hold onto it while the heavier weights are
 * computed. */
void dag_node_footprint_determine_descendant(struct dag_node *n)
{
	struct dag_node *node1, *node2; //, *res_node;
	struct list *tmp_direct_children = list_create();
	struct set *footprint = set_create(0);
	uint64_t footprint_size = 0;

	/* Create a second list of direct children that allows us to
		sort on footprint properties. This is used
		when we compare footprint and the residual nodes. */
	set_first_element(n->footprint->direct_children);
	while((node1 = set_next_element(n->footprint->direct_children))){
		list_push_tail(tmp_direct_children, node1);
		list_first_item(node1->footprint->residual_nodes);
	}

	/* There are two cases for descendant nodes:
		1. Multiple direct_children indicating that multiple branches will
			need to be maintained concurrently and we need to account.
		2. One descendant indicating we want to continue the chain
			of residual and footprints that out child holds.
			create empty lists for this case.
	*/
	set_first_element(n->footprint->direct_children);
	if(set_size(n->footprint->direct_children) > 1){
		dag_node_footprint_determine_desc_residual_intersect(n);

		dag_node_footprint_set_desc_res_wgt_diff(n);

		set_insert_list(footprint, n->target_files);

		list_sort(tmp_direct_children, dag_node_footprint_comp_diff);
		list_first_item(tmp_direct_children);
		/* Loop over each child giving it the chance to be the largest footprint. */
		while((node1 = list_next_item(tmp_direct_children))){
			footprint_size = dag_file_set_size(footprint);
			if((footprint_size + node1->footprint->wgt) > n->footprint->delete_footprint){
				set_delete(n->footprint->delete_files);
				n->footprint->delete_files = set_duplicate(footprint);
				set_insert_set(n->footprint->delete_files, node1->footprint->wgt_files);
				n->footprint->delete_footprint = dag_file_set_size(n->footprint->delete_files);

			}
			// This is where we would remove an input file if it wasn't needed for other branches
			set_insert_set(footprint, node1->footprint->res_files);
			list_push_tail(n->footprint->delete_run_order, node1);
		}

		list_sort(tmp_direct_children, dag_node_footprint_comp_wgt_rev);
		list_first_item(tmp_direct_children);
		node1 = list_next_item(tmp_direct_children);

		set_insert_set(n->footprint->prog_max_files, node1->footprint->max_wgt_files);
		set_insert_set(n->footprint->prog_min_files, node1->footprint->wgt_files);
		list_push_tail(n->footprint->prog_run_order, node1);

		/* Find what the total space is needed to hold all residuals and
			the largest footprint branch concurrently. */
		while((node2 = list_next_item(tmp_direct_children))){
			set_insert_set(n->footprint->prog_max_files, node2->footprint->max_wgt_files);
			set_insert_set(n->footprint->prog_min_files, node2->footprint->res_files);
			list_push_tail(n->footprint->prog_run_order, node2);
		}

		n->footprint->prog_max_footprint = dag_file_set_size(n->footprint->prog_max_files);
		n->footprint->prog_min_footprint = dag_file_set_size(n->footprint->prog_min_files);
	} else {
		if(set_size(n->footprint->direct_children) == 1){
			node1 = set_next_element(n->footprint->direct_children);
			list_delete(n->footprint->residual_nodes);
			n->footprint->residual_nodes = list_duplicate(node1->footprint->residual_nodes);
		}

		set_insert_list(n->footprint->residual_files, n->target_files);
		set_insert_set(n->footprint->residual_files, n->footprint->terminal_files);
		n->footprint->residual_size = dag_file_set_size(n->footprint->residual_files);
	}

	/* Adding the current nodes list so parents can quickly access
		these decisions. */
	list_push_tail(n->footprint->residual_nodes, n);

	list_delete(tmp_direct_children);
	set_delete(footprint);
}
예제 #29
0
struct dag_node_footprint *dag_node_footprint_create()
{
	struct dag_node_footprint *f;

	f = malloc(sizeof(struct dag_node_footprint));

	f->direct_children = set_create(0);
	f->accounted = set_create(0);

	f->source_size = 0;
	f->target_size = 0;

	f->terminal_files = set_create(0);
	f->coexist_files = set_create(0);

	f->residual_nodes = list_create();
	f->residual_files = set_create(0);
	f->residual_size = 0;

	f->run_files = set_create(0);
	f->run_footprint = 0;

	f->delete_files = set_create(0);
	f->delete_footprint = 0;
	f->delete_run_order = list_create();

	f->prog_min_files = set_create(0);
	f->prog_min_footprint = 0;

	f->prog_max_files = set_create(0);
	f->prog_max_footprint = 0;
	f->prog_run_order = list_create();

	f->footprint_min_files = set_create(0);
	f->footprint_min_size = 0;

	f->footprint_max_files = set_create(0);
	f->footprint_max_size = 0;

	f->res = 0;
	f->res_files = set_create(0);
	f->wgt = 0;
	f->wgt_files = set_create(0);
	f->max_wgt = 0;
	f->max_wgt_files = set_create(0);
	f->diff = 0;

	f->children_updated = 0;
	f->size_updated = 0;
	f->footprint_updated = 0;
	f->terminal_updated = 0;

	return f;
}
예제 #30
0
파일: set.c 프로젝트: depp/uniset
struct set *
set_union(struct set *x, struct set *y)
{
    struct set *z;
    struct range *restrict xp = x->r, *xe = x->r + x->length;
    struct range *restrict yp = y->r, *ye = y->r + y->length;
    struct range *tp, *te, *restrict zp;
    unsigned int afirst, alast, bfirst, blast;
    if (x->length == 0) {
        free(x);
        return y;
    } else if (y->length == 0) {
        free(y);
        return x;
    }
    z = set_create(x->length + y->length);
    zp = z->r;
    while (1) {
        if (xp->first < yp->first) {
            tp = xp; te = xe;
            xp = yp; xe = ye;
            yp = tp; ye = te;
        }
        afirst = yp->first;
        alast = yp->last;
        ++yp;
        while (1) {
            bfirst = xp->first;
            blast = xp->last;
            if (bfirst > alast + 1)
                break;
            ++xp;
            if (blast > alast) {
                alast = blast;
                tp = xp; te = xe;
                xp = yp; xe = ye;
                yp = tp; ye = te;
            }
            if (xp == xe) {
                zp->first = afirst;
                zp->last = alast;
                ++zp;
                while (yp != ye)
                    *zp++ = *yp++;
                goto done;
            }
        }
        zp->first = afirst;
        zp->last = alast;
        ++zp;
        if (yp == ye) {
            while (xp != xe)
                *zp++ =  *xp++;
            goto done;
        }
    }
done:
    z->length = zp - z->r;
    free(x);
    free(y);
    return z;
}