AutoResizingOrderedCollection.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 4332 e273ae4149cc
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:

"
 COPYRIGHT (c) 2015 by Claus Gittinger / eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:libbasic2' }"

"{ NameSpace: Smalltalk }"

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

!AutoResizingOrderedCollection class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2015 by Claus Gittinger / eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

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$'
! !