author | Merge Script |
Mon, 06 Jun 2016 06:56:04 +0200 | |
branch | jv |
changeset 3882 | a013a37e2c3d |
parent 3879 | 0b5011fc50ef |
permissions | -rw-r--r-- |
376 | 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 |
" |
|
1177 | 12 |
"{ Package: 'stx:libbasic2' }" |
13 |
||
3708 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
1177 | 16 |
UnboxedIntegerArray variableWordSubclass:#WordArray |
376 | 17 |
instanceVariableNames:'' |
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Collections-Arrayed' |
|
21 |
! |
|
22 |
||
23 |
!WordArray class methodsFor:'documentation'! |
|
24 |
||
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. |
|
1177 | 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. |
|
736 | 48 |
For example: |
49 |
Array new:100000 withAll:1 |
|
50 |
requires 400k of object memory; |
|
376 | 51 |
|
736 | 52 |
in contrast, |
53 |
WordArray new:100000 withAll:1 |
|
54 |
only requires half of it. |
|
55 |
||
56 |
[memory requirements:] |
|
57 |
OBJ-HEADER + (size * 2) |
|
376 | 58 |
|
59 |
[see also:] |
|
736 | 60 |
ByteArray BooleanArray FloatArray DoubleArray Array |
61 |
SignedWordArray |
|
376 | 62 |
|
63 |
[author:] |
|
736 | 64 |
Claus Gittinger |
376 | 65 |
" |
66 |
! ! |
|
67 |
||
2645
1950f0398db0
faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents:
1414
diff
changeset
|
68 |
!WordArray class methodsFor:'queries'! |
1950f0398db0
faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents:
1414
diff
changeset
|
69 |
|
1950f0398db0
faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents:
1414
diff
changeset
|
70 |
elementByteSize |
3330 | 71 |
"for bit-like containers, return the number of bytes stored per element. |
72 |
Here, 2 is returned" |
|
73 |
||
2645
1950f0398db0
faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents:
1414
diff
changeset
|
74 |
^ 2 |
1950f0398db0
faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents:
1414
diff
changeset
|
75 |
|
1950f0398db0
faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents:
1414
diff
changeset
|
76 |
"Created: / 15-09-2011 / 14:10:54 / cg" |
3735 | 77 |
! |
78 |
||
79 |
maxVal |
|
3879 | 80 |
"the maximum value which can be stored in instances of me. |
81 |
For WordArrays, this is 16rFFFF (largest 16bit unsigned int)" |
|
3868 | 82 |
|
3735 | 83 |
^ 16rFFFF |
3868 | 84 |
! |
85 |
||
86 |
minVal |
|
3879 | 87 |
"the minimum value which can be stored in instances of me. |
88 |
For WordArrays, this is 0" |
|
3868 | 89 |
|
90 |
^ 0 |
|
2645
1950f0398db0
faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents:
1414
diff
changeset
|
91 |
! ! |
1950f0398db0
faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents:
1414
diff
changeset
|
92 |
|
3708 | 93 |
!WordArray methodsFor:'accessing'! |
94 |
||
3755 | 95 |
unsignedInt16At:index MSB:msb |
3708 | 96 |
"return the 2-bytes starting at index as an (unsigned) Integer. |
97 |
The index is a smalltalk index (i.e. 1-based). |
|
98 |
The value is retrieved MSB (high 8 bits at lower index) if msb is true; |
|
99 |
LSB-first (i.e. low 8-bits at lower byte index) if its false. |
|
100 |
Notice: |
|
101 |
the index is a byte index; thus, this allows for unaligned access to |
|
3755 | 102 |
words on any boundary" |
3708 | 103 |
|
104 |
|w| |
|
105 |
||
106 |
index odd ifTrue:[ |
|
107 |
"/ aligned fetch |
|
108 |
w := self at:(index // 2) + 1. |
|
109 |
(msb ~~ UninterpretedBytes isBigEndian) ifTrue:[ |
|
110 |
w := w swapBytes |
|
111 |
]. |
|
112 |
^ w |
|
113 |
]. |
|
3755 | 114 |
^ super unsignedInt16At:index MSB:msb |
3708 | 115 |
|
116 |
" |
|
117 |
#(16r0201 16r0403 16r0605) asWordArray wordAt:1 MSB:false |
|
118 |
#(16r0201 16r0403 16r0605) asWordArray wordAt:3 MSB:false |
|
119 |
#(16r0201 16r0403 16r0605) asWordArray wordAt:5 MSB:false |
|
120 |
||
121 |
#(16r0201 16r0403 16r0605) asWordArray wordAt:2 MSB:false |
|
122 |
#(16r0201 16r0403 16r0605) asWordArray wordAt:4 MSB:false |
|
123 |
||
124 |
#(16rFFEE 16r0403 16r0605) asWordArray wordAt:1 MSB:false |
|
125 |
#(16rFFEE 16r0403 16r0605) asWordArray wordAt:1 MSB:true |
|
126 |
" |
|
127 |
! ! |
|
2645
1950f0398db0
faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents:
1414
diff
changeset
|
128 |
|
376 | 129 |
!WordArray class methodsFor:'documentation'! |
130 |
||
131 |
version |
|
3708 | 132 |
^ '$Header$' |
3879 | 133 |
! |
134 |
||
135 |
version_CVS |
|
136 |
^ '$Header$' |
|
376 | 137 |
! ! |
3330 | 138 |