The GTree struct is an opaque data structure representing a balanced binary tree. It should be accessed only by using the following functions.
Removes all keys and values from the <GTree> and
decreases its reference count by one. If keys and/or values are
dynamically allocated, you should either free them first or create the
<GTree> using tree:new-full. In the latter case the destroy functions you
supplied will be called on all keys and values before destroying the
<GTree>.
Calls the given function for each of the key/value pairs in the
<GTree>. The function is passed the key and value of
each pair, and the given data parameter. The tree is traversed in
sorted order.
The tree may not be modified while iterating over it (you can’t
add/remove items). To remove all items matching a predicate, you need
to add each item to a list in your
GTraverseFunc as you walk over the tree, then
walk the list and remove each item.
Passed: a <GTree>.
a <GTree>
Passed: a procedure.
the function to call for each node visited. If this function returns
#t, the traversal is stopped.
See GTraverseFunc for how it is called.
Not passed: guile-gi supplies it.
user data to pass to the function
Gets the height of a <GTree>.
If the <GTree> contains no nodes, the height is 0. If
the <GTree> contains only one root node the height is
1. If the root node has children the height is 2, etc.
Inserts a key/value pair into a <GTree>.
Inserts a new key and value into a <GTree> as
g_tree_insert_node() does, only this function does not return the
inserted or set node.
Gets the value corresponding to the given key. Since a
<GTree> is 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).
Looks up a key in the <GTree>, 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
tree:remove?.
Passed: a <GTree>.
a <GTree>
Passed, or left out: a foreign pointer, or a bytevector, or #f.
the key to look up
Returned: a boolean.
#t if the key was found in the <GTree>
Returned: a foreign pointer, or #f.
returns the original key
Returned: a foreign pointer, or #f.
returns the value associated with the key
Creates a new <GTree> like g_tree_new() and
allows to specify functions to free the memory allocated for the key and
value that get called when removing the entry from the
<GTree>.
Passed: a procedure.
qsort()-style comparison function
See GCompareDataFunc for how it is called.
Passed: a procedure.
a function to free the memory allocated for the key used when removing
the entry from the <GTree> or #f if you don’t
want to supply such a function
See GDestroyNotify for how it is called.
Returned: a <GTree>.
a newly allocated <GTree>
Not passed: guile-gi supplies it.
data to pass to comparison function
Not passed: guile-gi supplies it.
a function to free the memory allocated for the value used when removing
the entry from the <GTree> or #f if you don’t
want to supply such a function
See GDestroyNotify for how it is called.
Gets the number of nodes in a <GTree>.
Increments the reference count of self by one.
It is safe to call this function from any thread.
Removes all nodes from a <GTree> and destroys their
keys and values, then resets the <GTree>’s root to
#f.
Removes a key/value pair from a <GTree>.
If the <GTree> was created using 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 <GTree>, 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)).
Inserts a new key and value into a <GTree> as
g_tree_replace_node() does, only this function does not return
the inserted or set node.
Searches a <GTree> using search-func.
The search-func is called with a pointer to the key of a key/value
pair in the tree, and the passed in user-data. If
search-func returns 0 for a key/value pair, then the corresponding
value is returned as the result of tree:search. If search-func returns -1, searching will
proceed among the key/value pairs that have a smaller key; if
search-func returns 1, searching will proceed among the key/value
pairs that have a larger key.
Passed: a <GTree>.
a <GTree>
Passed: a procedure.
a function used to search the <GTree>
See GCompareFunc for how it is called.
Returned: a foreign pointer, or #f.
the value corresponding to the found key, or #f if the key was
not found
Not passed: guile-gi supplies it.
the data passed as the second argument to search-func
Removes a key and its associated value from a <GTree>
without calling the key and value destroy functions.
If the key does not exist in the <GTree>, the
function does nothing.
Calls the given function for each node in the
<GTree>.
Passed: a <GTree>.
a <GTree>
Passed: a procedure.
the function to call for each node visited. If this function returns
#t, the traversal is stopped.
See GTraverseFunc for how it is called.
Passed: a <%GTraverseType>, or one of its
symbols.
the order in which nodes are visited, one of
in-order,
pre-order and
post-order
Not passed: guile-gi supplies it.
user data to pass to the function
Decrements the reference count of self by one. If the reference count drops to 0, all keys and values will be destroyed (if destroy functions were specified) and all memory allocated by self will be released.
It is safe to call this function from any thread.