AutoResizingOrderedCollection.st
author Jan Vrany <jan.vrany@labware.com>
Wed, 30 Jun 2021 14:07:56 +0100
branchjv
changeset 5481 19d6355dc3e1
parent 4134 19fc23e191de
child 4332 e273ae4149cc
permissions -rw-r--r--
Cherry-picked `Unicode32String` from 48677b66883e: cherry-picked Unicode32String.st from 48677b66883e: * cb05c61f9204: #FEATURE by stefan, Stefan Vogel <sv@exept.de> * 5f6a992925c2: #DOCUMENTATION by stefan, Stefan Vogel <sv@exept.de> * 45176601c636: #BUGFIX by exept, Claus Gittinger <cg@exept.de> * d6f50be034db: #REFACTORING by stefan, Stefan Vogel <sv@exept.de> * ae8ed6040c96: #REFACTORING by stefan, Stefan Vogel <sv@exept.de>

"{ Package: 'stx:libbasic2' }"

"{ NameSpace: Smalltalk }"

OrderedCollection subclass:#AutoResizingOrderedCollection
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Collections-Sequenceable'
!

!AutoResizingOrderedCollection class methodsFor:'documentation'!

documentation
"
    I am an ordered collection which automatically resizes if elements
    are added beyond the size. 
    I.e. if #at:put: is sent for indexes > the current size, the receiver grows to
    the required index and missing fields are implicitly filled with nils.
    Queries for non-existing elements are anwered with nil.

    [see also:]
        OrderedCollection
        Array
        SparseArray
"
!

examples
"
    |coll|
    
    coll := AutoResizingOrderedCollection new.
    coll at:4 put:'four'.
    coll at:8 put:'eight'.
    coll at:9
"
! !

!AutoResizingOrderedCollection class methodsFor:'instance creation'!

newWithDefaultValue:defaultValue
    ^ AutoResizingOrderedCollectionWithDefault new setDefaultValue:defaultValue
! !

!AutoResizingOrderedCollection methodsFor:'accessing'!

at:index
    "fetch an object at index.
     If index is beyond the actual size, return nil
     (i.e. this is an alias for at:index ifAbsent:[nil])"
     
    index > self size ifTrue:[^ nil].
    ^ super at:index
!

at:index put:anObject
    "store an object at index.
     If required, grow the receiver to ensure that index is valid"
     
    index > self size ifTrue:[
        self grow:index.
    ].
    super at:index put:anObject
! !

!AutoResizingOrderedCollection class methodsFor:'documentation'!

version
    ^ '$Header$'
!

version_CVS
    ^ '$Header$'
! !