static celix_status_t getPermutations(array_list_pt bundleIds, int from, int to, array_list_pt permutations) {
		celix_status_t status = CELIX_SUCCESS;
		int i = 0;

		if (from == to) {
			long* permutation = (long*) calloc(to + 1, sizeof(*permutation));

			if (!permutation) {
				status = CELIX_ENOMEM;
			} else {
				for (; i <= to; i++) {
					permutation[i] = (long) arrayList_get(bundleIds, i);
				}

				arrayList_add(permutations, permutation);
			}
		} else {
			for (i = from; i <= to; i++) {
				long fromOrg = (long) arrayList_get(bundleIds, from);
				long iOrg = (long) arrayList_get(bundleIds, i);

				arrayList_set(bundleIds, from, (void*) iOrg);
				arrayList_set(bundleIds, i, (void*) fromOrg);

				status = getPermutations(bundleIds, from + 1, to, permutations);

				arrayList_set(bundleIds, from, (void*) fromOrg);
				arrayList_set(bundleIds, i, (void*) iOrg);
			}
		}

		return status;
	}
Exemple #2
0
void test_arrayList_set(void) {
	char * entry = "entry";
	char * entry2 = "entry2";
	char * entry3 = "entry3";
	char * get;
	char * old;

	arrayList_clear(list);

	arrayList_add(list, entry);
	arrayList_add(list, entry2);

	get = arrayList_get(list, 1);
	CU_ASSERT_EQUAL(entry2, get);

	old = arrayList_set(list, 1, entry3);
	CU_ASSERT_EQUAL(entry2, old);
	get = arrayList_get(list, 1);
	CU_ASSERT_EQUAL(entry3, get);
}