Tree


Object Hierarchy:

GLib.Tree GLib.Tree GLib.Tree

Description:

[ Compact ]
[ Version ( since = "2.22" ) ]
[ CCode ( ref_function = "g_tree_ref" , type_id = "G_TYPE_TREE" , unref_function = "g_tree_unref" ) ]
public class Tree<K,V>

The GTree struct is an opaque data structure representing a balanced binary tree.

It should be accessed only by using the following functions.

Example: Apply a function to each element:

public static int main (string[] args) {
Tree<string, string> tree = new Tree<string, string>.full ((a, b) => { return strcmp (a, b); }, free, free);
tree.insert ("key1", "val1");
tree.insert ("key2", "val2");
tree.insert ("key3", "val3");

// Output:
// ``key=key1, value=val1``
// ``key=key2, value=val2``
// ``key=key3, value=val3``
tree.@foreach ((_key, _val) => {
unowned string key = (string) _key; // void* _key
unowned string val = (string) _val; // void* _val
print ("key=%s, value=%s\n", key, val);
return false; // return true to stop foreach
});

return 0;
}

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


Namespace: GLib
Package: glib-2.0

Content:

Creation methods:

Methods: