[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why no for table-iterator like e. g. "hashpairs"?
- From: Francisco Olarte <folarte@...>
- Date: Fri, 1 Nov 2019 17:53:54 +0100
Replying to myself, I was curious and did some more experiments.
Sending them to try to convince people to not trust order in
non-sequences:
On Fri, Nov 1, 2019 at 5:47 PM Francisco Olarte <folarte@peoplecall.com> wrote:
> >>>>
> > for k,v in pairs(t) do print(k,v, k%4, k%8, k%16) end
> 44444 4 0 4 12
> 33333 3 1 5 5
> 22222 2 2 6 14
> 11111 1 3 7 7
> <<<
It seems to be 4:> t={[3]=1,[6]=2,[9]=3,[12]=4}
> for k,v in pairs(t) do print(k,v, k%4, k%8, k%16) end
12 4 0 4 12
9 3 1 1 9
6 2 2 6 6
3 1 3 3 3
And, as I suspected, insertion order matters:
> t={[3]=1,[6]=2,[9]=3,[13]=4}
> for k,v in pairs(t) do print(k,v, k%4, k%8, k%16) end
13 4 1 5 13
9 3 1 1 9
6 2 2 6 6
3 1 3 3 3
> t={[3]=1,[6]=2,[13]=4,[9]=3}
> for k,v in pairs(t) do print(k,v, k%4, k%8, k%16) end
9 3 1 1 9
13 4 1 5 13
6 2 2 6 6
3 1 3 3 3
>
( This seems to indicate modulo 2^n, open hashing, I did not remember
the details, read it many versions ago )
Francisco Olarte.