author | Merge Script |
Mon, 06 Jun 2016 06:56:04 +0200 | |
branch | jv |
changeset 3882 | a013a37e2c3d |
parent 3869 | d80d50eb684e |
permissions | -rw-r--r-- |
601 | 1 |
" |
736 | 2 |
COPYRIGHT (c) 1997 by eXept Software AG |
601 | 3 |
All Rights Reserved |
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
1177 | 12 |
"{ Package: 'stx:libbasic2' }" |
13 |
||
3709 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
1177 | 16 |
UnboxedIntegerArray variableLongSubclass:#IntegerArray |
601 | 17 |
instanceVariableNames:'' |
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Collections-Arrayed' |
|
21 |
! |
|
22 |
||
23 |
!IntegerArray class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
41 |
IntegerArrays store integers in the range 0..16rFFFFFFFF. |
|
42 |
In contrast to normal arrays (which store pointers to their elements), |
|
43 |
integerArrays store the values in a dense & compact way. |
|
44 |
Since the representation fits the underlying C-language systems representation |
|
45 |
of unsigned int32's, this is also useful to pass bulk data to c primitive code. |
|
46 |
||
736 | 47 |
[memory requirements:] |
48 |
OBJ-HEADER + (size * 4) |
|
49 |
||
601 | 50 |
[see also:] |
736 | 51 |
ByteArray BooleanArray FloatArray DoubleArray Array |
52 |
SignedWordArray WordArray |
|
601 | 53 |
|
54 |
[author:] |
|
736 | 55 |
Claus Gittinger |
601 | 56 |
" |
57 |
! ! |
|
58 |
||
2640
21e2ea3c88a5
faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents:
2289
diff
changeset
|
59 |
!IntegerArray class methodsFor:'queries'! |
21e2ea3c88a5
faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents:
2289
diff
changeset
|
60 |
|
21e2ea3c88a5
faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents:
2289
diff
changeset
|
61 |
elementByteSize |
3336
c07bb7638ac1
comment/format in: #elementByteSize
Claus Gittinger <cg@exept.de>
parents:
2640
diff
changeset
|
62 |
"for bit-like containers, return the number of bytes stored per element. |
c07bb7638ac1
comment/format in: #elementByteSize
Claus Gittinger <cg@exept.de>
parents:
2640
diff
changeset
|
63 |
Here, 4 is returned" |
c07bb7638ac1
comment/format in: #elementByteSize
Claus Gittinger <cg@exept.de>
parents:
2640
diff
changeset
|
64 |
|
2640
21e2ea3c88a5
faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents:
2289
diff
changeset
|
65 |
^ 4 |
21e2ea3c88a5
faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents:
2289
diff
changeset
|
66 |
|
21e2ea3c88a5
faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents:
2289
diff
changeset
|
67 |
"Created: / 15-09-2011 / 14:12:15 / cg" |
3729 | 68 |
! |
69 |
||
70 |
maxVal |
|
3869 | 71 |
"the maximum value which can be stored in instances of me" |
72 |
||
3729 | 73 |
^ 16rFFFFFFFF |
3869 | 74 |
! |
75 |
||
76 |
minVal |
|
77 |
"the minimum value which can be stored in instances of me" |
|
78 |
||
79 |
^ 0 |
|
2640
21e2ea3c88a5
faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents:
2289
diff
changeset
|
80 |
! ! |
21e2ea3c88a5
faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents:
2289
diff
changeset
|
81 |
|
3709 | 82 |
!IntegerArray methodsFor:'accessing'! |
83 |
||
3766 | 84 |
unsignedInt32At:index MSB:msb |
3709 | 85 |
"return the 4-bytes starting at index as an (unsigned) Integer. |
86 |
The index is a smalltalk index (i.e. 1-based). |
|
87 |
The value is retrieved MSB (high 8 bits at lower index) if msb is true; |
|
88 |
LSB-first (i.e. low 8-bits at lower byte index) if its false. |
|
89 |
Notice: |
|
90 |
the index is a byte index; thus, this allows for unaligned access to |
|
91 |
words on any boundary. |
|
92 |
Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)" |
|
93 |
||
94 |
|w| |
|
95 |
||
96 |
(index bitAnd: 16r03) == 1 ifTrue:[ |
|
97 |
"/ aligned fetch |
|
98 |
w := self at:(index // 4) + 1. |
|
99 |
(msb ~~ UninterpretedBytes isBigEndian) ifTrue:[ |
|
100 |
w := w swapBytes |
|
101 |
]. |
|
102 |
^ w |
|
103 |
]. |
|
3766 | 104 |
^ super unsignedInt32At:index MSB:msb |
3709 | 105 |
|
106 |
" |
|
3766 | 107 |
#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:1 MSB:false |
108 |
#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:5 MSB:false |
|
109 |
#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:9 MSB:false |
|
3709 | 110 |
|
3766 | 111 |
#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:2 MSB:false |
112 |
#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:3 MSB:false |
|
113 |
#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:4 MSB:false |
|
3709 | 114 |
|
3766 | 115 |
#(16rFFEE 16r0403 16r0605) asIntegerArray unsignedInt32At:1 MSB:false |
116 |
#(16rFFEE 16r0403 16r0605) asIntegerArray unsignedInt32At:1 MSB:true |
|
3709 | 117 |
" |
118 |
! ! |
|
119 |
||
1445 | 120 |
!IntegerArray methodsFor:'comparing'! |
121 |
||
122 |
< anIntegerArray |
|
123 |
"Compare the receiver with the argument and return true if the |
|
124 |
receiver is greater than the argument. Otherwise return false. |
|
125 |
||
126 |
Redefined for speed (xpath handling)" |
|
127 |
||
128 |
%{ /* NOCONTEXT */ |
|
129 |
||
130 |
int len1, len2, min, i; |
|
131 |
REGISTER OBJ s = anIntegerArray; |
|
132 |
unsigned int *ip1, *ip2; |
|
133 |
OBJ cls; |
|
134 |
OBJ myCls; |
|
135 |
||
136 |
if (__isNonNilObject(s)) { |
|
137 |
cls = __qClass(s); |
|
138 |
myCls = __qClass(self); |
|
139 |
||
140 |
if ((cls == IntegerArray) || (cls == myCls)) { |
|
141 |
ip2 = __integerArrayVal(s); |
|
142 |
len2 = __integerArraySize(s); |
|
143 |
/* |
|
144 |
* care for instances of subclasses ... |
|
145 |
*/ |
|
146 |
if (cls != IntegerArray) { |
|
147 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)) / sizeof(__integerArrayVal(s)); |
|
148 |
||
149 |
ip2 += n; |
|
150 |
len2 -= n; |
|
151 |
} |
|
152 |
||
153 |
ip1 = __integerArrayVal(self); |
|
154 |
len1 = __integerArraySize(self); |
|
155 |
/* |
|
156 |
* care for instances of subclasses ... |
|
157 |
*/ |
|
158 |
if (myCls != IntegerArray) { |
|
159 |
int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars)) / sizeof(__integerArrayVal(s)); |
|
160 |
||
161 |
ip1 += n; |
|
162 |
len1 -= n; |
|
163 |
} |
|
164 |
||
165 |
if (len1 <= len2) |
|
166 |
min = len1; |
|
167 |
else |
|
168 |
min = len2; |
|
169 |
||
170 |
for (i = 0; i < min; i++) { |
|
171 |
if (ip1[i] < ip2[i]) { |
|
172 |
RETURN(true) |
|
173 |
} |
|
174 |
if (ip1[i] > ip2[i]) { |
|
175 |
RETURN(false) |
|
176 |
} |
|
177 |
} |
|
178 |
||
179 |
if (len1 < len2) { |
|
180 |
RETURN ( true ); |
|
181 |
} |
|
182 |
RETURN ( false ); |
|
183 |
} |
|
184 |
} |
|
185 |
%}. |
|
186 |
^ super < anIntegerArray |
|
187 |
||
188 |
||
189 |
" |
|
190 |
(IntegerArray newFrom:#[1 2 3 4 5]) < (IntegerArray newFrom:#[1 2 3 4 5]) |
|
191 |
(IntegerArray newFrom:#[1 2 3 4 5]) < (IntegerArray newFrom:#[1 2 3 4]) |
|
192 |
(IntegerArray newFrom:#[1 2 3 4]) < (IntegerArray newFrom:#[1 2 3 4 5]) |
|
193 |
(IntegerArray newFrom:#[1 2 3 4 5]) < (IntegerArray newFrom:#[1 2 3 4 6]) |
|
194 |
(IntegerArray newFrom:#[]) < (IntegerArray newFrom:#[1 2 3 4 6]) |
|
195 |
" |
|
196 |
! ! |
|
197 |
||
2289 | 198 |
!IntegerArray methodsFor:'converting'! |
199 |
||
200 |
asIntegerArray |
|
201 |
"return a new IntegerArray with the collection's elements. |
|
202 |
That's the receiver itself here" |
|
203 |
||
204 |
^ self. |
|
205 |
! ! |
|
206 |
||
601 | 207 |
!IntegerArray class methodsFor:'documentation'! |
208 |
||
209 |
version |
|
3709 | 210 |
^ '$Header$' |
2289 | 211 |
! |
212 |
||
213 |
version_CVS |
|
3709 | 214 |
^ '$Header$' |
601 | 215 |
! ! |
3336
c07bb7638ac1
comment/format in: #elementByteSize
Claus Gittinger <cg@exept.de>
parents:
2640
diff
changeset
|
216 |