From WikiChip
Editing mirc/commands/hadd

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.

Latest revision Your text
Line 1: Line 1:
{{mirc title|/hadd Command}}
+
{{mirc title|/hadd Command}}{{mIRC menu}}
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.
+
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.
  
 
== Synopsis ==
 
== Synopsis ==
  /hadd   [-m[N]szuNk] <nowiki><table></nowiki> <item> [value]
+
  /hadd [-mszu#] <nowiki><table></nowiki> <key> [value]
  /hadd -b[cm[N]szuNk] <nowiki><table></nowiki> <item> <&bvar>
+
  /hadd -b[cmszu#] <nowiki><table></nowiki> <key> <&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.
+
* '''-m''' - Creates the hash table if it does not exist
 
* '''-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 and -z switches (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
* '''<item>''' - The item key associated with the value
+
* '''<key>''' - The key associated with the value
* '''[value]''' - The optional value associated with the item key
+
* '''[value]''' - The value associated with the key
* '''<&bvar>''' - The binary variable value associated with the item key
+
* '''<&bvar>''' - The binary variable value associated with the 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 35: Line 39:
 
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 | .timerX 5 1 echo 4 -a value $!hget(test,countdown) unsets in $!hget(test,countdown).unset
 
* 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 -zu3 test countdown 123.45 | .timerX 5 1 echo 4 -a value $!hget(test,countdown) unsets in $!hget(test,countdown).unset
 
* Same as above, except -u3 causes the item to unset 3 seconds in the future before it decements to zero.
 
 
//hadd -mu30 Voting Open 30 | echo 4 -a val $hget(voting,open) unset delay $hget(voting,open).unset | hadd -z Voting Open 10 | .timerX 5 1 echo 3 -a val $!hget(voting,open) unset delay $!hget(voting,open).unset
 
* Creates table "Voting" if it doesn't already exist, with default buckets 100. Creates an item named "Open" containing the value 1, which unsets 30 seconds in the future. Then it updates the variable to value 10, and -z resets the unset delay from 30 seconds to be 2^31-1 seconds in the future.
 
 
//hadd -mu30 Voting Open 30 | echo 4 -a val $hget(voting,open) unset delay $hget(voting,open).unset | hadd Voting Open 10 | .timerX 5 1 echo 3 -a val $!hget(voting,open) unset delay $!hget(voting,open).unset
 
* Same as above, except re-creating the variable without any switches resets the unset delay to 0, where it will not unset in the future.
 
 
//hadd -mu30 Voting Open 30 | hdel Voting Open | .timerX 5 1 hadd -ku99 Voting Open $!asctime $(|) echo 3 -a val $!hget(voting,open) unset delay $!hget(voting,open).unset
 
* -k is ignored the first time because the item does not exist, causing the item to be given a 99 seconds delay. But after that, the item having a non-zero unset delay means the -k switch causes the -u99 to be ignored, preserving the unset delay of an existing item. If the item had been created using the -z switch, it retains the non-zero unset delay (in excess of 2 billion seconds) but loses the property of decrementing by 1 each second if -z is not used again.
 
 
//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 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 ==
* {{mIRC|/hmake}}
+
* [[List of commands - mIRC|List of commands]]
 +
* [[List of identifiers - mIRC|List of identifiers]]
 +
* {{mIRC|$hfind}}
 +
* {{mIRC|$hget}}
 +
* {{mIRC|/hdec}}
 +
* {{mIRC|/hdel}}
 
* {{mIRC|/hfree}}
 
* {{mIRC|/hfree}}
 +
* {{mIRC|/hinc}}
 
* {{mIRC|/hload}}
 
* {{mIRC|/hload}}
 +
* {{mIRC|/hmake}}
 
* {{mIRC|/hsave}}
 
* {{mIRC|/hsave}}
* {{mIRC|/hdel}}
+
{{mIRC command list}}
* {{mIRC|/hinc}}
+
 
* {{mIRC|/hdec}}
+
[[Category:mIRC commands|hadd command - mIRC]]
* {{mIRC|Hash Tables}}
 
* {{mIRC|$hget}}
 
* {{mIRC|$hfind}}
 

Please note that all contributions to WikiChip may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see WikiChip:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)