int main(int argc, char** argv) { GTree* t = g_tree_new((GCompareFunc)g_ascii_strcasecmp); g_tree_insert(t, "c", "Chicago"); g_tree_insert(t, "b", "Boston"); g_tree_insert(t, "d", "Detroit"); printf("The data at 'b' is %s\n", g_tree_lookup(t, "b")); printf("%s\n", g_tree_lookup(t, "a") ? "My goodness!" : "As expected, couldn't find 'a'"); gpointer* key = NULL; gpointer* value = NULL; g_tree_lookup_extended(t, "c", (gpointer*)&key, (gpointer*)&value); printf("The data at '%s' is %s\n", key, value); gboolean found = g_tree_lookup_extended(t, "a", (gpointer*)&key, (gpointer*)&value); printf("%s\n", found ? "My goodness!" : "As expected, couldn't find 'a'"); g_tree_destroy(t); return 0; }
static gboolean mailbox_clear_recent(uint64_t *uid, MessageInfo *msginfo, T M) { msginfo->flags[IMAP_FLAG_RECENT] = 0; gpointer value; gpointer orig_key; if (g_tree_lookup_extended(M->recent_queue, uid, &orig_key, &value)) { g_tree_remove(M->recent_queue, orig_key); mempool_push(M->pool, orig_key, sizeof(uint64_t)); } return FALSE; }
gboolean ibus_hotkey_profile_remove_hotkey (IBusHotkeyProfile *profile, guint keyval, guint modifiers) { IBusHotkeyProfilePrivate *priv; priv = IBUS_HOTKEY_PROFILE_GET_PRIVATE (profile); IBusHotkey hotkey = { .keyval = keyval, .modifiers = modifiers }; IBusHotkey *p1; GQuark event; gboolean retval; retval = g_tree_lookup_extended (priv->hotkeys, &hotkey, (gpointer)&p1, (gpointer)&event); if (!retval) return FALSE; gint i; IBusHotkeyEvent *p2 = NULL; for ( i = 0; i < priv->events->len; i++) { p2 = &g_array_index (priv->events, IBusHotkeyEvent, i); if (p2->event == event) break; } g_assert (p2->event == event); p2->hotkeys = g_list_remove (p2->hotkeys, p1); if (p2->hotkeys == NULL) { g_array_remove_index_fast (priv->events, i); } g_tree_remove (priv->hotkeys, p1); return TRUE; }
static void add_incremental( CPIncrementals self, const char *key, /*@null@*/ const char *value, gboolean stack_use_expand ) /*@modifies *self@*/ { char **items; GTree *values; if (value == NULL) { return; } items = cp_strings_pysplit(value); if (items == NULL) { return; } values = register_incremental(self, key); /* As a long-standing practice, USE_EXPAND variables are only stacked across profiles, but not in make.conf. So, in order to be compatible with portage (and official Gentoo docs), we have this logic here. Yes, it is PMS violation. */ if (!stack_use_expand) { GTree *use_expand = g_tree_lookup(self->incrementals, "USE_EXPAND"); if (use_expand != NULL && g_tree_lookup_extended(use_expand, key, NULL, NULL)) { cp_tree_foreach_remove(values, cp_true_filter, NULL); } } cp_stack_dict(values, items); g_strfreev(items); }
static int url_find (char *urltext) { return (g_tree_lookup_extended (url_btree, urltext, NULL, NULL)); }
// We need node for the information about itself for the ownership details static void record_block_range(struct print_manager *pm, GNode * node, block_range_t range) { /* unsigned long long p; unsigned long long l; block_range_get_range(range, &p, &l); printf("Claiming range %llu-%llu\n", p, l); */ prong_assert(node != NULL); prong_assert(node->data != NULL); struct job_node_data *data = (struct job_node_data *) node->data; block_range_t existing_range; long long *owner; if (g_tree_lookup_extended(pm->continuation_tree, range, (gpointer *) & existing_range, (gpointer *) & owner) == TRUE) { unsigned long long pos_new; unsigned long long len_new; block_range_get_range(range, &pos_new, &len_new); unsigned long long pos_old; unsigned long long len_old; block_range_get_range(existing_range, &pos_old, &len_old); if (pos_new >= pos_old) { if ((pos_old + len_old) >= (pos_new + len_new)) { // Old has completely consumed new, therefore there is no work to do } else { // Old stops before completing consuming new. Add the remainder unsigned long long fragment_pos = pos_old + len_old; unsigned long long fragment_len = pos_new + len_new - fragment_pos; block_range_t br = block_range_init(NULL, 0); int ret = block_range_set_range(br, fragment_pos, fragment_len); prong_assert(ret == 0); record_block_range(pm, node, br); block_range_close(br); } } else { // We know that the new address starts before the old address unsigned long long fragment_pos = pos_new; unsigned long long fragment_len = pos_old - pos_new; block_range_t br = block_range_init(NULL, 0); int ret = block_range_set_range(br, fragment_pos, fragment_len); prong_assert(ret == 0); record_block_range(pm, node, br); block_range_close(br); if ((pos_new + len_new) >= (pos_old + len_old)) { // And now we know it also extends AFTER the end of the old address unsigned long long fragment_pos = pos_old + len_old; unsigned long long fragment_len = pos_new + len_new - fragment_pos; block_range_t br = block_range_init(NULL, 0); ret = block_range_set_range(br, fragment_pos, fragment_len); prong_assert(ret == 0); record_block_range(pm, node, br); block_range_close(br); } } } else { struct continuation_node *cont_node = (struct continuation_node *) g_malloc(sizeof(struct continuation_node)); cont_node->owner_offset = contract_get_absolute_offset(data->node_contract); unsigned int num_results; const result_t *results = contract_completion_report_get_results(data->node_report, &num_results); prong_assert(results != NULL); prong_assert(num_results > 0); cont_node->brief_description = g_strdup(result_get_brief_data_description(results[0])); cont_node->path = g_strdup(contract_get_path(data->node_contract)); cont_node->is_constant = is_constant_node(node); existing_range = block_range_clone(range); g_tree_insert(pm->continuation_tree, existing_range, cont_node); } }