SortedCollection.st
changeset 3251 87cac58a4e57
parent 3250 c4b444774f1c
child 3340 300d88cf8b14
equal deleted inserted replaced
3250:c4b444774f1c 3251:87cac58a4e57
    51 
    51 
    52     Thus a sortBlock of [:a :b | a < b] defines ascending sort-order,
    52     Thus a sortBlock of [:a :b | a < b] defines ascending sort-order,
    53     while [:a :b | a > b] defines descening order.
    53     while [:a :b | a > b] defines descening order.
    54     The default sortBlock for SortedCollections is the first one.
    54     The default sortBlock for SortedCollections is the first one.
    55 
    55 
       
    56     Compatibility Warning:
       
    57         VW seems to use a default sortBlock which compares a<=b,
       
    58         while ST/X uses a<b.
       
    59         That means, that elements which are compared MUST understand #< in ST/X
       
    60         while the minumum protocol is #<= in VW.
       
    61         This may be changed in a future release of ST/X 
       
    62         (it is not yet, to not confuse existing applications ...
       
    63          ... be aware, that the sortBlock has an effect on a few algorithms
       
    64          found here; especially #indexForInserting is critical.)
       
    65         
       
    66 
    56     [author:]
    67     [author:]
    57         Claus Gittinger
    68         Claus Gittinger
    58 "
    69 "
    59 !
    70 !
    60 
    71 
    90     takes 383 ms on the same machine.
   101     takes 383 ms on the same machine.
    91 
   102 
    92     If you already have a big sortedCollection at hand, adding multiple
   103     If you already have a big sortedCollection at hand, adding multiple
    93     items may be better done with #addAll:, which resorts all elements, if
   104     items may be better done with #addAll:, which resorts all elements, if
    94     the number of added items is more than some threshold number.
   105     the number of added items is more than some threshold number.
    95     Building some big collection:
   106     However, the break-even point where bulk-adding is faster depends
    96 
   107     on the machine ... (and ST/X version ;-).
    97         |o rnd c|
       
    98 
       
    99         o := OrderedCollection new.
       
   100         rnd := Random new.
       
   101         10000 timesRepeat:[
       
   102             o add:rnd next.
       
   103         ].
       
   104         o := o asSortedCollection.
       
   105 
       
   106     adding 1000 elements individually to it:
       
   107 
       
   108         1000 timesRepeat:[
       
   109             o add:rnd next.
       
   110         ].
       
   111 
       
   112     takes 258 ms 
       
   113     (because the elements have to be shifted around for each added element);
       
   114 
       
   115     while adding them en-bloque with:
       
   116 
       
   117         c := OrderedCollection new.
       
   118         1000 timesRepeat:[
       
   119             c add:rnd next.
       
   120         ].
       
   121         o addAll:o
       
   122 
       
   123     takes 71 ms
       
   124 "
   108 "
   125 ! !
   109 ! !
   126 
   110 
   127 !SortedCollection class methodsFor:'initialization'!
   111 !SortedCollection class methodsFor:'initialization'!
   128 
   112 
   703 ! !
   687 ! !
   704 
   688 
   705 !SortedCollection class methodsFor:'documentation'!
   689 !SortedCollection class methodsFor:'documentation'!
   706 
   690 
   707 version
   691 version
   708     ^ '$Header: /cvs/stx/stx/libbasic/SortedCollection.st,v 1.36 1998-01-30 00:50:42 cg Exp $'
   692     ^ '$Header: /cvs/stx/stx/libbasic/SortedCollection.st,v 1.37 1998-01-30 00:57:28 cg Exp $'
   709 ! !
   693 ! !
   710 SortedCollection initialize!
   694 SortedCollection initialize!