20655
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1995 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 |
This is a demo example:
|
|
13 |
|
|
14 |
THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND
|
|
15 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
16 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
17 |
ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE
|
|
18 |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
19 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
20 |
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
21 |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
22 |
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
23 |
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
24 |
SUCH DAMAGE.
|
|
25 |
"
|
|
26 |
"{ Package: 'stx:libbasic' }"
|
|
27 |
|
|
28 |
"{ NameSpace: Smalltalk }"
|
|
29 |
|
|
30 |
BitArray variableByteSubclass:#BooleanArray
|
|
31 |
instanceVariableNames:''
|
|
32 |
classVariableNames:''
|
|
33 |
poolDictionaries:''
|
|
34 |
category:'Collections-Arrayed'
|
|
35 |
!
|
|
36 |
|
|
37 |
!BooleanArray class methodsFor:'documentation'!
|
|
38 |
|
|
39 |
copyright
|
|
40 |
"
|
|
41 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
42 |
All Rights Reserved
|
|
43 |
|
|
44 |
This software is furnished under a license and may be used
|
|
45 |
only in accordance with the terms of that license and with the
|
|
46 |
inclusion of the above copyright notice. This software may not
|
|
47 |
be provided or otherwise made available to, or used by, any
|
|
48 |
other person. No title to or ownership of the software is
|
|
49 |
hereby transferred.
|
|
50 |
|
|
51 |
This is a demo example:
|
|
52 |
|
|
53 |
THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND
|
|
54 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
55 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
56 |
ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE
|
|
57 |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
58 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
59 |
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
60 |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
61 |
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
62 |
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
63 |
SUCH DAMAGE.
|
|
64 |
"
|
|
65 |
!
|
|
66 |
|
|
67 |
documentation
|
|
68 |
"
|
|
69 |
BooleanArrays are specially tuned to store booleans (true and false),
|
|
70 |
and are useful for bulk bit/boolean data.
|
|
71 |
|
|
72 |
Instances require only 1/32th (32bit machines) or even 1/64th (64bit machines)
|
|
73 |
of memory compared to a regular array of booleans.
|
|
74 |
|
|
75 |
They store 8 booleans per byte.
|
|
76 |
Since instances store bits in multiples of 8,
|
|
77 |
the real size of the collection is kept in an extra instance variable (tally).
|
|
78 |
It may be useful if huge boolean arrays are to be used.
|
|
79 |
|
|
80 |
ATTENTION:
|
|
81 |
inheriting from BitArray, bits 1 to 8 of the BooleanArray are stored in bits 8 to 1
|
|
82 |
of the corresponding byte, to allow easy mapping to ASN.1 BIT STRING encoding
|
|
83 |
in the BER.
|
|
84 |
Do not change this.
|
|
85 |
|
|
86 |
[memory requirements:]
|
|
87 |
OBJ-HEADER + ((size + 7) // 8)
|
|
88 |
|
|
89 |
[see also:]
|
|
90 |
ByteArray WordArray Array
|
|
91 |
|
|
92 |
[author:]
|
|
93 |
Claus Gittinger
|
|
94 |
"
|
|
95 |
!
|
|
96 |
|
|
97 |
examples
|
|
98 |
"
|
|
99 |
[exBegin]
|
|
100 |
(BooleanArray new:7) inspect
|
|
101 |
[exEnd]
|
|
102 |
[exBegin]
|
|
103 |
(BooleanArray new:7) basicInspect
|
|
104 |
[exEnd]
|
|
105 |
[exBegin]
|
|
106 |
|flags|
|
|
107 |
|
|
108 |
flags := BooleanArray new:1000000.
|
|
109 |
(flags at:9999) printNL.
|
|
110 |
flags at:9999 put:true.
|
|
111 |
(flags at:9999) printNL.
|
|
112 |
[exEnd]
|
|
113 |
"
|
|
114 |
! !
|
|
115 |
|
|
116 |
!BooleanArray methodsFor:'accessing'!
|
|
117 |
|
|
118 |
at:index
|
|
119 |
"retrieve the boolean at index"
|
|
120 |
|
|
121 |
^ (super at:index) == 1
|
|
122 |
|
|
123 |
"
|
|
124 |
(BooleanArray new:1000) at:555
|
|
125 |
"
|
|
126 |
|
|
127 |
"
|
|
128 |
|b|
|
|
129 |
|
|
130 |
b := BooleanArray new:1000.
|
|
131 |
b at:555 put:true.
|
|
132 |
b at:555
|
|
133 |
"
|
|
134 |
|
|
135 |
"Modified: / 31.7.1997 / 18:37:25 / cg"
|
|
136 |
"Modified: / 23.5.1999 / 20:02:57 / stefan"
|
|
137 |
!
|
|
138 |
|
|
139 |
at:index put:aBoolean
|
|
140 |
"store the argument, aBoolean at index; return aBoolean (sigh)."
|
|
141 |
|
|
142 |
|v|
|
|
143 |
|
|
144 |
aBoolean == true ifTrue:[
|
|
145 |
v := 1.
|
|
146 |
] ifFalse:[
|
|
147 |
aBoolean == false ifTrue:[
|
|
148 |
v := 0.
|
|
149 |
] ifFalse:[
|
|
150 |
"/ not true or false
|
|
151 |
^ self elementBoundsError:aBoolean
|
|
152 |
]
|
|
153 |
].
|
|
154 |
super at:index put:v.
|
|
155 |
^ aBoolean
|
|
156 |
|
|
157 |
"
|
|
158 |
|b|
|
|
159 |
|
|
160 |
b := BooleanArray new:1000.
|
|
161 |
b at:555 put:true.
|
|
162 |
b at:555
|
|
163 |
"
|
|
164 |
!
|
|
165 |
|
|
166 |
occurrencesOf:anElement
|
|
167 |
"count the occurrences of the argument, anElement in the receiver"
|
|
168 |
|
|
169 |
|nOnes|
|
|
170 |
|
|
171 |
nOnes := self countOnes.
|
|
172 |
anElement == true ifTrue:[
|
|
173 |
^ nOnes
|
|
174 |
].
|
|
175 |
anElement == false ifTrue:[
|
|
176 |
^ tally - nOnes
|
|
177 |
].
|
|
178 |
^ 0
|
|
179 |
|
|
180 |
"
|
|
181 |
(BooleanArray new:10)
|
|
182 |
at:4 put:true;
|
|
183 |
at:6 put:true;
|
|
184 |
at:7 put:true;
|
|
185 |
occurrencesOf:true
|
|
186 |
"
|
|
187 |
! !
|
|
188 |
|
|
189 |
!BooleanArray methodsFor:'filling & replacing'!
|
|
190 |
|
|
191 |
atAllPut:aBoolean
|
|
192 |
"replace all elements of the collection by the argument, aBoolean.
|
|
193 |
The argument, aBoolean must be true or false.
|
|
194 |
Notice: This operation modifies the receiver, NOT a copy;
|
|
195 |
therefore the change may affect all others referencing the receiver."
|
|
196 |
|
|
197 |
|v|
|
|
198 |
|
|
199 |
aBoolean == true ifTrue:[
|
|
200 |
v := 1
|
|
201 |
] ifFalse:[
|
|
202 |
aBoolean == false ifTrue:[
|
|
203 |
v := 0
|
|
204 |
] ifFalse:[
|
|
205 |
"/ booleanArrays can only hold true and false
|
|
206 |
^ self elementBoundsError:aBoolean
|
|
207 |
]
|
|
208 |
].
|
|
209 |
super atAllPut:v
|
|
210 |
! !
|
|
211 |
|
|
212 |
!BooleanArray methodsFor:'queries'!
|
|
213 |
|
|
214 |
defaultElement
|
|
215 |
^ false
|
|
216 |
!
|
|
217 |
|
|
218 |
isValidElement:anObject
|
|
219 |
"return true, if I can hold this kind of object"
|
|
220 |
|
|
221 |
^ anObject == true or:[anObject == false]
|
|
222 |
! !
|
|
223 |
|
|
224 |
!BooleanArray class methodsFor:'documentation'!
|
|
225 |
|
|
226 |
version
|
|
227 |
^ '$Header$'
|
|
228 |
!
|
|
229 |
|
|
230 |
version_CVS
|
|
231 |
^ '$Header$'
|
|
232 |
! !
|
|
233 |
|