UnboxedIntegerArray.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 20:55:17 +0200
changeset 24417 03b083548da2
parent 23968 53c2dc17d441
permissions -rw-r--r--
#REFACTORING by exept class: Smalltalk class changed: #recursiveInstallAutoloadedClassesFrom:rememberIn:maxLevels:noAutoload:packageTop:showSplashInLevels: Transcript showCR:(... bindWith:...) -> Transcript showCR:... with:...

"{ Encoding: utf8 }"

"
 COPYRIGHT (c) 2003 by 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:libbasic' }"

"{ NameSpace: Smalltalk }"

AbstractNumberVector subclass:#UnboxedIntegerArray
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Collections-Arrayed'
!

!UnboxedIntegerArray class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2003 by 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
"
    An abstract superclass for all unboxed integer classes.
    In contrast to normal arrays (which store pointers to their elements),
    unboxedIntegerArrays store the values in a dense & compact way. 
    Since the representation fits corresponding underlying C-language representations,
    these are also useful to pass bulk data to c primitive code.

    [see also:]
        ByteArray WordArray BooleanArray FloatArray DoubleArray Array
        IntegerArray LongIntegerArray SignedLongIntegerArray

    [author:]
        Claus Gittinger
"
! !

!UnboxedIntegerArray class methodsFor:'instance creation'!

new:size elementBitSize:nBitsPerElement signed:signedBoolean
    "return a new instance for size elements,
     each holding an nBitsPerElement-sized integer.
     With nBitsPerElement == 8, this returns a byteArray/signedByteArray,
     with nBitsPerElement == 16, a word/signedWordArray
     with nBitsPerElement == 32, an integer/signedIntegerArray
     and with nBitsPerElement == 65, a longInteger/signedLongIntegerArray
     Other sizes might be provided in the future."

    nBitsPerElement == 8 ifTrue:[
        ^ (signedBoolean ifTrue:[SignedByteArray] ifFalse:[ByteArray]) new:size
    ].    
    nBitsPerElement == 16 ifTrue:[
        ^ (signedBoolean ifTrue:[SignedWordArray] ifFalse:[WordArray]) new:size
    ].    
    nBitsPerElement == 32 ifTrue:[
        ^ (signedBoolean ifTrue:[SignedIntegerArray] ifFalse:[IntegerArray]) new:size
    ].    
    nBitsPerElement == 64 ifTrue:[
        ^ (signedBoolean ifTrue:[SignedLongIntegerArray] ifFalse:[LongIntegerArray]) new:size
    ].
    self error:'unsupported bits-per integer'

    "
     self new:10 elementBitSize:8 signed:false
     self new:10 elementBitSize:8 signed:true
     self new:10 elementBitSize:16 signed:true
     self new:10 elementBitSize:64 signed:true
    "

    "Created: / 24-03-2019 / 12:22:53 / Claus Gittinger"
! !

!UnboxedIntegerArray class methodsFor:'queries'!

isAbstract
    "Return if this class is an abstract class.
     True is returned for UnboxedIntegerArray here; false for subclasses.
     Abstract subclasses must redefine this again."

    ^ self == UnboxedIntegerArray
! !

!UnboxedIntegerArray methodsFor:'printing'!

printOn:aStream base:radix showRadix:showRadix
    "append a printed representation to aStream in the given number base."

    (self class == WordArray or:[self class == LongIntegerArray]) 
    ifTrue:[    "/ care for subclasses
        aStream nextPutAll:'#('.
        self 
            do:[:word | word printOn:aStream base:radix showRadix:showRadix]
            separatedBy:[aStream space].
        aStream nextPut:$).
        ^ self
    ].
    ^ self printOn:aStream
! !

!UnboxedIntegerArray methodsFor:'queries'!

defaultElement
    ^ 0
!

isValidElement:anObject
    "return true, if I can hold this kind of object"

    ^ anObject isInteger
    and:[ (anObject >= self class minVal)
    and:[ (anObject <= self class maxVal) ]]
! !

!UnboxedIntegerArray methodsFor:'testing'!

isIntegerArray
    "return true if the receiver has integer elements.
     These are Byte- and Integer arrays; both signed and unsigned"

    ^ true

    "Created: / 02-03-2019 / 23:10:28 / Claus Gittinger"
! !

!UnboxedIntegerArray class methodsFor:'documentation'!

version
    ^ '$Header$'
!

version_CVS
    ^ '$Header$'
! !