Not sure if this is since the new version or not, but I can't say I remember this behaviour, nor does it seem logical.

If you add some data to a hashtable, and then continue to retrieve it by looping through all the items (with .item / .data property), you'd expect the items to still be in the same order as you stored them. Nothing could be further from the truth, however...

Take the following code:

Code:
alias hashtest {
    var %i $iif($1 != $null, $1, 20)
    if ($hget(hashtest) != $null) {
        hfree hashtest
    }
    hmake hashtest %i
    var %c 1
    while (%c <= %i) {
        hadd hashtest $+(i,%c) $+(d,%c)
        echo -s added item $+(i,%c) with data $+(d,%c) to table hashtest.
        inc %c
    }
    var %c 1
    while (%c <= %i) {
        echo -s reading item $hget(hashtest, %c).item with data $hget(hashtest, %c).data from table hashtest.
        inc %c
    }
}


result:

Code:
added item i1 with data d1 to table hashtest.
added item i2 with data d2 to table hashtest.
added item i3 with data d3 to table hashtest.
added item i4 with data d4 to table hashtest.
added item i5 with data d5 to table hashtest.
added item i6 with data d6 to table hashtest.
added item i7 with data d7 to table hashtest.
added item i8 with data d8 to table hashtest.
added item i9 with data d9 to table hashtest.
added item i10 with data d10 to table hashtest.
added item i11 with data d11 to table hashtest.
added item i12 with data d12 to table hashtest.
added item i13 with data d13 to table hashtest.
added item i14 with data d14 to table hashtest.
added item i15 with data d15 to table hashtest.
added item i16 with data d16 to table hashtest.
added item i17 with data d17 to table hashtest.
added item i18 with data d18 to table hashtest.
added item i19 with data d19 to table hashtest.
added item i20 with data d20 to table hashtest.
reading item i20 with data d20 from table hashtest.
reading item i16 with data d16 from table hashtest.
reading item i17 with data d17 from table hashtest.
reading item i8 with data d8 from table hashtest.
reading item i14 with data d14 from table hashtest.
reading item i2 with data d2 from table hashtest.
reading item i9 with data d9 from table hashtest.
reading item i15 with data d15 from table hashtest.
reading item i3 with data d3 from table hashtest.
reading item i18 with data d18 from table hashtest.
reading item i12 with data d12 from table hashtest.
reading item i19 with data d19 from table hashtest.
reading item i13 with data d13 from table hashtest.
reading item i1 with data d1 from table hashtest.
reading item i10 with data d10 from table hashtest.
reading item i6 with data d6 from table hashtest.
reading item i11 with data d11 from table hashtest.
reading item i7 with data d7 from table hashtest.
reading item i4 with data d4 from table hashtest.
reading item i5 with data d5 from table hashtest.


I know that using the .item/.data properties are not what hashtables are specifically made for, but I'd still very much like it if this behaviour (as rarely or often it may be used by people) is modified to return items in the same order as they were stored.

I hope this makes sense ;_)



http://zowb.net

/server -m irc.p2p-network.net -j #zomgwtfbbq
(ssl on port 6697 and 7000)