void array_prepend(Array* arr, uint sz, void* el) { array_expand(arr, sz); memmove(arr->data + sz, arr->data, sz * arr->size); memcpy(arr->data, el, sz); arr->size++; }
void test_expand_contract() { size_t old_max = array->max; array_expand(array); mu_assert((unsigned int) array->max == old_max + array->expand_rate, "Wrong size after expand"); array_contract(array); mu_assert((unsigned int) array->max == array->expand_rate + 1, "Should stay at the expand rate at least"); }
uint8_t _read_refs(ngdb_t *ngdb, graph_t *graph, uint32_t nidx) { uint64_t i; uint32_t numrefs; uint32_t *refs; double *wts; refs = NULL; wts = NULL; numrefs = ngdb_node_num_refs(ngdb, nidx); if (numrefs == 0xFFFFFFFF) goto fail; if (numrefs > 0) { refs = malloc(numrefs*sizeof(uint32_t)); wts = malloc(numrefs*sizeof(double)); if (refs == NULL) goto fail; if (wts == NULL) goto fail; if (ngdb_node_get_all_refs(ngdb, nidx, refs, wts) != 0) goto fail; if (array_expand(&graph->neighbours[nidx], numrefs+1)) goto fail; if (array_expand(&graph->weights[ nidx], numrefs+1)) goto fail; for (i = 0; i < numrefs; i++) { if (graph_add_edge(graph, nidx, refs[i], wts[i])) goto fail; } free(refs); free(wts); refs = NULL; wts = NULL; } return 0; fail: if (refs != NULL) free(refs); if (wts != NULL) free(wts); return 1; }