BBTree

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.

Constructors

this
this(GTree* gTree, bool ownedRef)

Sets our main struct and passes it to the parent class.

this
this(GCompareFunc keyCompareFunc)

Creates a new GTree

this
this(GCompareDataFunc keyCompareFunc, void* keyCompareData, GDestroyNotify keyDestroyFunc, GDestroyNotify valueDestroyFunc)

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

this
this(GCompareDataFunc keyCompareFunc, void* keyCompareData)

Creates a new GTree with a comparison function that accepts user data. See g_tree_new() for more details.

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Members

Functions

destroy
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_
void foreach_(GTraverseFunc func, void* userData)

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.

getBBTreeStruct
GTree* getBBTreeStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

height
int height()

Gets the height of a GTree

insert
void insert(void* key, void* value)

Inserts a key/value pair into a GTree

lookup
void* lookup(void* 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).

lookupExtended
bool lookupExtended(void* lookupKey, void* origKey, void* value)

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().

nnodes
int nnodes()

Gets the number of nodes in a GTree

ref_
BBTree ref_()

Increments the reference count of tree by one.

remove
bool remove(void* key)

Removes a key/value pair from a GTree

replace
void replace(void* key, void* value)

Inserts a new key and value into a GTree similar to g_tree_insert(). 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.

search
void* search(GCompareFunc searchFunc, void* userData)

Searches a GTree using search_func.

steal
bool steal(void* key)

Removes a key and its associated value from a GTree without calling the key and value destroy functions.

traverse
void traverse(GTraverseFunc traverseFunc, GTraverseType traverseType, void* userData)

Calls the given function for each node in the GTree

unref
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.

Variables

gTree
GTree* gTree;

the main Gtk struct