[erlang-questions] idiomatic large data sets; shared and unshared

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Mon Jul 8 16:38:56 CEST 2013

On Sat, Jul 6, 2013 at 3:54 AM, Felix Gallo <felixgallo@REDACTED> wrote:

> In the mutable world, you might structure it as a hashtable of hashes, or
> hashtable of sets etc., and use the coordinate tuple {x,y} as a key into
> the hash table, then mutate the list.  addtocell(Coordinate, Value) and
> removefromcell(Coordinate, Value) are very small, easy, and extremely fast
> (sub-second for a million iterations of addtocell()).

In a game, you will get into trouble with this representation alone. You
need to have locational information about what are in the cells. In other
words, given a thing in a cell, you must know, quickly what are adjacent or
close to that cell in order to quickly asses what to do and so on.

The trick in a game is spatial separation. In other words, you break the
world into regions and then you handle each region by its own, gaining
locality. The same is true in Erlang. You need to break your big array into
a spatial structure, probably controlled by a process tree which handles
each area of the whole world. In turn, this enables parallel execution and
it also simplifies local decisions which can be made process-local.

Take a look into stuff like K,d-trees, octrees and so on for ideas on how
to approach the problem in a more general fasion.

A blind grid can be made in ETS: {{X, Y}, Content}. But this runs the risk
of having to copy Content to and from a process on each access and it is
also not safe from races on insertion. Think is, this is not a trivial
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130708/c83fe309/attachment.htm>

More information about the erlang-questions mailing list