On 2018-08-08 00:20, Bob Sneidar via use-livecode wrote:
I do stand corrected however, as I got the dgdata of a grid with 6
records, in the order they were added to the sql database, and then
queried for. The keys are NOT in numerical order:

5
6
1
2
3
4

The keys function does the minimal work necessary to return its result.

An array in LiveCode is a sequence of slots, each one which can hold a value (pre-7 they used to be chained hash-tables - but 7+ they changed to linear hash-tables).

The hash of the key is used to determine which slot its value goes in - if that slot is full it goes in the next available one.

The keys function iterates through the sequence of slots from 1 up to the capacity of the array (which is not the same as the number of elements - there's always head-room in the slot array), accumulating the keys which are present as it goes - any empty slots are skipped.

Therefore the ordering of the keys is determined by the numerical order of the hash of the keys themselves which holds scant relationship to the content of the keys - beyond that determined by the hash function - i.e. the hash function is designed to distribute keys arbitrarily, but uniformly across the sequence of slots.

Warmest Regards,

Mark.

--
Mark Waddingham ~ m...@livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to