Class Tree

All Implemented Interfaces:
PointerInterface

public class Tree extends Record
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.

https://docs.gtk.org/glib/struct.Tree.html

  • Constructor Details

    • Tree

      public Tree(PointerContainer pointer)
    • Tree

      public Tree(Tree.OnCompareFunc key_compare_func)
      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

      public static ClassHandler 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 function
      key_compare_data - data to pass to comparison function
      key_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 function
      value_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 function
      key_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.
      Overrides:
      destroy in class Record
    • foreach

      public void foreach(Tree.OnTraverseFunc func, @Nullable Pointer user_data)
      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

      public void foreachNode(Tree.OnTraverseNodeFunc func, @Nullable Pointer user_data)
      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

      public void insert(@Nullable Pointer key, @Nullable Pointer value)
      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 insert
      value - the value corresponding to the key
    • insertNode

      public ch.bailu.gtk.glib.TreeNode insertNode(@Nullable Pointer key, @Nullable Pointer value)
      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 insert
      value - the value corresponding to the key
      Returns:
      the inserted (or set) node.
    • lookup

      public Pointer lookup(@Nullable Pointer key)
      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

      public ch.bailu.gtk.glib.TreeNode lookupNode(@Nullable Pointer key)
      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

      public ch.bailu.gtk.glib.TreeNode lowerBound(@Nullable 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.

      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

      public 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

      public boolean remove(@Nullable Pointer key)
      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

      public void replace(@Nullable Pointer key, @Nullable Pointer value)
      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 insert
      value - the value corresponding to the key
    • replaceNode

      public ch.bailu.gtk.glib.TreeNode replaceNode(@Nullable Pointer key, @Nullable Pointer value)
      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 insert
      value - the value corresponding to the key
      Returns:
      the inserted (or set) node.
    • search

      public Pointer search(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 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 #GTree
      user_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 #GTree
      user_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

      public boolean steal(@Nullable Pointer key)
      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

      public ch.bailu.gtk.glib.TreeNode upperBound(@Nullable 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.

      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

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()