From WikiChip
Difference between revisions of "mirc/commands/hadd"
< mirc‎ | commands

Line 1: Line 1:
 
{{mirc title|/hadd Command}}
 
{{mirc title|/hadd Command}}
The '''/hadd command''' inserts a new key/value pair to the hash table by the <nowiki><table></nowiki> name. If a value already exists for that key, the old value is replaced. If the table does not exist, the -m switch can be used to create the table however it will use the default value of 100 buckets, this may or may not be suitable depending on your table size. See {{mIRC|/hmake}} for more details.
+
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 [-mNszu#] <nowiki><table></nowiki> <key> [value]
+
  /hadd   [-m[N]szuNk] <nowiki><table></nowiki> <item> [value]
  /hadd -b[cmNszu#] <nowiki><table></nowiki> <key> <&bvar>
+
  /hadd -b[cm[N]szuNk] <nowiki><table></nowiki> <item> <&bvar>
 
 
 
== Switches ==
 
== Switches ==
* '''-mN''' - Creates the hash table if it does not exist, you can specify N for the number of bucket.
+
* '''-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
* '''-z''' - Decreases the value by 1.0 every second; stops at zero
 
* '''-u#''' - Removes the key/value after # seconds
 
* '''-k''' - Keeps the remaining time left from the -u# switch (undocumented in help file)
 
 
 
== 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
* '''<key>''' - The key associated with the value
+
* '''<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 ==
== Example ==
 
 
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 ==
* [[List of commands - mIRC|List of commands]]
+
{{collist
* [[List of identifiers - mIRC|List of identifiers]]
+
|count = 3
* {{mIRC|$hfind}}
+
|style = width: 60%; display: inherit;
* {{mIRC|$hget}}
+
|
* {{mIRC|/hdec}}
+
* {{mIRC|/hmake}}
* {{mIRC|/hdel}}
 
 
* {{mIRC|/hfree}}
 
* {{mIRC|/hfree}}
* {{mIRC|/hinc}}
 
 
* {{mIRC|/hload}}
 
* {{mIRC|/hload}}
* {{mIRC|/hmake}}
 
 
* {{mIRC|/hsave}}
 
* {{mIRC|/hsave}}
{{mIRC command list}}
+
* {{mIRC|/hdel}}
 
+
* {{mIRC|/hinc}}
[[Category:mIRC commands|hadd command - mIRC]]
+
* {{mIRC|/hdec}}
 +
* {{mIRC|Hash Tables}}
 +
* {{mIRC|$hget}}
 +
* {{mIRC|$hfind}}
 +
}}

Revision as of 12:11, 13 June 2018

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.

See also