Calculate nested segment lengths

This is done by keeping track of the most recent data pointer during
population of the lookup tree.