19.0.0 released Nov 08, 2023
Delete tree

Purpose: Delete a node from a tree.

delete-tree <tree> key <key> \
    [ status [ define ] <status> ] \
    [ value [ define ] <value> ] \
    [ old-key [ define ] <old key> ]

delete-tree will search for <key> and if found, delete its node and set optional <status> (in "status" clause) to VV_OKAY. If <key> is not found, <status> will be VV_ERR_EXIST.

The key of the deleted node can be obtained in optional "old-key" clause in <old key> string; while its value in <value> in optional "value" clause, which can be a pointer of any type. Even though the value of <old key> will match <key> when deletion is successful, the two pointers may differ. Thus you may want to obtain <old key> if you need to release memory for the key, though in many cases you don't need to (see memory-handling). If <status> is not VV_OKAY, <value> and <old key> are unchanged.

Note that <status>, <value> and <old key> can be created with optional "define".
Examples
Delete node with key "123", and obtain its value and (the original) key.
char *k = "123";
delete-tree mytree key k value define val old-key define old_k status define st
if (st != VV_OKAY){
   @Could not find key <<p-out k>>
   exit-request
}
// delete the original key and value
delete-mem old_k
delete-mem val
@Deleted key <<p-out k>> with value <<p-out val>>

See also
Tree search
delete-tree  
get-tree  
new-tree  
purge-tree  
read-tree  
use-cursor  
write-tree    
See all
documentation


You are free to copy, redistribute and adapt this web page (even commercially), as long as you give credit and provide a dofollow link back to this page - see full license at CC-BY-4.0. Copyright (c) 2019-2023 Dasoftver LLC. Vely and elephant logo are trademarks of Dasoftver LLC. The software and information on this web site are provided "AS IS" and without any warranties or guarantees of any kind. Icons from table-icons.io copyright Paweł Kuna, licensed under MIT license.