"
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
This is a demo example:
THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
"
"{ Package: 'stx:libbasic2' }"
BooleanArray variableByteSubclass:#BitArray
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'Collections-Arrayed'
!
!BitArray class methodsFor:'documentation'!
copyright
"
COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
This is a demo example:
THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
"
!
documentation
"
like a booleanArray, but storing & returning 0's and 1's.
[memory requirements:]
OBJ-HEADER + ((size + 7) // 8)
[author:]
Claus Gittinger
[see also:]
BooleanArray ByteArray WordArray Array
"
!
examples
"
[exBegin]
(BitArray new:7) inspect
[exEnd]
[exBegin]
(BitArray new:7) basicInspect
[exEnd]
[exBegin]
|bits|
bits := BitArray new:1000000.
(bits at:9999) printCR.
bits at:9999 put:1.
(bits at:9999) printCR.
[exEnd]
"
! !
!BitArray methodsFor:'accessing'!
at:index
"retrieve the bit at index"
^ (super at:index) ifTrue:[1] ifFalse:[0]
"
(BitArray new:1000) at:555
"
"
|b|
b := BitArray new:1000.
b at:555 put:1.
b at:555
"
"Created: 5.9.1997 / 12:36:38 / cg"
"Modified: 5.9.1997 / 12:38:38 / cg"
!
at:index put:aBit
"store the argument, aBit at index; return aBit."
aBit == 0 ifTrue:[
super at:index put:false.
^ aBit.
].
aBit == 1 ifTrue:[
super at:index put:true.
^ aBit.
].
"/
"/ bitArrays can only hold 0's and 1's
"/
^ self elementBoundsError:aBit
"
|b|
b := BitArray new:1000.
b at:555 put:1.
b at:555
"
"Created: 5.9.1997 / 12:37:28 / cg"
"Modified: 5.9.1997 / 12:41:18 / cg"
! !
!BitArray methodsFor:'converting'!
bytes
"answer myself as a ByteArray containing my bytes"
|size bytes|
size := self basicSize.
bytes := ByteArray new:size.
1 to:size do:[:index|
bytes at:index put:(self byteAt:index)
].
^ bytes
! !
!BitArray methodsFor:'filling & replacing'!
atAllPut:aBit
aBit == 0 ifTrue:[
^ super atAllPut:false
].
aBit == 1 ifTrue:[
^ super atAllPut:true
].
"/
"/ bitArrays can only hold 0's and 1's
"/
^ self elementBoundsError:aBit
! !
!BitArray methodsFor:'queries'!
defaultElement
^ 0
! !
!BitArray methodsFor:'visiting'!
acceptVisitor:aVisitor with:aParameter
^ aVisitor visitBitArray:self with:aParameter
! !
!BitArray class methodsFor:'documentation'!
version
^ '$Header: /cvs/stx/stx/libbasic2/BitArray.st,v 1.7 2006-06-29 08:24:49 stefan Exp $'
! !