OrderedCollection.st
changeset 25351 30b332af1f33
parent 24894 09ca874a6160
child 25366 779764ba117b
equal deleted inserted replaced
25350:8f0794692a17 25351:30b332af1f33
     1 "{ Encoding: utf8 }"
       
     2 
       
     3 "
     1 "
     4  COPYRIGHT (c) 1989 by Claus Gittinger
     2  COPYRIGHT (c) 1989 by Claus Gittinger
     5 	      All Rights Reserved
     3 	      All Rights Reserved
     6 
     4 
     7  This software is furnished under a license and may be used
     5  This software is furnished under a license and may be used
   853     "/ first search forward to the first element which has
   851     "/ first search forward to the first element which has
   854     "/ to be removed (meets the criteria)
   852     "/ to be removed (meets the criteria)
   855     srcIndex := firstIndex.
   853     srcIndex := firstIndex.
   856     lastIdx := lastIndex.
   854     lastIdx := lastIndex.
   857 
   855 
       
   856     removedElements := OrderedCollection new.
   858     [
   857     [
   859         srcIndex > lastIdx
   858         srcIndex > lastIdx
   860         or:[ aBlock value:(contentsArray at:srcIndex) ]
   859         or:[ aBlock value:(contentsArray at:srcIndex) ]
   861     ] whileFalse:[
   860     ] whileFalse:[
   862         srcIndex := srcIndex + 1.
   861         srcIndex := srcIndex + 1.
   863     ].
   862     ].
   864     srcIndex > lastIdx ifTrue:[
   863     srcIndex > lastIdx ifTrue:[
   865         "/ nothing removed
   864         "/ nothing removed. Answer an empty OrderedCollection (not an Array)
   866         ^ #()
   865         "/ maybe sender wants to add elements.
       
   866         ^ removedElements
   867     ].
   867     ].
   868 
   868 
   869     "/ now srcIndex is the index of element, which is the first to be removed
   869     "/ now srcIndex is the index of element, which is the first to be removed
   870     removedElements := OrderedCollection new.
       
   871     removedElements add:(contentsArray at:srcIndex).
   870     removedElements add:(contentsArray at:srcIndex).
   872 
   871 
   873     dstIndex := srcIndex.
   872     dstIndex := srcIndex.
   874     srcIndex := srcIndex + 1.
   873     srcIndex := srcIndex + 1.
   875 
   874 
   970         many elements removed:
   969         many elements removed:
   971           (1000)  -  10          20         30
   970           (1000)  -  10          20         30
   972           (10000) - 130         290        260
   971           (10000) - 130         290        260
   973           (50000) - 720        1470       1300
   972           (50000) - 720        1470       1300
   974     "
   973     "
   975     "Modified: 8.2.1997 / 19:19:00 / cg"
   974 
       
   975     "Modified: / 08-02-1997 / 19:19:00 / cg"
       
   976     "Modified: / 31-03-2020 / 11:36:20 / Stefan Vogel"
   976 !
   977 !
   977 
   978 
   978 removeFirst
   979 removeFirst
   979     "remove the first element from the collection; return the element.
   980     "remove the first element from the collection; return the element.
   980      If there is no element in the receiver collection, raise an error.
   981      If there is no element in the receiver collection, raise an error.
  1858 
  1859 
  1859     "Modified: / 30-07-2018 / 12:06:33 / Claus Gittinger"
  1860     "Modified: / 30-07-2018 / 12:06:33 / Claus Gittinger"
  1860 ! !
  1861 ! !
  1861 
  1862 
  1862 
  1863 
       
  1864 
  1863 !OrderedCollection methodsFor:'private'!
  1865 !OrderedCollection methodsFor:'private'!
  1864 
  1866 
  1865 containerClass
  1867 containerClass
  1866     "the class of the underlying container.
  1868     "the class of the underlying container.
  1867      Here Array; redefined in WeakOrderedCollection to use a WeakArray"
  1869      Here Array; redefined in WeakOrderedCollection to use a WeakArray"