T Set_union(T s, T t)
{
	if (s == NULL)
	{
		assert(t);
		return copy(t, t->m_size);
	}
	else if (t == NULL)
	{
		return copy(s, s->m_size);
	}
	else
	{
		T set = copy(s, Arith_max(s->m_size, t->m_size));
		assert(s->m_compare == t->m_compare && s->m_hash == t->m_hash);
		{
			/*for each member q in t*/
			size_t i;
			struct element* q;
			for (i = 0; i < t->m_size; i++)
			{
				for (q = t->m_buckets[i]; q != NULL; q = q->m_next)
				{
					/*\for each member q in t*/
					Set_put(set, q->m_value);
				}
			}
		}
		return set;
	}
}
Beispiel #2
0
T Set_union(T s, T t) {
	if (s == NULL) {
		assert(t);
		return copy(t, t->size);
	} else if (t == NULL)
		return copy(s, s->size);
	else {
		T set = copy(s, Arith_max(s->size, t->size));
		assert(s->cmp == t->cmp && s->hash == t->hash);
		{ int i;
		  struct member *q;
		  for (i = 0; i < t->size; i++)
		  	for (q = t->buckets[i]; q; q = q->link)
			Set_put(set, q->member);
		}
		return set;
	}
}