Algorithm suggestion
I have a programming problem: Here's a simplification that isolates the actual problem:
Imagine a grid and a set of rectangles. Each rectangle has a position and width/height. One rectangle may enclose another, but they never overlap. Enclosed rectangles are considered on top of the enclosing ones.
Each rectangle has a unique identifier (a pointer to another object in fact)
The goal: For each horizontal row, I want to compute spans where the rectangle identifier is the same.
A simple solution for this would be to allocate the entire grid, then sort the rectangles by top-left x and y (or vice versa) and then iterate over each rectangle, filling each cell with the identifier. The sorting ensures that enclosed cells are drawn after the enclosing ones.
The issue is that I want to do this row-by-row. I.e. I do not want to allocate the entire grid in one go.
Anyone have a good solution to this?