/* This function copies the tree present in shared_region into the my_tree data structure for rank. * Doesn't perform any direct allocation, but utarray_new is called to allocate space for children * in my_tree. * */ void MPIDI_SHM_copy_tree(int *shared_region, int num_ranks, int rank, MPIR_Treealgo_tree_t * my_tree, int *topotree_fail) { int c; int *parent_ptr = shared_region; int *child_ctr = &shared_region[num_ranks]; int *children = &shared_region[num_ranks + num_ranks + 1]; int parent = parent_ptr[rank]; int num_children = child_ctr[rank + 1] - child_ctr[rank]; int *my_children = &children[child_ctr[rank]]; my_tree->parent = parent; my_tree->num_children = 0; my_tree->rank = rank; my_tree->nranks = num_ranks; utarray_new(my_tree->children, &ut_int_icd, MPL_MEM_COLL); utarray_reserve(my_tree->children, num_children, MPL_MEM_COLL); char str[1024], tmp[128]; sprintf(str, "----**Rank %d, Parent, %d, Child(%d)[", rank, parent, num_children); for (c = 0; c < num_children; ++c) { utarray_push_back(my_tree->children, &my_children[c], MPL_MEM_COLL); if (my_children[c] == 0) { *topotree_fail = 1; } sprintf(tmp, "%d, ", my_children[c]); strcat(str, tmp); my_tree->num_children++; } if (MPIDI_SHM_TOPOTREE_DEBUG) fprintf(stderr, "%s]\n", str); }
FCITX_EXPORT_API FcitxCandidateWordList* FcitxCandidateWordNewList() { FcitxCandidateWordList* candList = fcitx_utils_malloc0(sizeof(FcitxCandidateWordList)); utarray_init(&candList->candWords, &cand_icd); utarray_reserve(&candList->candWords, 128); candList->wordPerPage = 5; /* anyway put a default value for safety */ strncpy(candList->strChoose, DIGIT_STR_CHOOSE, MAX_CAND_WORD); return candList; }
FCITX_EXPORT_API void FcitxAddonsInit(UT_array* addons) { utarray_init(addons, &addon_icd); /* * FIXME: this is a workaround since everyone is using "FcitxAddon*" everywhere, * so realloc will really do some evil things. * * We might better use UT_hash for fcitx addon in the future */ utarray_reserve(addons, 512); }
/** * Return an array of size *returnSize. * Note: The returned array must be malloced, assume caller calls free(). */ int* postorderTraversal(struct TreeNode* root, int* returnSize) { UT_array* vec; utarray_new(vec, &ut_int_icd); utarray_reserve(vec, 8); postorderRecursive(root, vec); *returnSize = utarray_len(vec); int bytes = utarray_len(vec) * sizeof(int); int* res = malloc(bytes); memcpy(res, vec->d, bytes); utarray_free(vec); return res; }
device_consistency_signature_list *device_consistency_signature_list_copy(const device_consistency_signature_list *list) { int result = 0; device_consistency_signature_list *result_list = 0; unsigned int size; unsigned int i; device_consistency_signature **p; result_list = device_consistency_signature_list_alloc(); if(!result_list) { result = SG_ERR_NOMEM; goto complete; } size = utarray_len(list->values); utarray_reserve(result_list->values, size); for (i = 0; i < size; i++) { p = (device_consistency_signature **)utarray_eltptr(list->values, i); result = device_consistency_signature_list_push_back(result_list, *p); if(result < 0) { goto complete; } } complete: if(result < 0) { if(result_list) { device_consistency_signature_list_free(result_list); } return 0; } else { return result_list; } }
/* Runtime Error */ void postorderInterative(struct TreeNode* node, UT_array* v) { UT_array* stk; utarray_new(stk, &ut_ptr_icd); utarray_reserve(stk, 8); struct TreeNode* pre = NULL; while (utarray_len(stk) > 0 || node != NULL) { if (node != NULL) { utarray_push_back(stk, node); node = node->left; } else { struct TreeNode* tmp = utarray_back(stk); if (tmp->right != NULL && pre != tmp->right) { node = tmp->right; } else { utarray_pop_back(stk); utarray_push_back(v, &tmp->val); pre = tmp; } } } utarray_free(stk); }