GOLF(2gg)
π GOLF(2gg) π
okay bestie, welcome to the GOLF manual, page GOLF(2gg), Development section β this one is literally all about use-cursor, and it's giving β¨tree iterationβ¨ energy, so grab a boba and let's go π§
πΈ NAME πΈ
use-cursor β (tree)
π PURPOSE π
Iterate to a lesser or greater key in a tree. that's it, that's the vibe π¦
β¨ SYNTAX β¨
use-cursor <cursor> ( current | get-lesser | get-greater ) \
[ key <key> ] \
[ value <value> ] \
[ update-value <update value> ] \
[ status <status> ]
π DESCRIPTION π
so use-cursor takes a <cursor> you already made earlier (peep read-tree, write-tree π) and uses it to iterate over tree nodes with lesser or greater key values. it can also get the keys and values of those nodes, and lowkey it can update their values too. multitasking queen π
π«Ά CURRENT NODE π«Ά
every <cursor> has a current node, right? that node gets computed first by using the current, get-lesser or get-greater clauses, and then all your other clauses get applied to it (think key, value and update-value). order matters, no cap.
the computation of a current node happens using the <cursor>'s "previous current node" β aka the current node right before use-cursor executes. here's the tea:
- if you use the
currentclause, the current node stays exactly the same as the previous current node. iconic, no notes π - if you use the
get-lesserclause, a node with a key that's the next lesser from the previous current becomes the new current β¬ οΈ - if you use the
get-greaterclause, a node with a key that's the next greater from the previous current becomes the new current β‘οΈ
if the new current node can be found, then your other use-cursor clauses get applied to it β like grabbing a <key> or a <value>, or doing an <update value>. but if, as a result of either of these clauses, the new current node cannot be found (for instance, there's literally no lesser or greater key in the tree π), then the current node will be unchanged and <status> (in the status clause) will be GG_ERR_EXIST.
π KEY, VALUE, UPDATING VALUE, STATUS π
okay so the key clause will obtain the key in a current node into the <key> string. the value of the current node can be obtained in <value> with the value clause β and yes, <value> is a string. the value of the current node can also be updated to <update value> in the update-value clause; <update value> is a string too. and here's the cute part: this update is performed after <value> has been retrieved, which lets you grab the previous value in the same statement. two birds, one statement π¦π¦
the status clause is how you get the <status> number, which is GG_ERR_EXIST if the new current node cannot be found β and in that case, the current node, <key> and <value> are all unchanged. otherwise, <status> is GG_OKAY. slay β
π₯ EXAMPLES π₯
the following will find a value with key "999", and then iterate in the tree to find all lesser values (in descending order):
set-string k = "999"
read-tree mytree equal k status st \
value val new-cursor cur
start-loop
if-true st equal GG_OKAY
@Value found is [<<print-out val>>] for key [<<print-out k>>]
use-cursor cur get-lesser status st value val key k
else-if
break-loop
end-if
end-loop
for more examples, see new-tree. π
π SEE ALSO π
- Tree
delete-tree get-tree new-tree purge-tree read-tree use-cursor write-tree
See all documentation
and that's a wrap, bestie π this lil page was served to you on $DATE, brought to you by version $VERSION, and yes it still says GOLF(2gg) at the bottom because some things never change π go forth and iterate, you absolute main character π
π¦ where this page comes from
- ubuntu questing: golf 601.4.41-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms