class: SegmentedOrderedCollection
authorClaus Gittinger <cg@exept.de>
Sat, 26 Jul 2014 10:13:10 +0200
changeset 3328 deaef41ffd6f
parent 3327 5b988100c53a
child 3329 170f49ba6c9a
class: SegmentedOrderedCollection comment/format in: #documentation changed:7 methods
SegmentedOrderedCollection.st
--- a/SegmentedOrderedCollection.st	Sun Jul 20 20:15:26 2014 +0200
+++ b/SegmentedOrderedCollection.st	Sat Jul 26 10:13:10 2014 +0200
@@ -11,15 +11,19 @@
 
 documentation
 "
-    SegmentedOrderedCollections are intended as a replacement for huge OrderedCollections.
+    SegmentedOrderedCollections are intended as a replacement for huge OrderedCollections or Lists.
     They keep their elements in chunks (segments), allowing for fast 
     adding/removing at either end AND relatively fast add/remove inside the collection.
     For huge collections, the performance is much better when adding/removing inner elements.
-    However, notice: when only removing at either end only, an OrderedCollection is much faster.
+
+    However, notice: when only removing at either end only, an OrderedCollection is faster.
 
     The break-even in performance depends on the number of elements and the usage pattern.
     Consider it with (say) > 10000 elements and many adds/removes from the inside.
 
+    This class was added to support huge selection-in-lists (>100k elements), which are
+    constantly changing by adding/removing elements at arbitrary positions.
+
     Possibly unfinished (may need optimized search and replace).
 
     [author:]
@@ -115,6 +119,7 @@
     ].
     seg add:anObject.
     tally := tally + 1.
+    self changed:#insert: with:tally.
     ^ anObject.
 !
 
@@ -146,6 +151,7 @@
             ].
             seg add:anObject beforeIndex:(index - segStart + 1).
             tally := tally + 1.
+            self changed:#insert: with:index.
             ^ anObject
         ].
         segStart := segEnd + 1.
@@ -165,14 +171,20 @@
     ].
     seg addFirst:anObject.
     tally := tally + 1.
+    self changed:#insert: with:1
 !
 
 removeAll
     "remove all elements from the receiver. Returns the receiver."
 
+    |prevSize|
+
+    prevSize := tally.
     segments := OrderedCollection with:(OrderedCollection new).
     tally := 0.
+    self changed:#removeFrom: with:(Array with:1 with:prevSize)
 
+    
     "Modified: / 30-07-2013 / 19:31:05 / cg"
 !
 
@@ -200,6 +212,7 @@
         segments removeFirst
     ].
     tally := tally - 1.
+    self changed:#remove: with:1.
     ^ el
 !
 
@@ -238,6 +251,7 @@
                         segments removeAtIndex:segIndex.
                     ].
                     tally := tally - (endIndex - startIndex + 1).
+                    self changed:#removeFrom: with:(Array with:startIndex with:endIndex).
                     ^ self.
                 ].
                 seg removeFromIndex:(startIndex - segStart + 1).        
@@ -254,6 +268,7 @@
                     segments removeAtIndex:segIndex.
                 ].
                 tally := tally - (endIndex - startIndex + 1).
+                self changed:#removeFrom: with:(Array with:startIndex with:endIndex).
                 ^ self.
             ] ifFalse:[
                 "/ remove the whole segment
@@ -280,6 +295,7 @@
         segments removeLast
     ].
     tally := tally - 1.
+    self changed:#remove: with:(1 + tally).
     ^ el
 ! !
 
@@ -396,10 +412,10 @@
 !SegmentedOrderedCollection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/SegmentedOrderedCollection.st,v 1.10 2014-07-20 18:15:26 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/SegmentedOrderedCollection.st,v 1.11 2014-07-26 08:13:10 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic2/SegmentedOrderedCollection.st,v 1.10 2014-07-20 18:15:26 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/SegmentedOrderedCollection.st,v 1.11 2014-07-26 08:13:10 cg Exp $'
 ! !