One such way would be to fill gaps with ``blank'' DataItems which would also be in an internal list of unallocated items. When a new item is added to the data store rather than creating the DataItem at it would just pick the first one from the list of gaps.
This way a remove would generate a gap and an add would remove it:
Items: | 0 | 1 | 2 | 3 | 4 | |
Start | allocated | allocated | allocated | allocated | allocated | |
Remove Item 2 | allocated | allocated | unallocated | allocated | allocated | |
Remove item 0 | unallocated | allocated | unallocated | allocated | allocated | |
Add new item | allocated | allocated | unallocated | allocated | allocated | |
Add new item | allocated | allocated | allocated | allocated | allocated |
David Goodwin 2008-10-21