[Gambas-user] Sparse arrays? Possible?

Bruce adamnt42 at gmail.com
Sun Mar 8 06:16:17 CET 2020


Firstly, I haven't tried this but I was wondering if it is possible.

Given a set of objects that have an ordinal characteristic (not a 
property of the object itself and not encountered in the ascending order 
of that characteristic) is it possible to construct an array of such 
objects that is only sparsely populated?

Let's say we have the following objects, with that derived 
characteristic in brackets: Ahab(3),Chab(6), Fhab(2) and Ghab(7).
I want to fill the array such that its' final representation is
[0] -
[1] -
[2] Fhab
[3] Ahab
[4] -
[5] -
[6] Chab
[7] Ghab

I don't know at the outset what the maximum ordinal value is and so I 
don't know the size of the array.
There are reasons for using an array rather than a collection keyed by 
the value.
The source of the objects is unsortable, they arrive over time in a 
random order.

Any thoughts?
b

p.s. It's like the IP layer in TCP/IP putting the packets back in order 
to rebuild the entire message.


More information about the User mailing list