Beispiel #1
0
void new_insert_exists_destroy(void){
    /* our simple hash set */
    struct ls_set *set = 0;

    /* some keys */
    char *key_1 = "bbbbb";
    char *key_2 = "aaaaa";
    char *key_3 = "ccccc";

    puts("\ntesting basic functionality");

    puts("testing new");
    set = ls_new();
    assert(set);
    assert( 32 == set->size );
    assert( 0 == ls_nelems(set) );
    assert( 0 == ls_load(set) );


    puts("testing insert and get");
    puts("one");
    assert( ls_insert(set, key_1) );
    assert( 1 == ls_nelems(set) );
    assert( 0 == ls_exists(set, key_2) );
    assert( 0 == ls_exists(set, key_3) );
    assert(ls_exists(set, key_1) );


    puts("two");
    assert( ls_insert(set, key_2) );
    assert( 2 == ls_nelems(set) );
    assert( 0 == ls_exists(set, key_3) );
    assert( ls_exists(set, key_2) );


    puts("three");
    assert( ls_insert(set, key_3) );
    assert( 3 == ls_nelems(set) );
    assert( ls_exists(set, key_3) );


    assert( ls_destroy(set, 1) );
    puts("success!");
}
Beispiel #2
0
struct place * nc_create_place (void)
{
	struct place * p;
	
	p = ut_malloc (sizeof (struct place));
	ls_insert (&u.net.places, &p->nod);

	p->id = u.net.numpl++;
	al_init (&p->pre);
	al_init (&p->post);
	al_init (&p->cont);
	ls_init (&p->conds);
	p->m = 0;

	return p;
}
Beispiel #3
0
struct trans * nc_create_transition (void)
{
	struct trans * t;

	t = ut_malloc (sizeof (struct trans));
	ls_insert (&u.net.trans, &t->nod);

	t->id = ++u.net.numtr;
	al_init (&t->pre);
	al_init (&t->post);
	al_init (&t->cont);
	ls_init (&t->events);
	t->m = 0;
	t->parikhcnt1 = 0;
	t->parikhcnt2 = 0;

	return t;
}
Beispiel #4
0
static struct event * _pe_comb_new_event (void)
{
	struct trans *t;
	struct event *e;
	struct cond *c;
	int i;

	t = pe.comb.t;
	ASSERT (t);
	ASSERT (t->pre.deg + t->cont.deg == pe.comb.size + 1);

	/* allocate and initialize the event */
	e = gl_malloc (sizeof (struct event));
	ls_insert (&u.unf.events, &e->nod);
	al_init (&e->pre);
	al_init (&e->post);
	al_init (&e->cont);
	al_init (&e->ac);
	al_init (&e->hist);
	e->ft = t;
	ls_insert (&t->events, &e->tnod);
	e->m = 0;
	e->id = u.unf.numev++;

	/* we will update this if we find one history for this event which is
	 * not a cutoff */
	e->iscutoff = 1;

	/* add pe.comb.r->c to either the preset or context of e */
	if (pe.comb.ispre) {
		al_add (&e->pre, pe.comb.r->c);
		al_add (&pe.comb.r->c->post, e);
	} else {
		al_add (&e->cont, pe.comb.r->c);
		al_add (&pe.comb.r->c->cont, e);
	}

	/* set up preset and context */
	for (i = 0; i < pe.comb.size; i++) {
		c = pe.comb.tab[i].tab[pe.comb.tab[i].i]->c;
		if (pe.comb.tab[i].ispre) {
			al_add (&e->pre, c);
			al_add (&c->post, e);
		} else {
			al_add (&e->cont, c);
			al_add (&c->cont, e);
		}
	}
  ASSERT (e->pre.deg == t->pre.deg);
  ASSERT (e->cont.deg == t->cont.deg);

#ifdef CONFIG_DEBUG
	DPRINT ("+ Event e%d:%s; pre {", e->id, e->ft->name);
	for (i = e->pre.deg - 1; i >= 0; i--) {
		c = (struct cond *) e->pre.adj[i];
		DPRINT (" c%d:%s", c->id, c->fp->name);
	}
	DPRINT ("}; cont {");
	for (i = e->cont.deg - 1; i >= 0; i--) {
		c = (struct cond *) e->cont.adj[i];
		DPRINT (" c%d:%s", c->id, c->fp->name);
	}
	DPRINT ("}\n");
#endif

	/* therefore, at this the moment the event has no postset */
	return e;
}
Beispiel #5
0
void marking_add (struct h *h)
{
	struct hash_entry *he, *nhe;
	struct ls *buckl, *n;
	int ret;

	ASSERT (h);
	ASSERT (h->marking);
	ASSERT (h->corr != 0); /* histories always initialized as cutoffs */

	/* h->corr = 0;
	return; */

	/* add the marking h->marking to the hash table if there is no
	 * other history h' such that h->marking = h'->marking; if such h'
	 * exists, then h is a cutoff; the function returns 1 iff h is a cutoff
	 */

	/* determine if the marking h->marking is in the hash table */
	ASSERT (marking_hash (h->marking) == h->hash);
	buckl = hash.tab + h->hash;
	for (n = buckl->next; n; n = n->next) {
		he = ls_i (struct hash_entry, n, nod);
		ret = nl_compare (he->h->marking, h->marking);
		if (ret == 0) break;
	}

#ifdef CONFIG_MCMILLAN
	/* if it is the case, and the corresponding history is smaller,
	 * according to the McMillan's order, then it is a cutoff */
	if (n && h_cmp (he->h, h) < 0) {
#else
	/* if present in the hash table, then we know h is a cutoff, as we are
	 * sure that the corresponding history is smaller (the ERV order is
	 * total) */
	if (n) {
		// FIXME -- this deosn't work!!! ASSERT (h_cmp (he->h, h) < 0);
		ASSERT (h_cmp (he->h, h) <= 0);
#endif

		/* deallocate the marking and set history h as a cutoff, whose
		 * corresponding history is he->h */
		ASSERT (he);
		nl_delete (h->marking);
		h->marking = 0;
		h->corr = he->h;
		u.unf.numcutoffs++;
		return;
	}

	/* otherwise, insert h into the table */
	h->corr = 0;
	nhe = gl_malloc (sizeof (struct hash_entry));
	nhe->h = h;
	ls_insert (buckl, &nhe->nod);
	return;
}

static void _marking_print (const struct nl *l)
{
	if (! l) return;
	_marking_print (l->next);

	PRINT (" %s", ((const struct place*) (l->node))->name);
}

void marking_print (const struct h *h)
{
	_marking_print (h->marking);
}