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:...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23968
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
     1
"{ Encoding: utf8 }"
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
     2
20648
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
 COPYRIGHT (c) 2003 by eXept Software AG
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
              All Rights Reserved
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 This software is furnished under a license and may be used
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 hereby transferred.
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ Package: 'stx:libbasic' }"
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
"{ NameSpace: Smalltalk }"
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
AbstractNumberVector subclass:#UnboxedIntegerArray
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:''
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	classVariableNames:''
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	category:'Collections-Arrayed'
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
!UnboxedIntegerArray class methodsFor:'documentation'!
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
copyright
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
"
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 COPYRIGHT (c) 2003 by eXept Software AG
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
              All Rights Reserved
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 This software is furnished under a license and may be used
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 only in accordance with the terms of that license and with the
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 be provided or otherwise made available to, or used by, any
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 other person.  No title to or ownership of the software is
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 hereby transferred.
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
"
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
!
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
documentation
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
"
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    An abstract superclass for all unboxed integer classes.
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    In contrast to normal arrays (which store pointers to their elements),
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    unboxedIntegerArrays store the values in a dense & compact way. 
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    Since the representation fits corresponding underlying C-language representations,
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
    these are also useful to pass bulk data to c primitive code.
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
    [see also:]
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
        ByteArray WordArray BooleanArray FloatArray DoubleArray Array
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
        IntegerArray LongIntegerArray SignedLongIntegerArray
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    [author:]
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
        Claus Gittinger
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
"
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
! !
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
23968
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    58
!UnboxedIntegerArray class methodsFor:'instance creation'!
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    59
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    60
new:size elementBitSize:nBitsPerElement signed:signedBoolean
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    61
    "return a new instance for size elements,
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    62
     each holding an nBitsPerElement-sized integer.
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    63
     With nBitsPerElement == 8, this returns a byteArray/signedByteArray,
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    64
     with nBitsPerElement == 16, a word/signedWordArray
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    65
     with nBitsPerElement == 32, an integer/signedIntegerArray
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    66
     and with nBitsPerElement == 65, a longInteger/signedLongIntegerArray
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    67
     Other sizes might be provided in the future."
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    68
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    69
    nBitsPerElement == 8 ifTrue:[
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    70
        ^ (signedBoolean ifTrue:[SignedByteArray] ifFalse:[ByteArray]) new:size
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    71
    ].    
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    72
    nBitsPerElement == 16 ifTrue:[
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    73
        ^ (signedBoolean ifTrue:[SignedWordArray] ifFalse:[WordArray]) new:size
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    74
    ].    
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    75
    nBitsPerElement == 32 ifTrue:[
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    76
        ^ (signedBoolean ifTrue:[SignedIntegerArray] ifFalse:[IntegerArray]) new:size
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    77
    ].    
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    78
    nBitsPerElement == 64 ifTrue:[
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    79
        ^ (signedBoolean ifTrue:[SignedLongIntegerArray] ifFalse:[LongIntegerArray]) new:size
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    80
    ].
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    81
    self error:'unsupported bits-per integer'
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    82
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    83
    "
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    84
     self new:10 elementBitSize:8 signed:false
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    85
     self new:10 elementBitSize:8 signed:true
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    86
     self new:10 elementBitSize:16 signed:true
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    87
     self new:10 elementBitSize:64 signed:true
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    88
    "
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    89
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    90
    "Created: / 24-03-2019 / 12:22:53 / Claus Gittinger"
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    91
! !
53c2dc17d441 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23807
diff changeset
    92
20648
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
!UnboxedIntegerArray class methodsFor:'queries'!
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
isAbstract
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
    "Return if this class is an abstract class.
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
     True is returned for UnboxedIntegerArray here; false for subclasses.
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
     Abstract subclasses must redefine this again."
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
    ^ self == UnboxedIntegerArray
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
! !
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
!UnboxedIntegerArray methodsFor:'printing'!
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
printOn:aStream base:radix showRadix:showRadix
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
    "append a printed representation to aStream in the given number base."
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
    (self class == WordArray or:[self class == LongIntegerArray]) 
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
    ifTrue:[    "/ care for subclasses
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
        aStream nextPutAll:'#('.
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
        self 
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
            do:[:word | word printOn:aStream base:radix showRadix:showRadix]
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
            separatedBy:[aStream space].
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
        aStream nextPut:$).
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
        ^ self
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
    ].
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
    ^ self printOn:aStream
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
! !
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
!UnboxedIntegerArray methodsFor:'queries'!
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
defaultElement
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
    ^ 0
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
!
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
23799
8076bb8b19ed #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23795
diff changeset
   126
isValidElement:anObject
8076bb8b19ed #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23795
diff changeset
   127
    "return true, if I can hold this kind of object"
8076bb8b19ed #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23795
diff changeset
   128
8076bb8b19ed #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23795
diff changeset
   129
    ^ anObject isInteger
8076bb8b19ed #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23795
diff changeset
   130
    and:[ (anObject >= self class minVal)
8076bb8b19ed #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23795
diff changeset
   131
    and:[ (anObject <= self class maxVal) ]]
8076bb8b19ed #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23795
diff changeset
   132
! !
8076bb8b19ed #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23795
diff changeset
   133
8076bb8b19ed #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23795
diff changeset
   134
!UnboxedIntegerArray methodsFor:'testing'!
8076bb8b19ed #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23795
diff changeset
   135
23795
cdb4f82cb732 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20648
diff changeset
   136
isIntegerArray
cdb4f82cb732 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20648
diff changeset
   137
    "return true if the receiver has integer elements.
cdb4f82cb732 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20648
diff changeset
   138
     These are Byte- and Integer arrays; both signed and unsigned"
cdb4f82cb732 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20648
diff changeset
   139
cdb4f82cb732 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20648
diff changeset
   140
    ^ true
cdb4f82cb732 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20648
diff changeset
   141
cdb4f82cb732 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20648
diff changeset
   142
    "Created: / 02-03-2019 / 23:10:28 / Claus Gittinger"
20648
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
! !
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
!UnboxedIntegerArray class methodsFor:'documentation'!
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
version
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
    ^ '$Header$'
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
!
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
version_CVS
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
    ^ '$Header$'
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
! !
170b94ae15fd initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154