From WikiChip
Difference between revisions of "mirc/commands/hadd"
Maroonbells (talk | contribs) |
|||
Line 1: | Line 1: | ||
{{mirc title|/hadd Command}} | {{mirc title|/hadd Command}} | ||
− | The '''/hadd | + | The '''/hadd''' command inserts a new item/value pair in the hash table by the <nowiki><table></nowiki> name. If that item name already exists, its old value is replaced. If the table does not exist, the -m switch can be used to create the table however it defaults to have 100 buckets, which may or may not be suitable depending on your table size. See {{mIRC|/hmake}} for more details. |
== Synopsis == | == Synopsis == | ||
− | /hadd [- | + | /hadd [-m[N]szuNk] <nowiki><table></nowiki> <item> [value] |
− | /hadd -b[ | + | /hadd -b[cm[N]szuNk] <nowiki><table></nowiki> <item> <&bvar> |
− | |||
== Switches == | == Switches == | ||
− | * '''- | + | * '''-m[N]''' - Creates the hash table if it does not exist, you can optionally specify N for the number of buckets. If table already exists, this does not change the number of buckets. |
* '''-s''' - Displays the assignment information | * '''-s''' - Displays the assignment information | ||
+ | * '''-z''' - Decreases the value by 1.0 every second; unsets at zero | ||
+ | * '''-uN''' - Removes the item/value after N seconds | ||
+ | * '''-k''' - Keeps the remaining time left from the -uN switch (undocumented in help file) | ||
* '''-b''' - Treats the value as a binary variable | * '''-b''' - Treats the value as a binary variable | ||
* '''-c''' - Truncates the &bvar at the first null value | * '''-c''' - Truncates the &bvar at the first null value | ||
− | |||
− | |||
− | |||
− | |||
== Parameters == | == Parameters == | ||
− | |||
* '''<nowiki><table></nowiki>''' - The handle name of the table to operate on | * '''<nowiki><table></nowiki>''' - The handle name of the table to operate on | ||
− | * '''< | + | * '''<item>''' - The item key associated with the value |
− | * '''[value]''' - The value associated with the key | + | * '''[value]''' - The optional value associated with the item key |
− | * '''<&bvar>''' - The binary variable value associated with the key | + | * '''<&bvar>''' - The binary variable value associated with the item key |
− | + | == Examples == | |
− | == | ||
A basic usage for a hash table. | A basic usage for a hash table. | ||
<syntaxhighlight lang="mIRC">; call the setup once | <syntaxhighlight lang="mIRC">; call the setup once | ||
Line 39: | Line 35: | ||
alias abbr return $hget(abbr, $1)</syntaxhighlight> | alias abbr return $hget(abbr, $1)</syntaxhighlight> | ||
+ | <source lang="mIRC"> | ||
+ | //hadd -sm50 test time $ctime | ||
+ | * Creates item named "time" in hashtable "test". If table "test" did not already exist, that table is first created with 50 buckets. If it already existed, the number of buckets remains the same, and any other existing item/data are not affected. | ||
+ | |||
+ | /hadd -z test countdown 123.45 | ||
+ | * Creates item named "countdown" with the value 123.45 then decrements it by 1 each second, preserving fractions, as long as the number remains positive. If decrementing results in the value being zero or negative, the item is unset. At creation, the item is given the unset value of 2^31-1 seconds in the future, regardless of the value. This item is not guaranteed to be unset 124 seconds from now, because /hinc or /hdec used with the -k switch can change the value while preserving the countdown behavior. | ||
+ | |||
+ | /hadd -u30 Voting Open 1 | ||
+ | * creates an item named "Open" in existing table "Voting" containing the value 1, which unsets 30 seconds in the future. | ||
+ | |||
+ | /hadd -k Voting Open 11 | ||
+ | If the item does not already exist, the -k switch has no effect. If the item already exists, and if it has a non-zero number of seconds to be unset in the future, the item's data value is updated to 11 without altering the unset countdown. If the item had been created using the -z switch, it retains the non-zero countdown for unset (in excess of 2 billion seconds) but loses the property of decrementing by 1 each second. | ||
+ | |||
+ | //hfree -w test | hadd -mz test item1 33 | hadd test item2 44 | hadd -u30 test item3 55 | hsave -u test deleteme.txt | ||
+ | * All 3 items written to disk. If edited to remove hsave's -u switch, only item2 is written to disk because -z gives item1 an unset property over 2 billion seconds in the future, and item3 also has an unset property for 30 seconds in the future. | ||
+ | |||
+ | //bset &var1 1 97 98 99 00 100 101 | hadd -smb test bintest &var1 | noop $hget(test,bintest,&var2) | echo -a $bvar(&var2,0) $bvar(&var2,1-) | ||
+ | * after the &var1 is created, the 6 binary bytes are added to table 'test' as item 'bintest'. &var2 contains 6 bytes including the ASCII 0x00. | ||
+ | |||
+ | //bset &var1 1 97 98 99 00 100 101 | hadd -smbc test bintest &var1 | noop $hget(test,bintest,&var2) | echo -a $bvar(&var2,0) $bvar(&var2,1-) | ||
+ | * same except the contents of item 'bintest' is truncated, containing only the 3 bytes prior to the first 0x00 byte if any. | ||
+ | |||
+ | //hfree -w test | hadd -m test $ $+ version $+ $chr(32) $+ foo % $+ variable | echo 4 -a item= $hget(test,1).item data= $hget(test,1).data | ||
+ | * There is little restriction on the name given to items, but the 1st and 2nd space-delimited parameters are the table and item names, and everything beyond that is the data | ||
+ | |||
+ | //hfree -w test | hadd -m test itemname | echo 4 -a item= $hget(test,1).item data= $hget(test,1).data | ||
+ | * As with /set and /var, there is not a restriction against creating itemnames with null content. | ||
+ | </source> | ||
== Compatibility == | == Compatibility == | ||
{{mIRC compatibility|5.8}} | {{mIRC compatibility|5.8}} | ||
− | |||
== See also == | == See also == | ||
− | + | {{collist | |
− | + | |count = 3 | |
− | + | |style = width: 60%; display: inherit; | |
− | + | | | |
− | + | * {{mIRC|/hmake}} | |
− | * {{mIRC|/ | ||
* {{mIRC|/hfree}} | * {{mIRC|/hfree}} | ||
− | |||
* {{mIRC|/hload}} | * {{mIRC|/hload}} | ||
− | |||
* {{mIRC|/hsave}} | * {{mIRC|/hsave}} | ||
− | {{mIRC | + | * {{mIRC|/hdel}} |
− | + | * {{mIRC|/hinc}} | |
− | + | * {{mIRC|/hdec}} | |
+ | * {{mIRC|Hash Tables}} | ||
+ | * {{mIRC|$hget}} | ||
+ | * {{mIRC|$hfind}} | ||
+ | }} |
Revision as of 11:11, 13 June 2018
Commands & Identifiers
Basics
Events
Matching Tools
Data Storage
Control Structures
GUI Scripting
Sockets
Advanced Scripting
Additional Resources
Security
Other
The /hadd command inserts a new item/value pair in the hash table by the <table> name. If that item name already exists, its old value is replaced. If the table does not exist, the -m switch can be used to create the table however it defaults to have 100 buckets, which may or may not be suitable depending on your table size. See /hmake for more details.
Synopsis
/hadd [-m[N]szuNk] <table> <item> [value] /hadd -b[cm[N]szuNk] <table> <item> <&bvar>
Switches
- -m[N] - Creates the hash table if it does not exist, you can optionally specify N for the number of buckets. If table already exists, this does not change the number of buckets.
- -s - Displays the assignment information
- -z - Decreases the value by 1.0 every second; unsets at zero
- -uN - Removes the item/value after N seconds
- -k - Keeps the remaining time left from the -uN switch (undocumented in help file)
- -b - Treats the value as a binary variable
- -c - Truncates the &bvar at the first null value
Parameters
- <table> - The handle name of the table to operate on
- <item> - The item key associated with the value
- [value] - The optional value associated with the item key
- <&bvar> - The binary variable value associated with the item key
Examples
A basic usage for a hash table.
; call the setup once ; /abbr_setup ; ; //echo -a $abbr(lol) ; alias abbr_setup { ; populate the table, create it if it does not exist hadd -m abbr lol laughing out load hadd abbr omg oh my gosh hadd abbr lmao laughing my a?? off hadd abbr brb be right back } ; get the abbreviation alias abbr return $hget(abbr, $1)
//hadd -sm50 test time $ctime * Creates item named "time" in hashtable "test". If table "test" did not already exist, that table is first created with 50 buckets. If it already existed, the number of buckets remains the same, and any other existing item/data are not affected. /hadd -z test countdown 123.45 * Creates item named "countdown" with the value 123.45 then decrements it by 1 each second, preserving fractions, as long as the number remains positive. If decrementing results in the value being zero or negative, the item is unset. At creation, the item is given the unset value of 2^31-1 seconds in the future, regardless of the value. This item is not guaranteed to be unset 124 seconds from now, because /hinc or /hdec used with the -k switch can change the value while preserving the countdown behavior. /hadd -u30 Voting Open 1 * creates an item named "Open" in existing table "Voting" containing the value 1, which unsets 30 seconds in the future. /hadd -k Voting Open 11 If the item does not already exist, the -k switch has no effect. If the item already exists, and if it has a non-zero number of seconds to be unset in the future, the item's data value is updated to 11 without altering the unset countdown. If the item had been created using the -z switch, it retains the non-zero countdown for unset (in excess of 2 billion seconds) but loses the property of decrementing by 1 each second. //hfree -w test | hadd -mz test item1 33 | hadd test item2 44 | hadd -u30 test item3 55 | hsave -u test deleteme.txt * All 3 items written to disk. If edited to remove hsave's -u switch, only item2 is written to disk because -z gives item1 an unset property over 2 billion seconds in the future, and item3 also has an unset property for 30 seconds in the future. //bset &var1 1 97 98 99 00 100 101 | hadd -smb test bintest &var1 | noop $hget(test,bintest,&var2) | echo -a $bvar(&var2,0) $bvar(&var2,1-) * after the &var1 is created, the 6 binary bytes are added to table 'test' as item 'bintest'. &var2 contains 6 bytes including the ASCII 0x00. //bset &var1 1 97 98 99 00 100 101 | hadd -smbc test bintest &var1 | noop $hget(test,bintest,&var2) | echo -a $bvar(&var2,0) $bvar(&var2,1-) * same except the contents of item 'bintest' is truncated, containing only the 3 bytes prior to the first 0x00 byte if any. //hfree -w test | hadd -m test $ $+ version $+ $chr(32) $+ foo % $+ variable | echo 4 -a item= $hget(test,1).item data= $hget(test,1).data * There is little restriction on the name given to items, but the 1st and 2nd space-delimited parameters are the table and item names, and everything beyond that is the data //hfree -w test | hadd -m test itemname | echo 4 -a item= $hget(test,1).item data= $hget(test,1).data * As with /set and /var, there is not a restriction against creating itemnames with null content.
Compatibility
Added: mIRC v5.8
Added on: 05 Sep 2000
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.