merge partially contiguous sets