RunArray.st
changeset 4776 7259a694e36d
parent 4775 03b9f6efd595
child 4805 6e49b5b5f8c3
equal deleted inserted replaced
4775:03b9f6efd595 4776:7259a694e36d
   823 !RunArray methodsFor:'copying'!
   823 !RunArray methodsFor:'copying'!
   824 
   824 
   825 copyFrom:start to:stop
   825 copyFrom:start to:stop
   826     "return a new collection, containing the elements from start to stop"
   826     "return a new collection, containing the elements from start to stop"
   827 
   827 
   828     |runStart runNext newRuns idx copying|
   828     |srcIdx endIdx runStart runNext newRuns idx copying len val|
   829 
   829 
   830     (contentsArray notNil 
   830     (contentsArray notNil 
   831     and:[stop >= start]) ifTrue:[
   831     and:[stop >= start]) ifTrue:[
   832         newRuns := self species new.
   832         newRuns := self species new.
   833         runStart := 1.
   833         runStart := 1.
   834         idx := start.
   834         idx := start.
   835         copying := false.
   835         copying := false.
   836         contentsArray pairWiseDo:[:len :val | 
   836         srcIdx := 1.
       
   837         endIdx := contentsArray size.
       
   838         [srcIdx < endIdx] whileTrue:[
       
   839             len := contentsArray at:srcIdx.
       
   840             val := contentsArray at:srcIdx+1.
       
   841             srcIdx := srcIdx + 2.
       
   842             
   837             runNext := runStart + len.
   843             runNext := runStart + len.
   838         
   844         
   839             copying ifFalse:[
   845             copying ifFalse:[
   840                 idx >= runStart ifTrue:[
   846                 idx >= runStart ifTrue:[
   841                     copying := true
   847                     copying := true
   872      |r|
   878      |r|
   873      r := RunArray withAll:#(1 2 3 3 3 3 3 3 4 5 6 7 7 7 7 7 7 7).
   879      r := RunArray withAll:#(1 2 3 3 3 3 3 3 4 5 6 7 7 7 7 7 7 7).
   874      r copyFrom:1 to:20      
   880      r copyFrom:1 to:20      
   875     "
   881     "
   876 
   882 
   877     "Modified: 18.5.1996 / 19:28:47 / cg"
   883     "Modified: / 18-05-1996 / 19:28:47 / cg"
       
   884     "Modified: / 11-12-2018 / 20:59:27 / Claus Gittinger"
   878 !
   885 !
   879 
   886 
   880 postCopy
   887 postCopy
   881     contentsArray := contentsArray copy.
   888     contentsArray := contentsArray copy.
   882 ! !
   889 ! !