author | Stefan Vogel <sv@exept.de> |
Thu, 08 Nov 2007 15:03:20 +0100 | |
changeset 1909 | c76efba26558 |
parent 1644 | 540979f371b3 |
child 2077 | 1ee59d1df2de |
permissions | -rw-r--r-- |
565 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by eXept Software AG / 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 |
||
27 |
||
893
823d2fa809e2
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
736
diff
changeset
|
28 |
"{ Package: 'stx:libbasic2' }" |
823d2fa809e2
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
736
diff
changeset
|
29 |
|
736 | 30 |
BooleanArray variableByteSubclass:#BitArray |
565 | 31 |
instanceVariableNames:'' |
32 |
classVariableNames:'' |
|
33 |
poolDictionaries:'' |
|
34 |
category:'Collections-Arrayed' |
|
35 |
! |
|
36 |
||
37 |
!BitArray class methodsFor:'documentation'! |
|
38 |
||
39 |
copyright |
|
40 |
" |
|
41 |
COPYRIGHT (c) 1997 by eXept Software AG / 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 |
||
68 |
documentation |
|
69 |
" |
|
70 |
like a booleanArray, but storing & returning 0's and 1's. |
|
71 |
||
736 | 72 |
[memory requirements:] |
73 |
OBJ-HEADER + ((size + 7) // 8) |
|
74 |
||
565 | 75 |
[author:] |
76 |
Claus Gittinger |
|
77 |
||
78 |
[see also:] |
|
79 |
BooleanArray ByteArray WordArray Array |
|
80 |
" |
|
81 |
! |
|
82 |
||
83 |
examples |
|
84 |
" |
|
85 |
[exBegin] |
|
86 |
(BitArray new:7) inspect |
|
87 |
[exEnd] |
|
88 |
[exBegin] |
|
89 |
(BitArray new:7) basicInspect |
|
90 |
[exEnd] |
|
91 |
[exBegin] |
|
92 |
|bits| |
|
93 |
||
94 |
bits := BitArray new:1000000. |
|
1644
540979f371b3
Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents:
1459
diff
changeset
|
95 |
(bits at:9999) printCR. |
565 | 96 |
bits at:9999 put:1. |
1644
540979f371b3
Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents:
1459
diff
changeset
|
97 |
(bits at:9999) printCR. |
565 | 98 |
[exEnd] |
99 |
" |
|
100 |
! ! |
|
101 |
||
102 |
!BitArray methodsFor:'accessing'! |
|
103 |
||
104 |
at:index |
|
105 |
"retrieve the bit at index" |
|
106 |
||
107 |
^ (super at:index) ifTrue:[1] ifFalse:[0] |
|
108 |
||
109 |
" |
|
110 |
(BitArray new:1000) at:555 |
|
111 |
" |
|
112 |
||
113 |
" |
|
114 |
|b| |
|
115 |
||
116 |
b := BitArray new:1000. |
|
117 |
b at:555 put:1. |
|
118 |
b at:555 |
|
119 |
" |
|
120 |
||
121 |
"Created: 5.9.1997 / 12:36:38 / cg" |
|
122 |
"Modified: 5.9.1997 / 12:38:38 / cg" |
|
123 |
! |
|
124 |
||
125 |
at:index put:aBit |
|
126 |
"store the argument, aBit at index; return aBit." |
|
127 |
||
128 |
aBit == 0 ifTrue:[ |
|
129 |
super at:index put:false. |
|
130 |
^ aBit. |
|
131 |
]. |
|
132 |
aBit == 1 ifTrue:[ |
|
133 |
super at:index put:true. |
|
134 |
^ aBit. |
|
135 |
]. |
|
136 |
"/ |
|
137 |
"/ bitArrays can only hold 0's and 1's |
|
138 |
"/ |
|
1176
8224efd15c5a
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
893
diff
changeset
|
139 |
^ self elementBoundsError:aBit |
565 | 140 |
|
141 |
" |
|
142 |
|b| |
|
143 |
||
144 |
b := BitArray new:1000. |
|
145 |
b at:555 put:1. |
|
146 |
b at:555 |
|
147 |
" |
|
148 |
||
149 |
"Created: 5.9.1997 / 12:37:28 / cg" |
|
150 |
"Modified: 5.9.1997 / 12:41:18 / cg" |
|
151 |
! ! |
|
152 |
||
1644
540979f371b3
Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents:
1459
diff
changeset
|
153 |
!BitArray methodsFor:'converting'! |
540979f371b3
Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents:
1459
diff
changeset
|
154 |
|
540979f371b3
Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents:
1459
diff
changeset
|
155 |
bytes |
540979f371b3
Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents:
1459
diff
changeset
|
156 |
"answer myself as a ByteArray containing my bytes" |
540979f371b3
Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents:
1459
diff
changeset
|
157 |
|
540979f371b3
Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents:
1459
diff
changeset
|
158 |
|size bytes| |
540979f371b3
Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents:
1459
diff
changeset
|
159 |
|
540979f371b3
Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents:
1459
diff
changeset
|
160 |
size := self basicSize. |
540979f371b3
Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents:
1459
diff
changeset
|
161 |
bytes := ByteArray new:size. |
540979f371b3
Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents:
1459
diff
changeset
|
162 |
1 to:size do:[:index| |
540979f371b3
Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents:
1459
diff
changeset
|
163 |
bytes at:index put:(self byteAt:index) |
540979f371b3
Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents:
1459
diff
changeset
|
164 |
]. |
540979f371b3
Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents:
1459
diff
changeset
|
165 |
^ bytes |
540979f371b3
Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents:
1459
diff
changeset
|
166 |
! ! |
540979f371b3
Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents:
1459
diff
changeset
|
167 |
|
1176
8224efd15c5a
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
893
diff
changeset
|
168 |
!BitArray methodsFor:'filling & replacing'! |
8224efd15c5a
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
893
diff
changeset
|
169 |
|
8224efd15c5a
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
893
diff
changeset
|
170 |
atAllPut:aBit |
8224efd15c5a
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
893
diff
changeset
|
171 |
aBit == 0 ifTrue:[ |
1241 | 172 |
^ super atAllPut:false |
1176
8224efd15c5a
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
893
diff
changeset
|
173 |
]. |
8224efd15c5a
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
893
diff
changeset
|
174 |
aBit == 1 ifTrue:[ |
1241 | 175 |
^ super atAllPut:true |
1176
8224efd15c5a
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
893
diff
changeset
|
176 |
]. |
8224efd15c5a
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
893
diff
changeset
|
177 |
"/ |
8224efd15c5a
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
893
diff
changeset
|
178 |
"/ bitArrays can only hold 0's and 1's |
8224efd15c5a
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
893
diff
changeset
|
179 |
"/ |
8224efd15c5a
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
893
diff
changeset
|
180 |
^ self elementBoundsError:aBit |
8224efd15c5a
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
893
diff
changeset
|
181 |
! ! |
8224efd15c5a
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
893
diff
changeset
|
182 |
|
8224efd15c5a
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
893
diff
changeset
|
183 |
!BitArray methodsFor:'queries'! |
8224efd15c5a
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
893
diff
changeset
|
184 |
|
8224efd15c5a
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
893
diff
changeset
|
185 |
defaultElement |
8224efd15c5a
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
893
diff
changeset
|
186 |
^ 0 |
8224efd15c5a
elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents:
893
diff
changeset
|
187 |
! ! |
893
823d2fa809e2
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
736
diff
changeset
|
188 |
|
1644
540979f371b3
Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents:
1459
diff
changeset
|
189 |
|
1459
914d762066f0
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
1241
diff
changeset
|
190 |
!BitArray methodsFor:'visiting'! |
914d762066f0
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
1241
diff
changeset
|
191 |
|
914d762066f0
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
1241
diff
changeset
|
192 |
acceptVisitor:aVisitor with:aParameter |
914d762066f0
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
1241
diff
changeset
|
193 |
|
914d762066f0
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
1241
diff
changeset
|
194 |
^ aVisitor visitBitArray:self with:aParameter |
914d762066f0
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
1241
diff
changeset
|
195 |
! ! |
914d762066f0
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
1241
diff
changeset
|
196 |
|
565 | 197 |
!BitArray class methodsFor:'documentation'! |
198 |
||
199 |
version |
|
1644
540979f371b3
Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents:
1459
diff
changeset
|
200 |
^ '$Header: /cvs/stx/stx/libbasic2/BitArray.st,v 1.7 2006-06-29 08:24:49 stefan Exp $' |
565 | 201 |
! ! |