DArray * CloseNodes_GetNodes(CloseNodes *close) { assert(close != NULL && "NULL CloseNodes pointer"); DArray *nodes = DArray_create(sizeof(Node *), DArray_max(close->close_nodes)); check(nodes != NULL, "DArray_create failed"); int i = 0; for (i = 0; i < DArray_count(close->close_nodes); i++) { struct CloseNode *close_node = DArray_get(close->close_nodes, i); check(close_node != NULL, "NULL CloseNodes entry"); check(close_node->node != NULL, "NULL Node pointer in CloseNodes entry"); int rc = DArray_push(nodes, close_node->node); check(rc == 0, "DArray_push failed"); } return nodes; error: DArray_destroy(nodes); return NULL; }
int DArray_push(DArray *array, void *el) { array->contents[array->end] = el; array->end++; if (DArray_end(array) >= DArray_max(array)) { return DArray_expand(array); } else { return 0; } }
void ShiftFrom(DArray *close, int from) { assert(close != NULL && "NULL DArray pointer"); assert(BUCKET_K - 1 < DArray_max(close) && "Too small DArray"); assert(0 <= from && from <= DArray_end(close) && "Bad shift index"); if (DArray_end(close) == BUCKET_K) free(DArray_last(close)); int i; for (i = DArray_end(close) - 1; i > from; i--) { struct CloseNode *tmp = DArray_get(close, i - 1); DArray_set(close, i, tmp); } }
void DArray_destroy_ID_info(DArray *array, int ignore_const, int ignore_inputs, int ignore_outputs, int ignore_templates) { if(array) { int i = 0; if(array->element_size > 0) { for(i = 0; i < DArray_max(array); i++) { HashmapNode* node = (HashmapNode*) DArray_get(array,i); if(node) { ID_info* idi = (ID_info*) node->data; if(idi) { destroy_ID_info(idi, ignore_const, ignore_inputs, ignore_outputs, ignore_templates); } free(node); } } } if(array->contents) free(array->contents); free(array); array = NULL; } }
/* bring the array size down to max(array->end, array->expand_rate) */ int DArray_contract(DArray *array) { return DArray_resize(array, DArray_max(array->end, (int) array->expand_rate) + 1); }