With ‘functional’ people, I mean people who write in purely functional languages.
What does purely functional mean? You can’t change anything. Imagine to only be able to create [icode]final [datatype] variable[/icode] variables.
What’s the problem?
Imagine you have a Grid. A very simple one, only an array, where each Tile for a tile-based game is stored. Whenever you want to change the tile, you need to create a new Grid and copy all the tiles into them, since you can’t change anything (a.k.a. so called side-effects (changes of state) aren’t allowed).
Now copying a grid which is big is not cheap. What they do is: Use a data structure which is basically a tree. And then whenever a tree leaf changes, they only have to change all the leaf’s ancestors. Which is only 3-10 Quadtree nodes, depending on the size of the Quadtree and implementation.
With ‘functional’ people, I mean people who write in purely functional languages.
What does purely functional mean? You can’t change anything. Imagine to only be able to create [icode]final [datatype] variable[/icode] variables.
What’s the problem?
Imagine you have a Grid. A very simple one, only an array, where each Tile for a tile-based game is stored. Whenever you want to change the tile, you need to create a new Grid and copy all the tiles into them, since you can’t change anything (a.k.a. so called side-effects (changes of state) aren’t allowed).
Now copying a grid which is big is not cheap. What they do is: Use a data structure which is basically a tree. And then whenever a tree leaf changes, they only have to change all the leaf’s ancestors. Which is only 3-10 Quadtree nodes, depending on the size of the Quadtree and implementation.
Try this implementation PointQuadTree.java.
It will handle Riven’s issue with infinite recursion, and it shatters/merges branches in the tree as needed.
Try this implementation PointQuadTree.java.
It will handle Riven’s issue with infinite recursion, and it shatters/merges branches in the tree as needed.