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