Vely logo Empower C
install  tutorials  examples
documentation  license  about

12.1.0 released on Sep 19, 2022

write-hash



PURPOSE:


Store key/value pair into a hash table.

SYNTAX:


write-hash <hash> \
    key <key> \
    value <value> \
    [ status [ define ] <status> ] \
    [ old-value [ define ] <old value> ]


DESCRIPTION:


write-hash will store <key> (in "key" clause) with <value> (specified in "value" clause) into hash table <hash>, which must be created with new-hash. <key> is a string and <value> can be a pointer of any type, allowing storage of any kind of data. <key> and <value> must not go out of scope or be freed while the hash is used - if necessary, store a copy (see copy-string for strings).

If <key> already exists in the hash table, then the pointer to old value associated with it is returned in the optional <old value> (in "old-value" clause) - in this case the optional number <status> (in "status" clause) has a value of VV_ERR_EXIST. If <key> did not exist, <status> will be VV_OKAY and <old value> is NULL. Both <status> and <old value> can be created with "define" clause.

EXAMPLES:


Writing data to hash:
new-hash define h size 1000
write-hash h key "mykey" value "some data"

Writing new value with the same key and obtaining the previous value (which is "some data"):
write-hash h key "mykey" value "new data" status define st old-value define od
if (st == VV_ERR_EXIST) {
    @Previous value for this key is <<p-out od>>
}

See read-hash for more examples.

SEE ALSO:


Hash table ( get-hash   new-hash   purge-hash   read-hash   resize-hash   write-hash  )  SEE ALL (documentation)



Copyright (c) 2022 DaSoftver LLC. Vely is a trademark of Dasoftver LLC. The software and information herein are provided "AS IS" and without any warranties or guarantees of any kind. Icons copyright PaweĊ‚ Kuna licensed under MIT. This web page is licensed under CC-BY-SA-4.0.