in reply to How to code this?

Since I will politely assume that you do want “another set of eyes” looking with you at this problem, and given that (as you say) the problem is difficult to describe, let me try again.

This appears to me to fundamentally be a problem involving groups, the members of which happen to be “very large arrays” and which are identified by a numerical key that falls within the appointed (but arbitrary) boundaries of that group.   The membership of each group changes constantly, and it is significant to the problem that the status of each group-member (“recently added”) is known.   You said that the fact that a new item has been added to a group is significant in deciding when, whether, and how to process it.

(What I am calling “an item” consists of:   an arrayref which is the list of items (and which may or may not be the only such reference that exists); a key-value which identifies it; perhaps a group-number; and a status-indicator e.g. “recently added.”)

Storage management is an issue, of course, because you don’t need large things taking up memory when you no longer have any use for them, but I see this as an issue that Perl already knows how to take care of for itself.     I also observed how this enables an arrayref to be in multiple places within the structure at one time.

Perhaps the boundaries of a group are not fixed.   Perhaps with an arbitrary group-size of, let us say, “4,” a “group” is defined by all elements in the inclusive range [n ... n-(4-1)] for any key n that we happen to stumble-upon in the data.   But, once a group has been identified and its membership has been determined, so far it appears that the subsequent processing that takes place always happens within that one group.

I think that what you’re saying is that, once you have identified a group and determined what’s in it, the actual processing of that group is easy to describe.

Am I still on the right track?

Is this the sort of problem that might be usefully described as involving a “work to-do list?”   Say, when you “add a new group,” this establishes it as work-to-do and so you throw it into the bucket (perhaps it is a sorted list ...) and that is part of what determines what the algorithm is to do next.

I know I’m shooting in the dark here, but ... “HTH.”