mIRC Home    About    Download    Register    News    Help

Print Thread
#165028 21/11/06 04:20 PM
Joined: Sep 2006
Posts: 59
R
Rewtor Offline OP
Babel fish
OP Offline
Babel fish
R
Joined: Sep 2006
Posts: 59
Hi,

When i am using Hash tables or Vars to store data then sort them i keep getting either:

/hadd: line too long
or
/set: line too long

Is there anyway around this?
I am getting these messages due to the amount of data but have no idea how to make a work-around.

#165029 21/11/06 04:36 PM
Joined: Oct 2003
Posts: 313
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 313
mIRC has a built-in limit of around 950 chars for the length of a "string".

There are a couple of answers to the issue, but all require a rework of how you do your sort - i.e. you cannot use $sorttok() (which is what I assume you're using)

Binvars store data in binary format, and are limited only by the size of your memory.
Hash tables used as a list (i.e. each element holds one of the tokens that you would put in your string)

Each of these methods obviously requires you to write your own sort routine.


Sais
#165030 21/11/06 04:42 PM
Joined: Sep 2006
Posts: 59
R
Rewtor Offline OP
Babel fish
OP Offline
Babel fish
R
Joined: Sep 2006
Posts: 59
I have never used binvars etc, Could you show an example?
And yes i am using $sorttok.

#165031 22/11/06 01:16 AM
Joined: Dec 2004
Posts: 66
B
Babel fish
Offline
Babel fish
B
Joined: Dec 2004
Posts: 66
There are several ways to sort, depending on your needs and coding preferences, I often like to use a hidden window:
/help custom windows
The lines can be longer than can actually be displayed, I for get if the limit is mirc’s string length of about 950 characters or less but if you’ve been using tokkens to sort then the window line should be long enough.
Code:
/SortDemo {
  ; The h switch hides the window from the user, s for sort
  window -hs @SortWin

  ; Add unsorted lines to window:
  aline @SortWin Betty
  aline @SortWin Zippy
  aline @SortWin Nancy
  aline @SortWin Alice
  aline @SortWin Quark
  aline @SortWin Chirp

  ; How to display the sorted list to another window:
  window -s @Display
  aline @Display The sorted list of words:
  filter -ww @SortWin @Display *

  ; How to save the list to a file:
  savebuf @SortWin SortedWords.txt

  ; for testing look at the hidden window:
  window -a @SortWin

  ; close window unless it's a display window:
  ; window -c @SortWin
} 

#165032 22/11/06 11:28 PM
Joined: Sep 2006
Posts: 59
R
Rewtor Offline OP
Babel fish
OP Offline
Babel fish
R
Joined: Sep 2006
Posts: 59
let me post the code hold on let me get it

#165033 23/11/06 04:23 PM
Joined: Sep 2006
Posts: 59
R
Rewtor Offline OP
Babel fish
OP Offline
Babel fish
R
Joined: Sep 2006
Posts: 59
So how could i prevent this from giving the line too long error?:

alias sort {
var %n = 1, %l = 1
while (%n <= $hget(0)) {
var %list = %list $hfind($hget(%n),*,0,w) $+ $hget(%n) $+ $chr(32)
inc %n
}
var %list = $sorttok(%list,32,nr)
while (%l <= $numtok(%list,32)) {
echo -a $right($gettok(%list,%l,32),-1)
inc %l
}
}

#165034 23/11/06 04:31 PM
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
quoting from my post on the mIRC.net forums:
Quote:

You could go as far as 938
//hadd -m t t $str(a,938) | echo -a $len($hget(t,1).data)
The mirc line limit is 950 characters
//echo -a $calc(950 -$len(hadd -m t t))= 939 however theres a space between the last 't' and the data.

Note that the editbox allows for 2 more characters //
however if you do
$str(a,952)<tab>
It wont work because line doesn't start with //
highest you can go is:
$str(a,949)<tab> since the tab is a character as well.


If ~900 characters is not enough for you use binary hash item entries.
//var %x = $str(a,800) , %y = 1 | bset -t &t 1 %x | bset -t &t 800 %x | bset -t &t 1600 %x | hadd -mb t t &t | noop $hget(t,t,&test) | echo -a $bvar(&test,0)
now one hash table entry holds 2399 characters smile



$maybe
#165035 24/11/06 01:17 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
and if 2399 characters isn't enough...then I'd have to wonder what you're trying to store.

#165036 24/11/06 01:46 AM
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
the 2399 was just an example i'm sure, the size of the hash table entry containing a binary variable is limited only by your ram in the way things like 'regular' binary variables and other such storage is laugh so if hundreds of megabytes of space isnt enough, then i too wonder what youre trying to store!


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
#165037 24/11/06 01:53 AM
Joined: Dec 2004
Posts: 66
B
Babel fish
Offline
Babel fish
B
Joined: Dec 2004
Posts: 66
I see from your $sorttok(%list,32,nr) that you are doing a reverse numeric sort, /window only does a plain alpha sort, but it’s easy to script the other two. To reverse it just read the window from the bottom up, SortInWindow does that.

But for a numeric sort if the number of digits varies you need to left pad the number with zeros to the length of the largest number that the script might handle. It would help to see several examples of the data you are handling in the hash and sort.
Code:
alias SortInWindow {
  window -hs @SortWin

  var %n = $hget(0)
  while (%n) {
    aline @SortWin $hfind($hget(%n),*,0,w) $+ $hget(%n)
    dec %n
  }

  var %l = $line(@SortWin,0)
  while (%l) {
    echo -a $right($line(@SortWin,%l),-1)
    dec %l
  }

  window -c @SortWin
}

alias LeftPadNum {
  ; Call:  $LeftPadNum(Number2BePadded, WidthAfterPadding)
  return $str(0,$calc($2 - $len($1))) $+ $1
}

alias test.LeftPadNum {
  ; In this example the number is padded to 5 didgets wide, 654321 shows
  ; that a longer number will simply be returned
  echo -a $LeftPadNum(2,5)
  echo -a $LeftPadNum(47,5)
  echo -a $LeftPadNum(2947,5)
  echo -a $LeftPadNum(41879,5)
  echo -a $LeftPadNum(654321,5)
}
 

#165038 24/11/06 02:28 AM
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
you could also use $base(N,10,10,M) to pad an integer to size M, eg. $base(2,10,10,5) = 00002

and even sort the window numerically with /filter, /filter -teuwwc 1 32 @sortwin @sortwin which doesn't require any number padding :P


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
#165039 24/11/06 03:18 AM
Joined: Dec 2004
Posts: 66
B
Babel fish
Offline
Babel fish
B
Joined: Dec 2004
Posts: 66
Cool jaytea, I haven’t used $base before, have seen it in Help but didn’t catch that it could pad numbers. I use /filter a lot, but haven’t used several of those options. Thanks smile


Link Copied to Clipboard