|
Class: SegmentedOrderedCollection
Object
|
+--Collection
|
+--SequenceableCollection
|
+--SegmentedOrderedCollection
- Package:
- stx:libbasic2
- Category:
- Collections-Sequenceable
- Version:
- rev:
1.17
date: 2017/01/26 10:59:02
- user: cg
- file: SegmentedOrderedCollection.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
- Author:
- Claus Gittinger
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.
Compared to regular orderedColletions, there is not much of a difference if
elements are added at either end.
However, when adding/removing inner elements, the performance of SegmentedOrderedCollections
is much better above a certain number of elements (actually quite big).
However, notice again:
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).
Array
OrderedCollection
BTree
instance creation
-
new
-
return an initialized instance
-
new: size
-
return an initialized instance with space for size elements.
However, be aware that the logical size is 0
accessing
-
at: index
-
return the element at index, anInteger
-
at: index put: newElement
-
set the element at index, to be anInteger.
Return anObject (sigh).
-
first
-
return the first element
-
last
-
return the last element
adding & removing
-
add: anObject
-
add anObject to the end.
Returns the object (sigh)
-
add: anObject beforeIndex: index
-
insert the first argument, anObject into the collection before slot index.
Return the receiver (sigh - ST-80 compatibility).
Notice that this modifies the receiver, NOT a copy.
-
addFirst: anObject
-
add anObject to the beginning (insert as new first element).
-
removeAll
-
remove all elements from the receiver. Returns the receiver.
-
removeFirst
-
remove the first element from the collection; return the element.
If there is no element in the receiver collection, raise an error.
-
removeFirstIfAbsent: exceptionBlock
-
remove the first element from the collection; return the element.
If there is no element in the receiver collection, return the value from
exceptionBlock.
Destructive: modifies the receiver
-
removeFromIndex: startIndex toIndex: endIndex
-
remove the elements stored under startIndex up to and including
the elements under stopIndex.
Return the receiver.
Returning the receiver here is a historic leftover - it may change.
Please use yourself in a cascade, if you need the receiver's value
when using this method.
-
removeLast
-
remove the last element from the collection; return the element
enumerating
-
do: aBlock
-
evaluate the argument, aBlock for every element in the collection.
-
keysAndValuesDo: aBlock
-
evaluate the argument, aBlock for every element in the collection,
passing both index and element as arguments.
grow & shrink
-
grow: newSize
-
adjust the logical size to newSize
initialization
-
initialize
-
Invoked when a new instance is created.
private
-
splitSegmentAt: segmentIndex
-
queries
-
isFixedSize
-
return true if the receiver cannot grow
-
size
-
return the number of elements in the collection
|