Hash Tables Tutorial — File Browser

HashTablesTutorialv1.0 / HashTablesTutorialv1.0 / HT-Tutorial / Hash Tables / howiuse-use.htm

howiuse-use.htm — 7.12 KB — Download this file

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Hash Tables - How I Use</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {
	font-family: Tahoma;
	font-size: 12px;
}
.style2 {color: #0000CC}
.style3 {
	color: #0000FF;
	font-weight: bold;
}
.style4 {color: #0000FF}
.style5 {
font-family: Tahoma;
font-size: 24px;
-->
</style>
</head>

<body bgcolor="#F2FDFF" text="#000000">


<div align="center">
  <table width="500" border="0">
    <tr>
      <th width="500" scope="col"><div align="left">
        <p align="center" class="style5"><u>HOW I USE</u></p>
        <p align="center" class="style5">&nbsp;</p>
        <p align="left" class="style1">Theres two types of way i use hash tables to store data. Now I'll use an example to explain both ways. The example I'll use is codeing from my own channel protection. </p>
        <p align="left" class="style5">FIRST WAY </p>
        <p align="left" class="style1">The first way is , a single data word that defines something in the feature in my script.</p>
        <p align="left" class="style1">Meaning for example in my own channel protection, the edit field where someone would define how many texts before the feature kicks/bans user for flooding.</p>
        <p align="left" class="style1">I store this in the main hash table i use. Kinda like the variables section of mirc</p>
        <p align="left" class="style2">Example: </p>
        <p align="left" class="style2">on *:dialog:jacp:edit:*:{<br>
if ( $did == 21 ) { hadd system cp.t.count $did(21).text | system.update }</p>
        <p align="left" class="style1">When someone types in the edit field. this auto writes to the hash table named system. And it adds the item name <span class="style2">&quot;cp.t.count&quot;</span> and the data associated with the item, which is whatever is in that edit field. </p>
        <p align="left" class="style1">The system.update is my alias to save the hash table. Read the section related to saving to see more information on that. </p>
        <p align="left" class="style1">To return this information , on my init event for the channel protection, i have the line below in this event to add the information into the edit field again.</p>
        <p align="left" class="style2"> did -a jacp 21 $hget(system,cp.t.count) </p>
        <p align="left" class="style1">You should already know about $hget, if not go back and read the previous section. </p>
        <p align="left" class="style1">If i wished to delete this item from the hash table all together, I would just type the following or have this line on a button event in a dialog. </p>
        <p align="left" class="style2">/hdel system cp.t.count</p>
        <p align="left" class="style1">You don't need to type the data associated with the item to delete, just the item you wish to delete.</p>
        <p align="left" class="style5">SECOND WAY </p>
        <p align="left" class="style1">The second way i use hash tables is, say in my channel protection, i have a channels list that this feature will protect. So i have a line in my main hash table for this and it reads like below</p>
        <p align="left" class="style2">ITEM: cp.chans DATA: chan1 chan2 chan3 </p>
        <p align="left" class="style1">As you can see, i have more than one field in my data information here. Hense it's not as simple to adjust this item line as it is with the above way.</p>
        <p align="left" class="style1">I use 3 aliases to do the following , one allows me to add channel, one allows me to delete channel and one allows me to input information into a listbox</p>
        <p align="left" class="style2">alias cp.add.chan {<br>
var %cur = $hget(system,cp.chans)<br>
var %new.chans = %cur $did(79).text<br>
hadd system cp.chans %new.chans<br>
did -r jacp 79<br>
system.update<br>
cp.get.chans<br>
}</p>
        <p align="left" class="style1">This alias above as you can see, sets a temp variable called <span class="style2">%cur</span> , with the data stored in the item marked <span class="style2">cp.chans </span></p>
        <p align="left" class="style1">Then i set another temp variable called<span class="style2"> %new.chans</span> . This contains the current listed channels stored in the variable <span class="style2">%cur</span> and also the new channel that has been inputed in the edit field within the dialog. </p>
        <p align="left" class="style1">Then i add the new information to the hash table named system</p>
        <p align="left" class="style1">You will notice i don't delete previous information, thats cause i rarely have to delete a line from a hash table. As when you readd, it just auto removes previous information stored in <span class="style2">cp.chans</span> item line and adds the new information into there </p>
        <p align="left" class="style1">the cp.get.chans is the alias i use to return the information associated with the cp.chans item line and that is shown below</p>
        <p align="left" class="style2">alias cp.get.chans {<br>
did -r jacp 82<br>
var %cur = $hget(system,cp.chans)<br>
var %i = 1<br>
while ( $gettok(%cur,%i,32) ) {<br>
var %chan = $ifmatch<br>
did -a jacp 82 %chan<br>
inc %i<br>
}<br>
}</p>
        <p align="left" class="style1">Now you see that <span class="style2">%cur</span> temp variable is set with the channel list again. Then i use a while loop along with $gettok to return the information. You can read about while loops and $gettok in mircs own help file. But you do have the above alias you can copy and paste into your remote and change to suit your needs.</p>
        <p align="left" class="style1">When I wish to delete a channel from my list , I use the alias below to do so</p>
        <p align="left" class="style2">alias cp.del.chan {<br>
var %cur = $hget(system,cp.chans)<br>
var %rem = $did(jacp,82).seltext<br>
var %new.chans = $remove(%cur,%rem)<br>
hadd system cp.chans %new.chans<br>
system.update<br>
cp.get.chans<br>
} </p>
        <p align="left" class="style1">Yet again, i set the temp variable <span class="style2">%cur</span> but this time i also set another variable <span class="style2">%rem</span> . This is the line that I have selected in the listbox which gets set here</p>
        <p align="left" class="style1">Then i use <span class="style2">$remove</span> command to remove the information stored in <span class="style2">%rem</span> from the channel list stored in <span class="style2">%cur</span> . Then obviouslly i readd to hash table and return the new information threw my <span class="style2">cp.get.chans</span> alias </p>
        <p align="left" class="style1">&nbsp;</p>
        <p align="left" class="style1">&nbsp; </p>
        <p align="left" class="style1">&nbsp;</p>
	    <p align="left" class="style1">&nbsp; </p>
	    <p align="left" class="style1">&nbsp; </p>
	    <p align="left" class="style1">&nbsp;</p>
	    <p align="left" class="style1">&nbsp; </p>
	    <p align="left" class="style1">&nbsp;</p>
	    <p align="left" class="style1">&nbsp;</p>
      </div></th>
    </tr>
  </table>
</div>
</body>
</html>