Gjsify LogoGjsify Logo

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.

record

Hierarchy

  • Tree

Index

Constructors

Properties

name: string

Methods

  • destroy(): void
  • 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.

    Returns void

  • height(): number
  • 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 number

  • insert(key: object, value: object): void
  • 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: object

      the key to insert

    • value: object

      the value corresponding to the key

    Returns void

  • 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: object

      the key to insert

    • value: object

      the value corresponding to the key

    Returns GLib.TreeNode

  • lookup(key: object): object
  • 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: object

      the key to look up

    Returns object

  • lookupExtended(lookupKey: object): [boolean, object, object]
  • 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 g_tree_remove().

    Parameters

    • lookupKey: object

      the key to look up

    Returns [boolean, object, object]

  • 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: object

      the key to look up

    Returns GLib.TreeNode

  • 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: object

      the key to calculate the lower bound for

    Returns GLib.TreeNode

  • nnodes(): number
  • Increments the reference count of tree by one.

    It is safe to call this function from any thread.

    Returns GLib.Tree

  • remove(key: object): boolean
  • 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: object

      the key to remove

    Returns boolean

  • removeAll(): void
  • Removes all nodes from a #GTree and destroys their keys and values, then resets the #GTreeā€™s root to %NULL.

    Returns void

  • replace(key: object, value: object): 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.

    Parameters

    • key: object

      the key to insert

    • value: object

      the value corresponding to the key

    Returns void

  • 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: object

      the key to insert

    • value: object

      the value corresponding to the key

    Returns GLib.TreeNode

  • steal(key: object): boolean
  • 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: object

      the key to remove

    Returns boolean

  • unref(): void
  • 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.

    Returns void

  • 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: object

      the key to calculate the upper bound for

    Returns GLib.TreeNode

  • 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

    • keyCompareFunc: CompareDataFunc

      qsort()-style comparison function

    • keyDestroyFunc: GLib.DestroyNotify

      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

    Returns GLib.Tree

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method