Collection.st
changeset 21490 1e0702c33531
parent 21456 f99fbdd1c81b
child 21542 7989ab6cba0a
equal deleted inserted replaced
21489:2c4c8ccda384 21490:1e0702c33531
     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
   342      Only redefined in the immutable collections (of which instances are
   340      Only redefined in the immutable collections (of which instances are
   343      created by the compiler)"
   341      created by the compiler)"
   344 
   342 
   345     ^ self
   343     ^ self
   346 ! !
   344 ! !
   347 
       
   348 
   345 
   349 !Collection methodsFor:'Compatibility-ANSI'!
   346 !Collection methodsFor:'Compatibility-ANSI'!
   350 
   347 
   351 identityIncludes:anObject
   348 identityIncludes:anObject
   352     "return true, if the argument, anObject is in the collection.
   349     "return true, if the argument, anObject is in the collection.
  3867 
  3864 
  3868     "
  3865     "
  3869      (1 to:3) with:#(1 2 3 4) conform:[:a :b | a = b]   --- raises an error
  3866      (1 to:3) with:#(1 2 3 4) conform:[:a :b | a = b]   --- raises an error
  3870      (1 to:3) with:#(1 22 3) conform:[:a :b | a = b]
  3867      (1 to:3) with:#(1 22 3) conform:[:a :b | a = b]
  3871      (1 to:3) with:#(1 2 3) conform:[:a :b | a = b]
  3868      (1 to:3) with:#(1 2 3) conform:[:a :b | a = b]
  3872     "
  3869      (1 to:3) with:#('1' '2' '3') conform:[:a :b | a asString = b asString]
       
  3870     "
       
  3871 
       
  3872     "Modified (comment): / 19-02-2017 / 18:30:08 / cg"
  3873 !
  3873 !
  3874 
  3874 
  3875 with:aCollection contains:aTwoArgBlock
  3875 with:aCollection contains:aTwoArgBlock
  3876     "evaluate the argument, aBlock for successive elements from
  3876     "evaluate the argument, aBlock for successive elements from
  3877      each the receiver and the argument, aCollection.
  3877      each the receiver and the argument, aCollection.
  4369         aStream nextPutAll:(s contents).
  4369         aStream nextPutAll:(s contents).
  4370     ].
  4370     ].
  4371     aStream nextPut:$)
  4371     aStream nextPut:$)
  4372 
  4372 
  4373     "
  4373     "
  4374      #(1 2 3 'hello' $a $ü) printOn:Transcript
  4374      #(1 2 3 'hello' $a $ü) printOn:Transcript
  4375      (Array new:100000) printOn:Transcript
  4375      (Array new:100000) printOn:Transcript
  4376      (Array new:100000) printOn:Stdout
  4376      (Array new:100000) printOn:Stdout
  4377      (Array new:100000) printString size
  4377      (Array new:100000) printString size
  4378      (Dictionary new at:#hello put:'world';
  4378      (Dictionary new at:#hello put:'world';
  4379                      at:#foo put:'bar'; yourself) printOn:Transcript
  4379                      at:#foo put:'bar'; yourself) printOn:Transcript
  5726 !
  5726 !
  5727 
  5727 
  5728 includesAll:aCollection
  5728 includesAll:aCollection
  5729     "return true if the receiver includes all elements of
  5729     "return true if the receiver includes all elements of
  5730      the argument, aCollection; false if any is missing.
  5730      the argument, aCollection; false if any is missing.
  5731      Notice: this method has O² runtime behavior and may be
  5731      Notice: this method has O² runtime behavior and may be
  5732              slow for big receivers/args.
  5732              slow for big receivers/args.
  5733              Think about using a Set, or Dictionary."
  5733              Think about using a Set, or Dictionary."
  5734 
  5734 
  5735     ^ aCollection conform:[:element | (self includes:element)]
  5735     ^ aCollection conform:[:element | (self includes:element)]
  5736 
  5736 
  5746 includesAny:searchedElementsCollection
  5746 includesAny:searchedElementsCollection
  5747     "return true if the receiver includes any from the argument, aCollection.
  5747     "return true if the receiver includes any from the argument, aCollection.
  5748      Return false if it includes none.
  5748      Return false if it includes none.
  5749      Uses #= (value compare)
  5749      Uses #= (value compare)
  5750      Notice:
  5750      Notice:
  5751         this method has O² runtime behavior for some subclasses and may be slow for big receivers/args.
  5751         this method has O² runtime behavior for some subclasses and may be slow for big receivers/args.
  5752         Think about using a Set or Dictionary.
  5752         Think about using a Set or Dictionary.
  5753         Some speedup is also possible, by arranging highly
  5753         Some speedup is also possible, by arranging highly
  5754         probable elements towards the beginning of aCollection, to avoid useless searches.
  5754         probable elements towards the beginning of aCollection, to avoid useless searches.
  5755 
  5755 
  5756         Also: I am not sure, if (and if so, at which breakeven),
  5756         Also: I am not sure, if (and if so, at which breakeven),
  5823 includesAnyIdentical:searchedElementsCollection
  5823 includesAnyIdentical:searchedElementsCollection
  5824     "return true, if the receiver includes any from the argument, aCollection.
  5824     "return true, if the receiver includes any from the argument, aCollection.
  5825      Return false if it includes none.
  5825      Return false if it includes none.
  5826      Use identity compare for comparing.
  5826      Use identity compare for comparing.
  5827      Notice:
  5827      Notice:
  5828         this method has O² runtime behavior for some subclasses and may be slow for big receivers/args.
  5828         this method has O² runtime behavior for some subclasses and may be slow for big receivers/args.
  5829         Think about using a Set or Dictionary.
  5829         Think about using a Set or Dictionary.
  5830         Some speedup is also possible, by arranging highly
  5830         Some speedup is also possible, by arranging highly
  5831         probable elements towards the beginning of aCollection, to avoid useless searches."
  5831         probable elements towards the beginning of aCollection, to avoid useless searches."
  5832 
  5832 
  5833     searchedElementsCollection do:[:element |
  5833     searchedElementsCollection do:[:element |