mIRC Homepage

Arrays

Posted By: ecliptik

Arrays - 31/12/06 04:12 AM

i knwo you got tokens but i'd like to see arrays too

for eample

Array[0] = test,test2,test3
Array[1] = test4,test5

then i can use the tokens to get them split

example of making a array

/array Array1
/aset Array[0] blah
Array(Array1).length
Array(Array1,blah).append
/aunset Array1
Posted By: genius_at_work

Re: Arrays - 31/12/06 04:56 AM

I can't see a use for arrays unless they support multi-dimension. If not, then hash tables can do the same things, essentially.

/hmake array
/hadd array [1] blah
$hget(array,0).item
(not sure what the .append would do)
/hfree array

If arrays were added, a FOREACH structure should be added with it, as it would permit simpler loops with arrays.

-genius_at_work
Posted By: DaveC

Re: Arrays - 31/12/06 07:40 AM

I think hash tables are fine enough for this, I know you know but hash tables can appear to do multi dimensions anyway with ex, /hadd array [1/1/5] for instance, but of course were just really making up unique item names, but it comes to the same result.

ps: I think his .append would add an item to the end of the array
Posted By: Mpdreamz

Re: Arrays - 31/12/06 09:26 AM

An array feauture would be a really nice option if it will allow you to pass complete arrays to aliases.
It would also be a cleaner option then a temporary hash table.

Since arrays are "Sorted" i wouldn't class them the same as an hash table eventhough you can "fake" array support in mIRC by using hash tables.

A foreach structure to go with it would indeed be total sweetness.

Oh well just wait and see if suggestion #342342 makes it smile




Posted By: hixxy

Re: Arrays - 31/12/06 12:58 PM

Signed. Hashtables are a shoddy workaround at best. They may work, but they're missing many advantages that true array support would bring.
Posted By: DaveC

Re: Arrays - 31/12/06 10:21 PM

I asked a little birdy i know, and it said, they are stuck working on suggestion #19, but they welll get to #342342 when its turn comes up. :-)
Posted By: Riamus2

Re: Arrays - 01/01/07 12:56 AM

Speaking of .append, I'd love to see something like that for hash tables. I'd rather than have to do something like:

/hadd table item $hget(Table,item) appended_data

I'd rather do something like:

/hadd -a table item appended_data
Posted By: Ghozer

Re: Arrays - 08/01/07 03:05 AM

If you use arrays, use a similar method to php arrays, this will allow multi dimensional, arrays within arrays, and named array items...

in php its $var = array("item_name1" => "item1", "item_name2" => "item2)

then its just $var['item_name1'] to retrieve the info..

the mIRC equivelent would be something like

var %moo = $array(item_name1 = item1, item_name2 = item2)

then just %moo[item_name1] or something, maybe have an appendage on the variable to say your calling an array item, maybe something like... &%moo item_name1
Posted By: PhantasyX

Re: Arrays - 08/01/07 05:46 AM

Longer Variables would be nice too. *shrugs*
Posted By: Ledah

Re: Arrays - 13/02/07 06:19 AM

We sure can do a workaround for Arrays, but im for the idea that true arrays would be better. a For Loop WOULD be simpler than the current Whiles we have too.
On the same way, the WhileFix is a nice workaround BUT having it as a true mirc function would surely increase its potential

So... we should be around #32 by now... and arrays is #342342 ? Let's change that a little ;p
$left(#342432,3) ftw!
Posted By: hixxy

Re: Arrays - 13/02/07 12:32 PM

Just something similar to the hashtable implementation would be enough:

Code:
acopy <array1> <array2>
; Copy an array to another.

amake <array> <size>
; Create an array.

aadd [-imo] <array> [N] <data>
/*
Add data to an array.
-i = insert <data> at position [N]
-m = make array if it doesn't already exist.
-o = overwrite item at position [N] with <data>
*/

adel <array> <N>
; Delete an item from an array.

aunset <array>
; Delete an array.

$aget(<array>,<N>)
; Get data from an array.

$afind(<array>,<wildcard/regex>,[rw],<N>)
/*
Find data within an array.
r = regex comparison
w = wildcard comparison
*/


The main advantage over hashtables would be that they could be used to store sorted data, without having to use slow file access. As per usual, using 0 for the <N> parameters for the identifiers will return the number of found matches / total number of items.
Posted By: Riamus2

Re: Arrays - 13/02/07 07:14 PM

You can sort hash tables very quickly and easily using /filter. Even tables with thousands of items can be sorted very quickly.
Posted By: hixxy

Re: Arrays - 13/02/07 07:16 PM

/filter does not support hashtables.

Even if it did, it wouldn't work, because they are unsorted. Hashtables are stored as a key/data pair, so their order does not matter, as to retrieve data you must know the key.
Posted By: Riamus2

Re: Arrays - 13/02/07 09:55 PM

Filter does actually work. DaveC gave a very good example a year or two ago about doing it. It's a matter of a save of the table (data only), filtering that includes line numbers, and the calling the data by the line number. That's probably not a very accurate description, but I don't have the code in front of me.

Yes, it's a workaround, but it allows very quick sorting of the hash tables with very little coding necessary to do it (under 5 lines).
Posted By: hixxy

Re: Arrays - 13/02/07 09:57 PM

If you save the table then it's acting on a file, not a hashtable. /filter does not support hashtables.

That is also not sorting the data. Well, it is, but the data inside of the table is still unsorted, but you can use a number as an item/key to sort the data yourself - this is not a built-in hashtable sort routine, but a workaround. It doesn't change the fact that hashtables are unsorted.
© 2020 mIRC Discussion Forums