partial algorithm for compacting lap buffer