/* * Clean data of keys array */ void clean_keys_array(const struct bwstring *s, struct keys_array *ka) { if (ka) { for (size_t i = 0; i < keys_num; ++i) if (ka->key[i].k && ka->key[i].k != s) bwsfree(ka->key[i].k); memset(ka, 0, keys_array_size()); } }
/* * Allocate keys array */ struct keys_array * keys_array_alloc(void) { struct keys_array *ka; size_t sz; sz = keys_array_size(); ka = sort_malloc(sz); memset(ka, 0, sz); return (ka); }
/* * Initialize a sort list item */ struct sort_list_item * sort_list_item_alloc(void) { struct sort_list_item *si; size_t sz; sz = sizeof(struct sort_list_item) + keys_array_size(); si = sort_malloc(sz); memset(si, 0, sz); return (si); }
/* * Clean data of keys array */ void clean_keys_array(const struct bwstring *s, struct keys_array *ka) { if (ka) { for (size_t i = 0; i < keys_num; ++i) { const struct key_value *kv; kv = get_key_from_keys_array(ka, i); if (kv->k && kv->k != s) bwsfree(kv->k); } memset(ka, 0, keys_array_size()); } }
size_t sort_list_item_size(struct sort_list_item *si) { size_t ret = 0; if (si) { ret = sizeof(struct sort_list_item) + keys_array_size(); if (si->str) ret += bws_memsize(si->str); for (size_t i = 0; i < keys_num; ++i) { const struct key_value *kv; kv = get_key_from_keys_array(&si->ka, i); if (kv->k != si->str) ret += bws_memsize(kv->k); } } return (ret); }
size_t sort_list_item_size(struct sort_list_item *si) { size_t ret = 0; if (si) { ret = sizeof(struct sort_list_item) + keys_array_size(); if (si->str) ret += bws_memsize(si->str); for (size_t i = 0; i < keys_num; ++i) { struct key_value *kv; kv = &(si->ka.key[i]); if (kv->k != si->str) ret += bws_memsize(kv->k); } } return (ret); }