Store key/value pair into a hash table.
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.
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.