23963
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
20653
|
3 |
"
|
|
4 |
COPYRIGHT (c) 1997 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 |
UnboxedIntegerArray variableLongSubclass:#IntegerArray
|
|
19 |
instanceVariableNames:''
|
|
20 |
classVariableNames:''
|
|
21 |
poolDictionaries:''
|
|
22 |
category:'Collections-Arrayed'
|
|
23 |
!
|
|
24 |
|
|
25 |
!IntegerArray class methodsFor:'documentation'!
|
|
26 |
|
|
27 |
copyright
|
|
28 |
"
|
|
29 |
COPYRIGHT (c) 1997 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 |
IntegerArrays store integers in the range 0..16rFFFFFFFF.
|
|
44 |
In contrast to normal arrays (which store pointers to their elements),
|
|
45 |
integerArrays store the values in a dense & compact way.
|
|
46 |
Since the representation fits the underlying C-language systems representation
|
|
47 |
of unsigned int32's, this is also useful to pass bulk data to c primitive code.
|
|
48 |
|
|
49 |
[memory requirements:]
|
|
50 |
OBJ-HEADER + (size * 4)
|
|
51 |
|
|
52 |
[see also:]
|
|
53 |
ByteArray BooleanArray FloatArray DoubleArray Array
|
|
54 |
SignedWordArray WordArray
|
|
55 |
|
23963
|
56 |
[caveat:]
|
|
57 |
should probably be renamed to UnsignedInt32Array
|
|
58 |
|
20653
|
59 |
[author:]
|
|
60 |
Claus Gittinger
|
|
61 |
"
|
|
62 |
! !
|
|
63 |
|
|
64 |
!IntegerArray class methodsFor:'queries'!
|
|
65 |
|
|
66 |
elementByteSize
|
|
67 |
"for bit-like containers, return the number of bytes stored per element.
|
|
68 |
Here, 4 is returned"
|
|
69 |
|
|
70 |
^ 4
|
|
71 |
|
|
72 |
"Created: / 15-09-2011 / 14:12:15 / cg"
|
|
73 |
!
|
|
74 |
|
|
75 |
maxVal
|
|
76 |
"the maximum value which can be stored in instances of me"
|
|
77 |
|
|
78 |
^ 16rFFFFFFFF
|
|
79 |
!
|
|
80 |
|
|
81 |
minVal
|
|
82 |
"the minimum value which can be stored in instances of me"
|
|
83 |
|
|
84 |
^ 0
|
|
85 |
! !
|
|
86 |
|
|
87 |
!IntegerArray methodsFor:'accessing'!
|
|
88 |
|
|
89 |
unsignedInt32At:index MSB:msb
|
|
90 |
"return the 4-bytes starting at index as an (unsigned) Integer.
|
|
91 |
The index is a smalltalk index (i.e. 1-based).
|
|
92 |
The value is retrieved MSB (high 8 bits at lower index) if msb is true;
|
21428
|
93 |
LSB-first (i.e. low 8-bits at lower byte index) if it's false.
|
20653
|
94 |
Notice:
|
|
95 |
the index is a byte index; thus, this allows for unaligned access to
|
21691
|
96 |
words on any boundary."
|
20653
|
97 |
|
|
98 |
|w|
|
|
99 |
|
|
100 |
(index bitAnd: 16r03) == 1 ifTrue:[
|
|
101 |
"/ aligned fetch
|
|
102 |
w := self at:(index // 4) + 1.
|
|
103 |
(msb ~~ UninterpretedBytes isBigEndian) ifTrue:[
|
|
104 |
w := w swapBytes
|
|
105 |
].
|
|
106 |
^ w
|
|
107 |
].
|
|
108 |
^ super unsignedInt32At:index MSB:msb
|
|
109 |
|
|
110 |
"
|
|
111 |
#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:1 MSB:false
|
|
112 |
#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:5 MSB:false
|
|
113 |
#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:9 MSB:false
|
|
114 |
|
|
115 |
#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:2 MSB:false
|
|
116 |
#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:3 MSB:false
|
|
117 |
#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:4 MSB:false
|
|
118 |
|
|
119 |
#(16rFFEE 16r0403 16r0605) asIntegerArray unsignedInt32At:1 MSB:false
|
|
120 |
#(16rFFEE 16r0403 16r0605) asIntegerArray unsignedInt32At:1 MSB:true
|
|
121 |
"
|
21428
|
122 |
|
21691
|
123 |
"Modified (comment): / 10-04-2017 / 11:28:01 / cg"
|
20653
|
124 |
! !
|
|
125 |
|
|
126 |
!IntegerArray methodsFor:'comparing'!
|
|
127 |
|
|
128 |
< anIntegerArray
|
|
129 |
"Compare the receiver with the argument and return true if the
|
|
130 |
receiver is greater than the argument. Otherwise return false.
|
|
131 |
|
|
132 |
Redefined for speed (xpath handling)"
|
|
133 |
|
|
134 |
%{ /* NOCONTEXT */
|
|
135 |
|
|
136 |
int len1, len2, min, i;
|
|
137 |
REGISTER OBJ s = anIntegerArray;
|
|
138 |
unsigned int *ip1, *ip2;
|
|
139 |
OBJ cls;
|
|
140 |
OBJ myCls;
|
|
141 |
|
|
142 |
if (__isNonNilObject(s)) {
|
|
143 |
cls = __qClass(s);
|
|
144 |
myCls = __qClass(self);
|
|
145 |
|
|
146 |
if ((cls == IntegerArray) || (cls == myCls)) {
|
|
147 |
ip2 = __integerArrayVal(s);
|
|
148 |
len2 = __integerArraySize(s);
|
|
149 |
/*
|
|
150 |
* care for instances of subclasses ...
|
|
151 |
*/
|
|
152 |
if (cls != IntegerArray) {
|
|
153 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)) / sizeof(__integerArrayVal(s));
|
|
154 |
|
|
155 |
ip2 += n;
|
|
156 |
len2 -= n;
|
|
157 |
}
|
|
158 |
|
|
159 |
ip1 = __integerArrayVal(self);
|
|
160 |
len1 = __integerArraySize(self);
|
|
161 |
/*
|
|
162 |
* care for instances of subclasses ...
|
|
163 |
*/
|
|
164 |
if (myCls != IntegerArray) {
|
|
165 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars)) / sizeof(__integerArrayVal(s));
|
|
166 |
|
|
167 |
ip1 += n;
|
|
168 |
len1 -= n;
|
|
169 |
}
|
|
170 |
|
|
171 |
if (len1 <= len2)
|
|
172 |
min = len1;
|
|
173 |
else
|
|
174 |
min = len2;
|
|
175 |
|
|
176 |
for (i = 0; i < min; i++) {
|
|
177 |
if (ip1[i] < ip2[i]) {
|
|
178 |
RETURN(true)
|
|
179 |
}
|
|
180 |
if (ip1[i] > ip2[i]) {
|
|
181 |
RETURN(false)
|
|
182 |
}
|
|
183 |
}
|
|
184 |
|
|
185 |
if (len1 < len2) {
|
|
186 |
RETURN ( true );
|
|
187 |
}
|
|
188 |
RETURN ( false );
|
|
189 |
}
|
|
190 |
}
|
|
191 |
%}.
|
|
192 |
^ super < anIntegerArray
|
|
193 |
|
|
194 |
|
|
195 |
"
|
|
196 |
(IntegerArray newFrom:#[1 2 3 4 5]) < (IntegerArray newFrom:#[1 2 3 4 5])
|
|
197 |
(IntegerArray newFrom:#[1 2 3 4 5]) < (IntegerArray newFrom:#[1 2 3 4])
|
|
198 |
(IntegerArray newFrom:#[1 2 3 4]) < (IntegerArray newFrom:#[1 2 3 4 5])
|
|
199 |
(IntegerArray newFrom:#[1 2 3 4 5]) < (IntegerArray newFrom:#[1 2 3 4 6])
|
|
200 |
(IntegerArray newFrom:#[]) < (IntegerArray newFrom:#[1 2 3 4 6])
|
|
201 |
"
|
|
202 |
! !
|
|
203 |
|
|
204 |
!IntegerArray methodsFor:'converting'!
|
|
205 |
|
|
206 |
asIntegerArray
|
|
207 |
"return a new IntegerArray with the collection's elements.
|
|
208 |
That's the receiver itself here"
|
|
209 |
|
|
210 |
^ self.
|
|
211 |
! !
|
|
212 |
|
|
213 |
!IntegerArray class methodsFor:'documentation'!
|
|
214 |
|
|
215 |
version
|
|
216 |
^ '$Header$'
|
|
217 |
!
|
|
218 |
|
|
219 |
version_CVS
|
|
220 |
^ '$Header$'
|
|
221 |
! !
|
|
222 |
|