bugbear <bugbear@trim_papermule.co.uk_trim> wrote in comp.lang.perl.misc:

> (E-Mail Removed) wrote:

> > Hi.

> >

> > Thank you very much for your quick answers. I try to handle data from a

> > 450x450 meter surface.

> >

> > I've got 100,000 elements distributed on this surface, and each

> > square millimeter can hold one or more elements. So the array to create

> > is a sparse one: most of square millimeters holds zero elements, and

> > the rest, 20 or less.

> >

> > I'm trying to find the square meter with more elements inside.
"The square meter" as in, divide the surface into meter-squares like

a checkerboard and find the one with the most elements? Or as in,

find the one-meter square that holds the most elements? The first

ones must start on integer meter-coordinates, the other can start

anywhere. The second search space is much larger.

> Ah. OK.

>

> Your question should really be "what data structure should

> I use to..."

>

> It's not really a perl question at all, it's

> really an algorithm and data structure question.
There is, however, a likely Perl answer: Use a hash. It is often

the most straight-forward way to represent a sparse anything.

Here one could use blank-separated integer coordinates (in mm) for

keys and the (nonzero) number of elements for values. Values of

zero are *not* entered. Some care may be needed not to autovivify

these non-entries.

Anno