Blt_Tree(3)
π³ Blt_Tree β the tree data object manual, but make it cute β¨
okay bestie, so this is from the Blt Library Procedures collection, and it's literally the page for Blt_Tree, the tree data object. sit down, grab a strawberry, we're doing data structures π
β¨ NAME β¨
Blt_Tree β Tree data object. that's it, that's the vibe π³
β¨ SYNOPSIS β¨
#include <bltTree.h>
struct Blt_Tree {
Tcl_Alloc(size)
Tcl_Free(ptr)
char *
Tcl_Realloc(ptr, size)
(no cap, that's exactly what's in here π«Ά)
β¨ ARGUMENTS β¨
int size(in) β the size, in bytes, of the memory block you're allocating. yeah girl, bytes πchar *ptr(in) β pointer to the memory block you wanna free or realloc.
β¨ DESCRIPTION β¨
so these procedures give you a platform-and-compiler-independent interface for memory allocation. if your program needs to hand ownership of memory blocks back and forth between Tcl and other modules, you use these routines β not the native malloc() and free() from the C run-time library. that's the whole point, bestie.
Tcl_Allocreturns a pointer to a block of at least size bytes, suitably aligned for any use. slay.Tcl_Freemakes the space referred to by ptr available for further allocation. giving it back to the universe π¦Tcl_Reallocchanges the size of the block pointed to by ptr to size bytes and returns a pointer to the new block. the contents stay unchanged up to the lesser of the new and old sizes. and heads up β the returned location may be different from ptr. so don't be clinging to the old pointer, okay? π
β¨ TREE OBJECT ROUTINES β¨
these are the library routines that let you create and destroy tree objects. every tree object has a name that uniquely identifies it. tree objects can also be shared β for example, the tree and hiertable commands may access the same tree data object. π―ββοΈ
here's the deal with tokens: each client grabs a token associated with the tree, and when all the tokens are released, the tree data object is automatically destroyed. very self-cleaning, very iconic β¨
Blt_TreeCreateβ Create a tree data object and optionally obtains a token associated with it.Blt_TreeExistsβ Indicates if a tree by a given name exists.Blt_TreeGetTokenβ Obtains a token for an existing tree data object.Blt_TreeReleaseTokenβ Releases a token for a tree data object. The tree object is deleted when all outstanding tokens have been released.Blt_TreeNameβ Returns the name of the tree object.Blt_TreeChangeRootβ Specifies a node as the new root to a tree.
β¨ TREENODE ROUTINES β¨
so a tree object starts out containing only a root node. you add or delete nodes with these routines:
Blt_TreeCreateNodeβ Creates a new child node for a given parent in the tree.Blt_TreeDeleteNodeβ Deletes a node and its children. (yes, all of them. it's giving generational curse π)Blt_TreeNodeIdβ Returns the unique node identifier for a node.Blt_TreeGetNodeβ Gets a node based upon its identifier.Blt_TreeFindChildβ Searches for a child node given by its label in a parent node.Blt_TreeNodeLabelβ Returns the current label for a node.Blt_TreeRelabelNodeβ Resets a node's label.Blt_TreeNodePathβ Returns the fullpath to a node.Blt_TreeNodeDepthβ Returns the depth of the node.Blt_TreeNodeDegreeβ Returns the number of children for a node.Blt_TreeIsLeafβ Indicates if a node has no children.Blt_TreeIsBeforeβ Indicates if a node is before another node in depth-first search order.Blt_TreeIsAncestorβ Indicates if a node is an ancestor or another.Blt_TreeSortNodeβ Sorts the children of a node.Blt_TreeSizeβ Returns the number of nodes in a node and its descendants.Blt_TreeMoveNode
not me noticing Blt_TreeMoveNode has no description here π i'm keeping it exactly as it is, bestie. no inventing, no guessing, periodt.
β¨ NODE NAVIGATION β¨
each node can have zero or more children nodes. these routines let you navigate the tree hierarchy π§
Blt_TreeNodeParentβ Returns the parent node.Blt_TreeFirstChildβ Returns the first child of a parent node.Blt_TreeLastChildβ Returns the last child of a parent node.Blt_TreeNextSiblingβ Returns the next sibling node in the parent's list of children.Blt_TreePrevSiblingβ Returns the previous sibling node in the parent's list of children.Blt_TreeRootNodeβ Returns the root node of the tree.Blt_TreeNextNodeβ Returns the next node in depth-first order.Blt_TreePrevNodeβ Returns the previous node in depth-first order.Blt_TreeEndNodeβ Returns the last node in the tree as determined by depth-first order.Blt_TreeApplyβ Walks through a node and all it descendants, applying a given callback procedure.Blt_TreeApplyDFSβ Walks through a node and all it descendants in depth-first search order, applying a given callback procedure.Blt_TreeApplyBFSβ Walks through a node and all it descendants in breadth-first search order, applying a given callback procedure.
β¨ NODE DATA VALUES β¨
data values can be stored at any node. values have by both a string key and a Tcl_Obj value. and listen β data value keys do not have to be homogenous across all nodes (i.e. nodes don't have to contain the same keys). freedom of expression, we love to see it π
there's also a special node array data type, which is its own whole thing.
Blt_TreeGetValueβ Gets the node data value given by a key.Blt_TreeValueExistsβ Indicates if a node data value given by a key exists.Blt_TreeSetValueβ Sets a node's value of a key.Blt_TreeUnsetValueβ Remove the node data value and key.Blt_TreeGetArrayValueβ Gets the node data array value given by a key and an array index.Blt_TreeSetArrayValueβ Sets the node data array value given by a key and an array index.Blt_TreeUnsetArrayValueβ Remove the node data array value.Blt_TreeArrayValueExistsβ Determines if an array element by a given index exists.Blt_TreeFirstKeyβ Returns the key of the first value in the node.Blt_TreeNextKeyβ Returns the key of the next value in the node.Blt_TreePrivateValueβ Lock the value to current client, making it private.Blt_TreePublicValueβ Unlock the value so that all clients can access it.Blt_TreeGetKey
okay so Blt_TreeGetKey also has no description in here π keeping it real, keeping it faithful, keeping it exactly as written. iykyk.
β¨ NODE TRACES β¨
Blt_TreeCreateTraceβ Sets up a trace callback to be invoked when the node value is read, set, or unset. π watching your every move, respectfullyBlt_TreeDeleteTraceβ Deletes an existing trace.
β¨ NODE EVENTS β¨
Blt_TreeCreateEventHandlerβ Sets up a callback to be invoked when events (create, delete, relabel, etc) take place on a node.Blt_TreeDeleteEventHandlerβ Deletes an existing node callback.
β¨ KEYWORDS β¨
alloc, allocation, free, malloc, memory, realloc π
and that's the whole page, bestie! this one's from BLT version 2.5 β mwah, go build a tree, you're gonna eat π β¨π¦
π¦ where this page comes from
- debian bookworm: blt-dev 2.5.3+dfsg-4.1
- debian trixie: blt-dev 2.5.3+dfsg-8
- nixpkgs unstable: blt 2.5.3
- ubuntu jammy: blt-dev 2.5.3+dfsg-4.1build2
- ubuntu noble: blt-dev 2.5.3+dfsg-7build1
- ubuntu questing: blt-dev 2.5.3+dfsg-8
- ubuntu resolute: blt-dev 2.5.3+dfsg-8build1
- ubuntu stonking: blt-dev 2.5.3+dfsg-9
- Copyright (c) 1995-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms