mIRC Homepage

/hren and /hcopy - Rename/Copy Hash Tables/Items

Posted By: PhireCoder

/hren and /hcopy - Rename/Copy Hash Tables/Items - 25/08/07 08:23 PM

Hey, First off, I'm new to the mIRC message boards, so if this has been suggested already I must be doing something wrong because I've done about 7 different searches for this and found nothing... Seems like someone would have thought of this before... or the search here must not work correctly...

/hren Rename Hash Tables.
/hren <table> [item] <new name>
* renames <table> to <new name>
* if [item] is specified, renames [item] to <new name>

and possibly...

/hcopy Copy item from 1 hash table to an other.
/hcopy [-m] <table1> [item] <table2> [item2]
* copies contents of <table1> to <table2>
* if [item] is specified, copies [item] from <table1> to <table2>.
* if [item2] is specified, copies [item] from <table1> to [item2] of <table2>.
* if -m is used, creates <table2> if it doesn't exist.
* if [item2] does not exist, creates [item2] automatically.
* <table2> can be <table1>
Posted By: Riamus2

Re: /hren and /hcopy - Rename/Copy Hash Tables/Items - 25/08/07 09:25 PM

I'm not entirely sure why you'd rename a hash table that you created, but I suppose it's not a bad command to have. For the item names, it would just cut 2 commands down to 1 command, so I'm not sure why you'd do that.

As far as copying, that's not difficult to do without any other commands.

/hadd Table2 Item1_or_Item2 $hget(Table1,Item1).data
Posted By: RusselB

Re: /hren and /hcopy - Rename/Copy Hash Tables/Ite - 25/08/07 09:42 PM

For renaming
Code:
/hsave <table> <file>
/hmake <table2> <size>
/hload <table2> <file>
/hfree <table>

Posted By: PhireCoder

Re: /hren and /hcopy - Rename/Copy Hash Tables/Ite - 25/08/07 10:04 PM

I know this is probably not a practical everyday use example but for instance:

I've coded an IRC Server in mIRC Script for testing purposes and when a client connects to the scripted server i assign the new connection a temp name e.g.
var %a = $+(Serv.Client.,$ticks)
sockaccept %a
I then create a hash table to store info about the new client.
hmake %a 10
hadd %a ip $sock(%a).ip
ect.
ect.
When the client sends the first nick command I then rename the client's socket to $+(Serv.Client.<nickname>)
It would therefor be useful to simply rename the hash table to $sockname which is Serv.Client.Nickname

This is my example however i'm sure there are other irc (client) related examples as well.
Posted By: PhireCoder

Re: /hren and /hcopy - Rename/Copy Hash Tables/Ite - 25/08/07 10:12 PM

I know there are workarounds.
And the workarounds are how i currently handle these situations.
However I think these commands would be simple to add into mIRC and think that there could be many practical script uses for these commands to make things easier / simpler / faster / better / more convenient.

For example if we didn't have /set, /unset, and %variables, we could use /writeini, and $readini (variables.ini).
However Global Variables are easier / simpler / faster / better / more convenient.

The fact that i think these would be simple to implement with little effort is the only reason i suggest them. Otherwise I wouldn't bother and would suggest everyone use workarounds.
Posted By: SladeKraven

Re: /hren and /hcopy - Rename/Copy Hash Tables/Ite - 27/08/07 01:48 PM

Both of these have been suggested before.

Hash Rename and the last post in this thread dating back to 03.
/hcopy - Copy hash tables
Posted By: PhireCoder

Re: /hren and /hcopy - Rename/Copy Hash Tables/Ite - 28/08/07 09:29 AM

SladeKraven, it doesn't seem as if those posts have gotten anywhere. I don't quite understand how these commands could not seem useful to observers of these posts, whereas several scripting sites would show differently, just about all scripting help sites show a handful of sniplets that do these functions, there are tons of partially redundent commands in mirc that do far less than these commands would offer...

Quote:

I'm not entirely sure why you'd rename a hash table that you created, but I suppose it's not a bad command to have.


I've given my example above however apparently alot more people than me find it useful, hence all the sniplets.

Quote:
For the item names, it would just cut 2 commands down to 1 command, so I'm not sure why you'd do that.


First off, it's a little more than 2 commands if you include error checking, Secondly I just thought it was only logical to include item renaming as part of the command. But besides that some scripts might contain alot of redundant item renaming thus cutting down the script by 50% or more. I would also like to point out the commands /hinc and /hdec, for the same reasons.. These commands cut down on 2 commands as well (not to mention tons of other commands which cut down on even less). And finally the true purpose of this command is to rename an entier hash table in such cases as the example I've given above, the item renaming is just a convenient side effect.

Quote:

As far as copying, that's not difficult to do without any other commands.

/hadd Table2 Item1_or_Item2 $hget(Table1,Item1).data


Same applies as above, there is also the possibility of what i call dynamic user templetes,in such case, one might want to copy entire hash tables. I could give an example but it's kinda lenghthy and might be confusing to most, so i won't bother. So anyway.. the current most common work around is to save the hash table as a file, then load into a new hash table.. This is obviously very inefficient. Also as DaveC pointed out on a previous post, this method does not work in such cases as the following:

Code:
bset &binvar 1000000 0 | hadd -mb table1 item1 &binvar
var %crlf = $crlf      | hadd -m table1 item2 %crlf
var %num = 99          | hadd -mz table1 item3 %num
var %true = $true      | hadd -mu10 table1 item4 %num


Final thought:
All in all, I just don't understand why these commands are not already added. It seems to me that they should have been there since hash tables were introduced, I mean I cannot see how /hinc and /hdec made the cut, but /hcopy and /hren aren't there or even implimented as a switch of a current command.

Hope to see these in the next version smile
Posted By: SladeKraven

Re: /hren and /hcopy - Rename/Copy Hash Tables/Ite - 28/08/07 01:31 PM

Unless Khaled has a public todo list only he can say whether or not it will be implemented. I'm not saying they aren't useful because I use Hash Tables quit often and wouldn't mind seeing it added. Along with a number of people on here.

Both of the commands you chose Hash Copying/Renaming were talked about 4 and a half years ago so I'm not sure if that's a hint or what, only time will tell but don't hold your breath.
Posted By: PhireCoder

Re: /hren and /hcopy - Rename/Copy Hash Tables/Ite *DELETED* - 28/08/07 10:16 PM

Post deleted by PhireCoder
Posted By: Om3n

Re: /hren and /hcopy - Rename/Copy Hash Tables/Ite - 28/08/07 10:59 PM

Do you always bitch when somebody offers you an informative & educated opinion based on historical facts?

I think /hcopy is useless give that you can do it in a single command with /hadd already.

I think that /hrename would be quite useful, it an easy alias to script, however saving to file and reloading can become quite a significant waste of resouces/cpu cycles/etc and potentially slow a script down quite a bit. Much cleaner to just change one simple value in memory.
Posted By: Horstl

Re: /hren and /hcopy - Rename/Copy Hash Tables/Ite - 28/08/07 11:20 PM

My latest suggestion has zero replies so far; now I could suppose what I suggested was too ingenious or too stupid, or just too bland or all opinions are ambiguous... ...but I don't! smile
Wanna swap places with me? cool

EDIT: side note: I like the hren, too
Posted By: PhireCoder

Re: /hren and /hcopy - Rename/Copy Hash Tables/Ite *DELETED* - 28/08/07 11:38 PM

Post deleted by PhireCoder
Posted By: SladeKraven

Re: /hren and /hcopy - Rename/Copy Hash Tables/Ite - 29/08/07 01:07 AM

Quote:

!!!!! (Message to the future - Yeah you reading this post dated back 4 and a half years ago in 2007 - Don't bother reposting this suggestion, It's useless) !!!!!


Most people wouldn't repost anyway if they had the common sense, on the other hand that's the most useful thing you've come out with. Well Done.
Posted By: PhireCoder

Re: /hren and /hcopy - Rename/Copy Hash Tables/Ite *DELETED* - 29/08/07 01:56 AM

Post deleted by PhireCoder
Posted By: SladeKraven

Re: /hren and /hcopy - Rename/Copy Hash Tables/Ite - 29/08/07 02:31 AM

And how did you come to that conclusion? You haven't seen a picture of me. Anyways, even if I was what does that have to do with any of the above?
Posted By: PhireCoder

Re: /hren and /hcopy - Rename/Copy Hash Tables/Ite *DELETED* - 29/08/07 02:46 AM

Post deleted by PhireCoder
Posted By: starbucks_mafia

Re: /hren and /hcopy - Rename/Copy Hash Tables/Ite - 29/08/07 03:21 AM

OK I'm thinking both of you need to stop if you intend to salvage any shred of dignity out of this thread.

The suggestion has been made, I'm sure Khaled will read it and consider it. Yes, there's no reason not to suggest it again after x many years since the last time. Yes, it makes sense to post any previous threads - hopefully to save everyone going over the same ground again and in case any good points were made for or against a feature. Yes, it can make sense to show how something can be scripted especially if it's quite simple, but no that in itself is not necessarily enough reason to mean something shouldn't be added to mIRC as a feature.

There, everything covered. So now can we all please get back to discussing the feature itself instead of this pathetic arguing?
Posted By: PhireCoder

Re: /hren and /hcopy - Rename/Copy Hash Tables/Ite - 30/08/07 10:59 PM

OK, back to the topic...

In this post I would like to show exactly how these commands would function for anyone interested...

You can use these aliases until they are implemented as internal commands.

Advanced Users and/or Anyone not interested in these commands, may simply disregard this post.

Note that while these aliases function perfectly they are not nearly as efficient as built-in commands.
Also I am aware that using /hsave and /hload instead of while loops may be more efficient, however that method doesn't work properly in certain situations.
These aliases include error handling.

Command: /hren
Info: Renames hash tables or hash table items.
Syntax: /hren <table> [item] <new name>
Code:
alias hren {
  if (!$2) echo $color(info) -ae * /hren: insufficient parameters
  elseif (!$hget($1)) echo $color(info) -ae * /hren: no such table $+(',$1,')
  elseif ($3) {
    if (!$hfind($1,$2)) echo $color(info) -ae * /hren: no such item $+(',$2,')
    else {
      hadd $1 $3 $hget($1,$2)
      hdel $1-2
    }
  }
  elseif ($2) {
    var %a = $hget($1,0).item
    hmake $2 $hget($1).size
    while (%a) {
      hadd $2 $hget($1,%a).item $hget($1,%a).data
      dec %a
    }
    hfree $1
  }
}

Command: /hcopy
Info: Copies hash tables or hash table items.
Syntax: /hcopy <table1> [item1] <table2> [item2]
Code:
alias hcopy {
  if (!$2) echo $color(info) -ae * /hcopy: insufficient parameters
  elseif (!$hget($1)) echo $color(info) -ae * /hcopy: no such table $+(',$1,')
  elseif ($3) {
    if (!$hfind($1,$2)) echo $color(info) -ae * /hcopy: no such item $+(',$2,')
    elseif ($4) hadd -m $3-4 $hget($1,$2)
    else hadd -m $3 $2 $hget($1,$2)
  }
  else {
    var %a = $hget($1,0).item
    if (!$hget($2)) hmake $2 $hget($1).size
    while (%a) {
      hadd $2 $hget($1,%a).item $hget($1,%a).data
      dec %a
    }
  }
}
Posted By: PhireCoder

Re: /hren and /hcopy - Rename/Copy Hash Tables/Ite - 02/09/07 05:18 PM

oops messed up on above /hren command...
here's the fixed version...
Code:
alias hren {
  if (!$2) echo $color(info) -ae * /hren: insufficient parameters
  elseif (!$hget($1)) echo $color(info) -ae * /hren: no such table $+(',$1,')
  elseif ($3) {
    if (!$hfind($1,$2)) echo $color(info) -ae * /hren: no such item $+(',$2,')
    else {
      hadd $1 $3 $hget($1,$2)
      hdel $1-2
    }
  }
  elseif ($hget($2)) echo $color(info) -ae * /hren: table name already in use $+(',$2,')
  else {
    var %a = $hget($1,0).item
    hmake $2 $hget($1).size
    while (%a) {
      hadd $2 $hget($1,%a).item $hget($1,%a).data
      dec %a
    }
    hfree $1
  }
}
Posted By: argv0

Re: /hren and /hcopy - Rename/Copy Hash Tables/Ite - 02/09/07 10:59 PM

right but when using in a controlled environment (ie. your own scripts) 80% of the error checking is unnecessary, turning the snippet into essentially a one-(technically, two)-liner:

Code:
alias hcopy { var %f = $+($1,$ticks) | hsave -bu $1 %f | hmake $2 | hload -b $2 %f | .remove %f }
alias hren { hcopy $1 $2 | .hdel $1 }


This, however, is not how renaming *should* be done. It *should* be done by just changing the symbol name in the script engine's symbol table so that no copying is necessary at all. Renaming the symbol name would mean improved performance, which is why I believe the suggestion is good on the grounds that it is not possible to do (properly) via script-- NOT because it will reduce your script's line count by ~7 lines. hcopy could also be better implemented at the C level simply by a memcpy() of the hash structure, but of course everything could be better implemented in C, so I won't delve into that.

ps. you'll notice I used hsave/load in my implementation. You claim that it does not work properly in certain situations-- manually using /hadd will work improperly in many more situations, specifically with binary data, which your alias cannot get out. Technically, my alias probably won't maintain "unset" information or any items set with -z. unset information can be maintained by looping with
Code:
$hget($1,%i,&tmp)


and adding with
Code:
hadd -mbu $+ $hget($1,%i).unset $2 &tmp


but this method still will not maintain the -z information. This is yet another reason this suggestion is useful, since you can't accurately copy a hash table via script anyway, no matter how many lines it takes.

Why you would need to copy or rename a table after creating it is another question though, but I won't even bother to ask. I don't buy the "using the name to store the status" story, by the way-- that can much more easily just be done with a "status" item in the table, and it makes more implementation sense too.
Posted By: PhireCoder

Re: /hren and /hcopy - Rename/Copy Hash Tables/Ite - 03/09/07 12:53 AM

Ok, thanx argv0 you make alot of good points... I am new to mIRC so I don't know exactly how everything works... I'm just now learning the scripting language and how to do different things... This is also my first shot at any type of programming too... I do realize now that those script examples are bad examples... I was really just trying to show how it would look and work if implemented internally. That's why the error checking... I know internally it wouldn't work in the same way, I kinda just figured that there was some sort of way to only rename the tables Internally... smile imma n00b take it easy.. lol.. j/k PLZ correct my mistakes that's the only way i will learn... thx again
© 2020 mIRC Discussion Forums