[erlang-questions] Code complexity and encapsulation
Richard A. O'Keefe
Tue May 20 01:00:15 CEST 2014
On 19/05/2014, at 8:50 PM, Suraj Kumar wrote:
> The problem domain is analogous to a drawing system: There is a 2D 'canvas onto which several different types of 'shape objects' can be fit into. Once they are all placed on the canvas, it is required that the canvas gets to know all the shapes which seem to coincide with point P (x, y co-ordinates) (or must do similar natured querying of all the shapes without being aware of their details). To find this, the canvas has to ask each shape, in an agnostic/implementation-independent way, whether the object "is_on_point (x,y)".
ARGH! No! Please don't do that!
There is an abundance of 2D spatial indexing structures.
Have an "index".
Each "object" tells the index what its shape is.
The "canvas" asks the index its spatial questions.
We are talking about the difference between "millions" and
the logarithm of "millions". 2*21/21 is roughly 10**5.
Getting the canvas to ask each object "do you overlap this point"
is just going to be insanely slow compared with what you could do.
More information about the erlang-questions