20647
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
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 |
"
|
|
12 |
"{ Package: 'stx:libbasic' }"
|
|
13 |
|
|
14 |
"{ NameSpace: Smalltalk }"
|
|
15 |
|
|
16 |
UnboxedIntegerArray variableWordSubclass:#WordArray
|
|
17 |
instanceVariableNames:''
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Collections-Arrayed'
|
|
21 |
!
|
|
22 |
|
24716
|
23 |
!WordArray class methodsFor:'documentation'!
|
20647
|
24 |
|
24716
|
25 |
copyright
|
|
26 |
"
|
|
27 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
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 |
WordArrays store integers in the range 0..16rFFFF.
|
|
42 |
In contrast to normal arrays (which store pointers to their elements),
|
|
43 |
wordArrays store the values in a dense & compact way.
|
|
44 |
Since the representation fits the underlying C-language systems representation
|
|
45 |
of unsigned int16's, this is also useful to pass bulk data to c primitive code.
|
|
46 |
|
|
47 |
WordArrays can be used to hold bulk integer data in a more compact way.
|
|
48 |
For example:
|
|
49 |
Array new:100000 withAll:1
|
|
50 |
requires 400k of object memory;
|
|
51 |
|
|
52 |
in contrast,
|
|
53 |
WordArray new:100000 withAll:1
|
|
54 |
only requires half of it.
|
|
55 |
|
|
56 |
[memory requirements:]
|
|
57 |
OBJ-HEADER + (size * 2)
|
|
58 |
|
|
59 |
[see also:]
|
|
60 |
ByteArray BooleanArray FloatArray DoubleArray Array
|
|
61 |
SignedWordArray
|
|
62 |
|
|
63 |
[caveat:]
|
|
64 |
should probably be renamed to UnsignedInt16Array or UInt16Array
|
|
65 |
|
|
66 |
[author:]
|
|
67 |
Claus Gittinger
|
|
68 |
"
|
|
69 |
! !
|
20647
|
70 |
|
21436
|
71 |
|
|
72 |
|
24716
|
73 |
!WordArray class methodsFor:'queries'!
|
|
74 |
|
|
75 |
elementByteSize
|
|
76 |
"for bit-like containers, return the number of bytes stored per element.
|
|
77 |
Here, 2 is returned"
|
|
78 |
|
|
79 |
^ 2
|
|
80 |
|
|
81 |
"Created: / 15-09-2011 / 14:10:54 / cg"
|
|
82 |
!
|
|
83 |
|
|
84 |
maxVal
|
|
85 |
"the maximum value which can be stored in instances of me.
|
|
86 |
For WordArrays, this is 16rFFFF (largest 16bit unsigned int)"
|
|
87 |
|
|
88 |
^ 16rFFFF
|
|
89 |
!
|
|
90 |
|
|
91 |
minVal
|
|
92 |
"the minimum value which can be stored in instances of me.
|
|
93 |
For WordArrays, this is 0"
|
|
94 |
|
|
95 |
^ 0
|
|
96 |
! !
|
20647
|
97 |
|
21436
|
98 |
|
24716
|
99 |
!WordArray methodsFor:'accessing'!
|
20647
|
100 |
|
24716
|
101 |
unsignedInt16At:index MSB:msb
|
|
102 |
"return the 2-bytes starting at index as an (unsigned) Integer.
|
|
103 |
The index is a smalltalk index (i.e. 1-based).
|
|
104 |
The value is retrieved MSB (high 8 bits at lower index) if msb is true;
|
|
105 |
LSB-first (i.e. low 8-bits at lower byte index) if it's false.
|
|
106 |
Notice:
|
|
107 |
the index is a byte index; thus, this allows for unaligned access to
|
|
108 |
words on any boundary"
|
|
109 |
|
|
110 |
|w|
|
|
111 |
|
|
112 |
index odd ifTrue:[
|
|
113 |
"/ aligned fetch
|
|
114 |
w := self at:(index // 2) + 1.
|
|
115 |
(msb ~~ UninterpretedBytes isBigEndian) ifTrue:[
|
|
116 |
w := w swapBytes
|
|
117 |
].
|
|
118 |
^ w
|
|
119 |
].
|
|
120 |
^ super unsignedInt16At:index MSB:msb
|
|
121 |
|
|
122 |
"
|
|
123 |
#(16r0201 16r0403 16r0605) asWordArray wordAt:1 MSB:false
|
|
124 |
#(16r0201 16r0403 16r0605) asWordArray wordAt:3 MSB:false
|
|
125 |
#(16r0201 16r0403 16r0605) asWordArray wordAt:5 MSB:false
|
|
126 |
|
|
127 |
#(16r0201 16r0403 16r0605) asWordArray wordAt:2 MSB:false
|
|
128 |
#(16r0201 16r0403 16r0605) asWordArray wordAt:4 MSB:false
|
|
129 |
|
|
130 |
#(16rFFEE 16r0403 16r0605) asWordArray wordAt:1 MSB:false
|
|
131 |
#(16rFFEE 16r0403 16r0605) asWordArray wordAt:1 MSB:true
|
|
132 |
"
|
|
133 |
|
|
134 |
"Modified (comment): / 13-02-2017 / 20:34:38 / cg"
|
|
135 |
! !
|
|
136 |
|
|
137 |
!WordArray class methodsFor:'documentation'!
|
|
138 |
|
|
139 |
version_CVS
|
|
140 |
^ '$Header$'
|
|
141 |
! !
|
|
142 |
|