lookup_extended


Description:

public bool lookup_extended (K lookup_key, out unowned K orig_key, out unowned V value)

Looks up a key in the Tree, returning the original key and the associated value.

This is useful if you need to free the memory allocated for the original key, for example before calling remove.

Example: Lookup, extended:

public static int main (string[] args) {
Tree<string, string> tree = new Tree<string, string> ((a,b) => { return strcmp (a,b); });
tree.insert ("1. entry", "1. entry");
tree.insert ("2. entry", "2. entry");
tree.insert ("3. entry", "3. entry");

string needle = "1. entry";
unowned string? key = null; // stored key
unowned string? val = null; // stored value
bool res = tree.lookup_extended (needle, out key, out val);
// Output: ``res='true' needle='1. entry' key='1. entry', val='1. entry'``
print ("res='%s' needle='%s' key='%s', val='%s'\n", res.to_string (), needle, key, val);

return 0;
}

valac --pkg glib-2.0 GLib.Tree.lookup_extended.vala

Parameters:

this

a Tree

lookup_key

the key to look up

orig_key

returns the original key

value

returns the value associated with the key

Returns:

true if the key was found in the Tree