OrderedCollection.st
changeset 24003 abb6108fb06b
parent 23702 6b11890f5f2c
child 24042 2c4768bb2e89
equal deleted inserted replaced
24002:ac83f90e549c 24003:abb6108fb06b
       
     1 "{ Encoding: utf8 }"
       
     2 
     1 "
     3 "
     2  COPYRIGHT (c) 1989 by Claus Gittinger
     4  COPYRIGHT (c) 1989 by Claus Gittinger
     3 	      All Rights Reserved
     5 	      All Rights Reserved
     4 
     6 
     5  This software is furnished under a license and may be used
     7  This software is furnished under a license and may be used
  2241     ^ index - firstIndex + 1
  2243     ^ index - firstIndex + 1
  2242 
  2244 
  2243     "Modified: 12.4.1996 / 17:58:19 / cg"
  2245     "Modified: 12.4.1996 / 17:58:19 / cg"
  2244 !
  2246 !
  2245 
  2247 
       
  2248 identityIndexOf:anObject startingAt:startIndex endingAt:stopIndex
       
  2249     "return the index of anObject, starting search at startIndex,
       
  2250      ending at stop.
       
  2251      If found (within the range), return the index, otherwise return 0.
       
  2252      Compare using ==; return 0 if not found in the collection"
       
  2253 
       
  2254     |index|
       
  2255 
       
  2256     index := contentsArray
       
  2257                 identityIndexOf:anObject
       
  2258                 startingAt:(startIndex + firstIndex - 1)
       
  2259                 endingAt:((stopIndex + firstIndex - 1) min:lastIndex).
       
  2260     index == 0 ifTrue:[^ 0].
       
  2261     ^ index - firstIndex + 1
       
  2262 
       
  2263     "
       
  2264      |coll|
       
  2265      coll := #(1 2 3 4 5 6 7 8 9 10) asOrderedCollection.
       
  2266      coll identityIndexOf:7 startingAt:2 endingAt:6.  
       
  2267      coll identityIndexOf:7 startingAt:2 endingAt:7.  
       
  2268      coll identityIndexOf:7 startingAt:2 endingAt:8.  
       
  2269      coll identityIndexOf:7 startingAt:2 endingAt:9. 
       
  2270      coll removeFirst.
       
  2271      coll removeFirst.
       
  2272      coll.     'now: OrderedCollection(3 4 5 6 7 8 9 10)'.   
       
  2273      coll identityIndexOf:7 startingAt:2 endingAt:4.    
       
  2274      coll identityIndexOf:7 startingAt:2 endingAt:5.     
       
  2275      coll identityIndexOf:7 startingAt:2 endingAt:6.  
       
  2276      coll identityIndexOf:7 startingAt:2 endingAt:7. 
       
  2277     "
       
  2278 
       
  2279     "Modified: 12.4.1996 / 17:58:19 / cg"
       
  2280 !
       
  2281 
  2246 indexOf:anObject
  2282 indexOf:anObject
  2247     "return the index of anObject or 0 if not found in the collection.
  2283     "return the index of anObject or 0 if not found in the collection.
  2248      Compare using ="
  2284      Compare using ="
  2249 
  2285 
  2250     |index|
  2286     |index|