Package ch.bailu.gtk.glib
Class Tree
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.type.Record
ch.bailu.gtk.glib.Tree
- All Implemented Interfaces:
PointerInterface
The GTree struct is an opaque data structure representing a
[balanced binary tree][glib-Balanced-Binary-Trees]. It should be
accessed only by using the following functions.
[balanced binary tree][glib-Balanced-Binary-Trees]. It should be
accessed only by using the following functions.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
static interface
static interface
static interface
-
Field Summary
-
Constructor Summary
ConstructorDescriptionTree
(Tree.OnCompareFunc key_compare_func) Creates a new #GTree.Tree
(PointerContainer pointer) -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
Removes all keys and values from the #GTree and decreases its
reference count by one.void
foreach
(Tree.OnTraverseFunc func, Pointer user_data) Calls the given function for each of the key/value pairs in the #GTree.void
foreachNode
(Tree.OnTraverseNodeFunc func, Pointer user_data) Calls the given function for each of the nodes in the #GTree.static ClassHandler
static int
static long
static TypeSystem.TypeSize
static long
static TypeSystem.TypeSize
int
height()
Gets the height of a #GTree.void
Inserts a key/value pair into a #GTree.ch.bailu.gtk.glib.TreeNode
insertNode
(Pointer key, Pointer value) Inserts a key/value pair into a #GTree.Gets the value corresponding to the given key.ch.bailu.gtk.glib.TreeNode
lookupNode
(Pointer key) Gets the tree node corresponding to the given key.ch.bailu.gtk.glib.TreeNode
lowerBound
(Pointer key) Gets the lower bound node corresponding to the given key,
or %NULL if the tree is empty or all the nodes in the tree
have keys that are strictly lower than the searched key.static Tree
newFullTree
(Tree.OnCompareDataFunc key_compare_func, Pointer key_compare_data, Tree.OnDestroyNotify key_destroy_func, Tree.OnDestroyNotify value_destroy_func) 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.static Tree
newWithDataTree
(Tree.OnCompareDataFunc key_compare_func, Pointer key_compare_data) Creates a new #GTree with a comparison function that accepts user data.int
nnodes()
Gets the number of nodes in a #GTree.ch.bailu.gtk.glib.TreeNode
Returns the first in-order node of the tree, or %NULL
for an empty tree.ch.bailu.gtk.glib.TreeNode
nodeLast()
Returns the last in-order node of the tree, or %NULL
for an empty tree.ref()
Increments the reference count of @tree by one.boolean
Removes a key/value pair from a #GTree.void
Removes all nodes from a #GTree and destroys their keys and values,
then resets the #GTree’s root to %NULL.void
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.ch.bailu.gtk.glib.TreeNode
replaceNode
(Pointer key, Pointer value) Inserts a new key and value into a #GTree similar to g_tree_insert_node().search
(Tree.OnCompareFunc search_func, Pointer user_data) Searches a #GTree using @search_func.ch.bailu.gtk.glib.TreeNode
searchNode
(Tree.OnCompareFunc search_func, Pointer user_data) Searches a #GTree using @search_func.boolean
Removes a key and its associated value from a #GTree without calling
the key and value destroy functions.void
unref()
Decrements the reference count of @tree by one.ch.bailu.gtk.glib.TreeNode
upperBound
(Pointer key) Gets the upper bound node corresponding to the given key,
or %NULL if the tree is empty or all the nodes in the tree
have keys that are lower than or equal to the searched key.Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Constructor Details
-
Tree
-
Tree
Creates a new #GTree.- Parameters:
key_compare_func
- the function used to order the nodes in the #GTree. It should return values similar to the standard strcmp() function - 0 if the two arguments are equal, a negative value if the first argument comes before the second, or a positive value if the first argument comes after the second.
-
-
Method Details
-
getClassHandler
-
newFullTree
public static Tree newFullTree(Tree.OnCompareDataFunc key_compare_func, @Nullable Pointer key_compare_data, Tree.OnDestroyNotify key_destroy_func, Tree.OnDestroyNotify value_destroy_func) 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.- Parameters:
key_compare_func
- qsort()-style comparison functionkey_compare_data
- data to pass to comparison functionkey_destroy_func
- a function to free the memory allocated for the key used when removing the entry from the #GTree or %NULL if you don't want to supply such a functionvalue_destroy_func
- a function to free the memory allocated for the value used when removing the entry from the #GTree or %NULL if you don't want to supply such a function- Returns:
- a newly allocated #GTree
-
newWithDataTree
public static Tree newWithDataTree(Tree.OnCompareDataFunc key_compare_func, @Nullable Pointer key_compare_data) Creates a new #GTree with a comparison function that accepts user data.
See g_tree_new() for more details.- Parameters:
key_compare_func
- qsort()-style comparison functionkey_compare_data
- data to pass to comparison function- Returns:
- a newly allocated #GTree
-
destroy
public void destroy()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 g_tree_new_full(). In the latter case the destroy functions
you supplied will be called on all keys and values before destroying
the #GTree. -
foreach
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.- Parameters:
func
- the function to call for each node visited. If this function returns %TRUE, the traversal is stopped.user_data
- user data to pass to the function
-
foreachNode
Calls the given function for each of the nodes in the #GTree.
The function is passed the pointer to the particular node, and the given
@data parameter. The tree traversal happens in-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.- Parameters:
func
- the function to call for each node visited. If this function returns %TRUE, the traversal is stopped.user_data
- user data to pass to the function
-
height
public int height()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.- Returns:
- the height of @tree
-
insert
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.- Parameters:
key
- the key to insertvalue
- the value corresponding to the key
-
insertNode
Inserts a key/value pair into a #GTree.
If the given key already exists in the #GTree its corresponding value
is set to the new value. If you supplied a @value_destroy_func when
creating the #GTree, the old value is freed using that function. If
you supplied a @key_destroy_func when creating the #GTree, 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)).- Parameters:
key
- the key to insertvalue
- the value corresponding to the key- Returns:
- the inserted (or set) node.
-
lookup
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).- Parameters:
key
- the key to look up- Returns:
- the value corresponding to the key, or %NULL if the key was not found
-
lookupNode
Gets the tree node 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).- Parameters:
key
- the key to look up- Returns:
- the tree node corresponding to the key, or %NULL if the key was not found
-
lowerBound
Gets the lower bound node corresponding to the given key,
or %NULL if the tree is empty or all the nodes in the tree
have keys that are strictly lower than the searched key.
The lower bound is the first node that has its key greater
than or equal to the searched key.- Parameters:
key
- the key to calculate the lower bound for- Returns:
- the tree node corresponding to the lower bound, or %NULL if the tree is empty or has only keys strictly lower than the searched key.
-
nnodes
public int nnodes()Gets the number of nodes in a #GTree.- Returns:
- the number of nodes in @tree
-
nodeFirst
public ch.bailu.gtk.glib.TreeNode nodeFirst()Returns the first in-order node of the tree, or %NULL
for an empty tree.- Returns:
- the first node in the tree
-
nodeLast
public ch.bailu.gtk.glib.TreeNode nodeLast()Returns the last in-order node of the tree, or %NULL
for an empty tree.- Returns:
- the last node in the tree
-
ref
Increments the reference count of @tree by one.
It is safe to call this function from any thread.- Returns:
- the passed in #GTree
-
remove
Removes a key/value pair from a #GTree.
If the #GTree was 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 #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)).- Parameters:
key
- the key to remove- Returns:
- %TRUE if the key was found (prior to 2.8, this function returned nothing)
-
removeAll
public void removeAll()Removes all nodes from a #GTree and destroys their keys and values,
then resets the #GTree’s root to %NULL. -
replace
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.- Parameters:
key
- the key to insertvalue
- the value corresponding to the key
-
replaceNode
Inserts a new key and value into a #GTree similar to g_tree_insert_node().
The difference is that if the key already exists in the #GTree, it gets
replaced by the new key. If you supplied a @value_destroy_func when
creating the #GTree, the old value is freed using that function. If you
supplied a @key_destroy_func when creating the #GTree, 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.- Parameters:
key
- the key to insertvalue
- the value corresponding to the key- Returns:
- the inserted (or set) node.
-
search
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 g_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.- Parameters:
search_func
- a function used to search the #GTreeuser_data
- the data passed as the second argument to @search_func- Returns:
- the value corresponding to the found key, or %NULL if the key was not found
-
searchNode
public ch.bailu.gtk.glib.TreeNode searchNode(Tree.OnCompareFunc search_func, @Nullable Pointer user_data) 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 node is returned as
the result of g_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.- Parameters:
search_func
- a function used to search the #GTreeuser_data
- the data passed as the second argument to @search_func- Returns:
- the node corresponding to the found key, or %NULL if the key was not found
-
steal
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.- Parameters:
key
- the key to remove- Returns:
- %TRUE if the key was found (prior to 2.8, this function returned nothing)
-
unref
public void unref()Decrements the reference count of @tree 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 @tree will be released.
It is safe to call this function from any thread. -
upperBound
Gets the upper bound node corresponding to the given key,
or %NULL if the tree is empty or all the nodes in the tree
have keys that are lower than or equal to the searched key.
The upper bound is the first node that has its key strictly greater
than the searched key.- Parameters:
key
- the key to calculate the upper bound for- Returns:
- the tree node corresponding to the upper bound, or %NULL if the tree is empty or has only keys lower than or equal to the searched key.
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-