GOLF(2gg)
β¨ NAME β¨
read-hash β (hash) π
π― PURPOSE π―
Bestie, we're getting data from a hash. That's it, that's the whole vibe. β¨
π§ SYNTAX π§
Okay so here's the tea, both ways you can do this:
// Random access to hash data:
read-hash <hash> \
key <key> \
value <value> \
[ delete [ <delete> ] ] \
[ status <status> ]
// Sequential access to hash data:
read-hash <hash> traverse begin
read-hash <hash> traverse \
key <key> \
value <value> \
[ delete [ <delete> ] ] \
[ status <status> ] \
π DESCRIPTION π
πΈ WITHOUT TRAVERSE CLAUSE πΈ
So like, read-hash will obtain an element from <hash>, which is a string <value> (in the "value" clause) based on a string <key> (in the "key" clause). And where did <hash> come from? It was created by new-hash. Iconic. π
You can also delete an element from the hash by using the "delete" clause β the <value> is still obtained though it is no longer in the hash. Not me deleting it and still handing you the goods π. The hash element gets deleted if the "delete" clause is used without boolean variable <delete>, or if <delete> evaluates to true. No cap.
If no <key> was found in the hash, <status> number (in the "status" clause) is GG_ERR_EXIST and <value> is unchanged, otherwise <status> is GG_OKAY. Periodt. π―
π¦ WITH TRAVERSE CLAUSE π¦
read-hash with the "traverse" clause obtains <key> and <value> of the current element, and then positions to the next one. Very main character energy, moving through the hash like it owns the place. You can also delete this element from the hash by using the "delete" clause β the <key> and <value> are still obtained though the element is no longer in the hash. The hash element is deleted if the "delete" clause is used without boolean variable <delete>, or if <delete> evaluates to true.
Use the "begin" clause to position at the very first element. This is useful if you wish to get all the key/value pairs from a hash β but heads up bestie, note they are not extracted in any particular order. π« When there are no more elements, <key> and <value> are unchanged and <status> number (in the "status" clause) is GG_ERR_EXIST, otherwise <status> is GG_OKAY.
You may search, add or delete elements while traversing a hash, and this will be reflected in all elements not yet traversed. Slay, live your truth, just know the future elements are watching. π
π EXAMPLES π
Okay so in this example, a new hash is created, a key/value pair is written to it, and then the value is obtained and the element deleted; return status is checked. Classic. π
// Create new hash
new-hash h
// Write to a hash
write-hash h key "X0029" value "some data"
// Read from a hash
read-hash h key "X0029" value res status f delete
if-true f equal GG_ERR_EXIST
@No data in the hash!
else-if
@Deleted value is <<print-out res>>
end-if
And the following will traverse the entire hash and display all the data. Full tour, no skips. π
// Position at the beginning of the hash
read-hash h traverse begin
start-loop
// Get elements, one by one, until NULL returned as a key
read-hash h traverse key k value r status f
if-true f equal GG_ERR_EXIST
break;
end-if
print-format "Key [%s] data [%s]\n", k, r
end-loop
π SEE ALSO π
Hash
get-hash new-hash purge-hash read-hash resize-hash write-hash β See all documentation π
And that's the whole page, bestie!! π This was the GOLF(2gg) Development page, brought to you by $VERSION on $DATE. Go forth and read those hashes, you absolute icon. π
β¨π¦
π¦ 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