implement data segment generation algorithm