Esempio n. 1
0
static void
dyn_array_int_merge_one (DynArray *array, int value)
{
	int i;
	int tmp;
	int end = array->size;

	for (i = 0; i < end; ++i) {
		if (DYN_ARRAY_INT_REF (array, i) == value)
			return;
		else if (DYN_ARRAY_INT_REF (array, i) > value)
			break;
	}

	dyn_array_ensure_capacity (array, array->size + 1);

	if (i < end) {
		tmp = DYN_ARRAY_INT_REF (array, i);
		for (; i <= end; ++i) {
			DYN_ARRAY_INT_REF (array, i) = value;
			value = tmp;
			tmp = DYN_ARRAY_INT_REF (array, i + 1);
		}
		DYN_ARRAY_INT_REF (array, end + 1) = tmp;
	} else {
		DYN_ARRAY_INT_REF (array, end) = value;
	}
	++array->size;
}
Esempio n. 2
0
static void
dyn_array_ensure_independent (DynArray *da, int elem_size)
{
	if (!dyn_array_is_copy (da))
		return;
	dyn_array_ensure_capacity (da, da->size, elem_size);
	g_assert (da->capacity > 0);
}
Esempio n. 3
0
static void*
dyn_array_add (DynArray *da)
{
	void *p;

	dyn_array_ensure_capacity (da, da->size + 1);

	p = DYN_ARRAY_REF (da, da->size);
	++da->size;
	return p;
}
Esempio n. 4
0
static void*
dyn_array_add (DynArray *da, int elem_size)
{
	void *p;

	dyn_array_ensure_capacity (da, da->size + 1, elem_size);

	p = da->data + da->size * elem_size;
	++da->size;
	return p;
}
Esempio n. 5
0
static void
dyn_array_int_merge (DynArray *dst, DynArray *src)
{
	int i, j;

	dyn_array_ensure_capacity (&merge_array, dst->size + src->size);
	merge_array.size = 0;

	for (i = j = 0; i < dst->size || j < src->size; ) {
		if (i < dst->size && j < src->size) {
			int a = DYN_ARRAY_INT_REF (dst, i); 
			int b = DYN_ARRAY_INT_REF (src, j); 
			if (a < b) {
				dyn_array_int_add (&merge_array, a);
				++i;
			} else if (a == b) {
				dyn_array_int_add (&merge_array, a);
				++i;
				++j;	
			} else {
				dyn_array_int_add (&merge_array, b);
				++j;
			}
		} else if (i < dst->size) {
			dyn_array_int_add (&merge_array, DYN_ARRAY_INT_REF (dst, i));
			++i;
		} else {
			dyn_array_int_add (&merge_array, DYN_ARRAY_INT_REF (src, j));
			++j;
		}
	}

	if (merge_array.size > dst->size) {
		dyn_array_ensure_capacity (dst, merge_array.size);
		memcpy (DYN_ARRAY_REF (dst, 0), DYN_ARRAY_REF (&merge_array, 0), merge_array.size * merge_array.elem_size);
		dst->size = merge_array.size;
	}
}
Esempio n. 6
0
static void
dyn_array_int_ensure_capacity (DynIntArray *da, int capacity)
{
	dyn_array_ensure_capacity (&da->array, capacity, sizeof (int));
}
Esempio n. 7
0
static void
dyn_array_ptr_ensure_capacity (DynPtrArray *da, int capacity)
{
	dyn_array_ensure_capacity (&da->array, capacity, sizeof (void*));
}