GLib.Tree¶
Fields¶
None
Methods¶
| destroy() | |
| height() | |
| insert(key, value) | |
| lookup(key) | |
| lookup_extended(lookup_key) | |
| nnodes() | |
| remove(key) | |
| replace(key, value) | |
| steal(key) | |
| unref() | 
Details¶
- 
class GLib.Tree¶
- The - GLib.Treestruct is an opaque data structure representing a balanced binary tree. It should be accessed only by using the following functions.- 
destroy()[source]¶
- Removes all keys and values from the - GLib.Treeand decreases its reference count by one. If keys and/or values are dynamically allocated, you should either free them first or create the- GLib.Treeusing g_tree_new_full(). In the latter case the destroy functions you supplied will be called on all keys and values before destroying the- GLib.Tree.
 - 
height()[source]¶
- Returns: - the height of self - Return type: - int- Gets the height of a - GLib.Tree.- If the - GLib.Treecontains no nodes, the height is 0. If the- GLib.Treecontains only one root node the height is 1. If the root node has children the height is 2, etc.
 - 
insert(key, value)[source]¶
- Parameters: - Inserts a key/value pair into a - GLib.Tree.- If the given key already exists in the - GLib.Treeits corresponding value is set to the new value. If you supplied a value_destroy_func when creating the- GLib.Tree, the old value is freed using that function. If you supplied a key_destroy_func when creating the- GLib.Tree, the passed key is freed using that function.- The tree is automatically ‘balanced’ as new key/value pairs are added, so that the distance from the root to every leaf is as small as possible. The cost of maintaining a balanced tree while inserting new key/value result in a O(n log(n)) operation where most of the other operations are O(log(n)). 
 - 
lookup(key)[source]¶
- Parameters: - key ( - objector- None) – the key to look up- Returns: - the value corresponding to the key, or - Noneif the key was not found- Return type: - objector- None- Gets the value corresponding to the given key. Since a - GLib.Treeis automatically balanced as key/value pairs are added, key lookup is O(log n) (where n is the number of key/value pairs in the tree).
 - 
lookup_extended(lookup_key)[source]¶
- Parameters: - lookup_key ( - objector- None) – the key to look up- Returns: - Trueif the key was found in the- GLib.Tree- orig_key: - returns the original key - value: - returns the value associated with the key - Return type: - ( - bool, orig_key:- object, value:- object)- Looks up a key in the - GLib.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- GLib.Tree.remove().
 - 
nnodes()[source]¶
- Returns: - the number of nodes in self - Return type: - int- Gets the number of nodes in a - GLib.Tree.
 - 
remove(key)[source]¶
- Parameters: - key ( - objector- None) – the key to remove- Returns: - Trueif the key was found (prior to 2.8, this function returned nothing)- Return type: - bool- Removes a key/value pair from a - GLib.Tree.- If the - GLib.Treewas created using g_tree_new_full(), the key and value are freed using the supplied destroy functions, otherwise you have to make sure that any dynamically allocated values are freed yourself. If the key does not exist in the- GLib.Tree, the function does nothing.- The cost of maintaining a balanced tree while removing a key/value result in a O(n log(n)) operation where most of the other operations are O(log(n)). 
 - 
replace(key, value)[source]¶
- Parameters: - Inserts a new key and value into a - GLib.Treesimilar to- GLib.Tree.insert(). The difference is that if the key already exists in the- GLib.Tree, it gets replaced by the new key. If you supplied a value_destroy_func when creating the- GLib.Tree, the old value is freed using that function. If you supplied a key_destroy_func when creating the- GLib.Tree, the old key is freed using that function.- The tree is automatically ‘balanced’ as new key/value pairs are added, so that the distance from the root to every leaf is as small as possible. 
 - 
steal(key)[source]¶
- Parameters: - key ( - objector- None) – the key to remove- Returns: - Trueif the key was found (prior to 2.8, this function returned nothing)- Return type: - bool- Removes a key and its associated value from a - GLib.Treewithout calling the key and value destroy functions.- If the key does not exist in the - GLib.Tree, the function does nothing.
 
-