BitArray.st
author Claus Gittinger <cg@exept.de>
Thu, 09 Jun 2016 12:30:05 +0200
changeset 3886 b4fe47975cce
parent 3881 16890fe7ef2e
child 4033 369352e8b5a2
permissions -rw-r--r--
initial checkin class: ValueDoubleLink added: #copyright #documentation #value #value:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 This is a demo example:
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
 THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
 ARE DISCLAIMED.  IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
 SUCH DAMAGE.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
"
893
823d2fa809e2 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 736
diff changeset
    26
"{ Package: 'stx:libbasic2' }"
823d2fa809e2 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 736
diff changeset
    27
3534
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
    28
"{ NameSpace: Smalltalk }"
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
    29
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
    30
ArrayedCollection variableByteSubclass:#BitArray
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
    31
	instanceVariableNames:'tally'
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
	classVariableNames:''
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
	poolDictionaries:''
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
	category:'Collections-Arrayed'
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
!
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
!BitArray class methodsFor:'documentation'!
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
copyright
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
 COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
              All Rights Reserved
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
 This software is furnished under a license and may be used
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
 only in accordance with the terms of that license and with the
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
 inclusion of the above copyright notice.   This software may not
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
 be provided or otherwise made available to, or used by, any
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
 other person.  No title to or ownership of the software is
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
 hereby transferred.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
 This is a demo example:
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
 THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
 ARE DISCLAIMED.  IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
 SUCH DAMAGE.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
!
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
documentation
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
"
3279
b1906422c6d5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
    70
    useful for bulk bit/boolean data 
3881
16890fe7ef2e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
    71
    Requires only 1/32th (32bit machines) or 1/64th (64bit machines) of the memory 
16890fe7ef2e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3880
diff changeset
    72
    compared to an array of booleans.
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
    73
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
    74
    This one stores 8 bits per byte. Since instances store bits in multiples
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
    75
    of 8, we have to keep the real size of the collection in an extra instance
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
    76
    variable (tally).
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
    77
    It may be useful if huge boolean arrays are to be used.
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
    78
3279
b1906422c6d5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
    79
    There are 10 types of people in this world: 
b1906422c6d5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
    80
        Those who understand binary, & those who don't.
b1906422c6d5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
    81
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
    82
    ATTENTION:
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
    83
    Bits 1 to 8 of the BooleanArray are stored in bits 8 to 1 of the
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
    84
    corresponding byte, to allow easy mapping to ASN.1 BIT STRING encoding
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
    85
    in the BER. (i.e. MSB-first)
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
736
db164846b078 documentation
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
    87
    [memory requirements:]
db164846b078 documentation
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
    88
        OBJ-HEADER + ((size + 7) // 8)
db164846b078 documentation
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
    89
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
    [author:]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
        Claus Gittinger
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
    [see also:]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
        BooleanArray ByteArray WordArray Array
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
!
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
examples
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
                                                                        [exBegin]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
    (BitArray new:7) inspect
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
                                                                        [exEnd]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
                                                                        [exBegin]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
    (BitArray new:7) basicInspect
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
                                                                        [exEnd]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
                                                                        [exBegin]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
    |bits|
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
    bits := BitArray new:1000000.
1644
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   110
    (bits at:9999) printCR.
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
    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
   112
    (bits at:9999) printCR.
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
                                                                        [exEnd]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
! !
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   117
!BitArray class methodsFor:'instance creation'!
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   118
3172
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   119
fromBytes:aByteArray
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   120
    "return a new instance, capable of holding aByteArray size*8 bits, initialized from aByteArray"
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   121
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   122
    |a|
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   123
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   124
    a := self new: aByteArray size*8.
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   125
    1 to:aByteArray size do:[:i | a byteAt:i put:(aByteArray at:i)].
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   126
    ^ a
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   127
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   128
    "
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   129
     BitArray fromBytes:#[ 2r00001111 2r10101010 2r01010101]
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   130
    "
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   131
!
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   132
3823
f10f46475b8c #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3748
diff changeset
   133
new
f10f46475b8c #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3748
diff changeset
   134
    "return a new instance, capable of holding size bits"
f10f46475b8c #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3748
diff changeset
   135
f10f46475b8c #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3748
diff changeset
   136
    ^ self new:0
f10f46475b8c #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3748
diff changeset
   137
f10f46475b8c #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3748
diff changeset
   138
    "
f10f46475b8c #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3748
diff changeset
   139
     BitArray new
f10f46475b8c #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3748
diff changeset
   140
    "
f10f46475b8c #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3748
diff changeset
   141
!
f10f46475b8c #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3748
diff changeset
   142
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   143
new:size
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   144
    "return a new instance, capable of holding size bits"
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   145
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   146
    |nBytes|
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   147
3747
837035fa4d2c #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3551
diff changeset
   148
    nBytes := (size + 7) // 8.
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   149
    ^ (super new:nBytes) setTally:size
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   150
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   151
    "
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   152
     BitArray new:10
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   153
    "
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   154
! !
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   155
3870
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   156
!BitArray class methodsFor:'queries'!
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   157
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   158
maxVal
3880
981c4604c1ce #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3870
diff changeset
   159
    "the minimum value which can be stored in instances of me.
981c4604c1ce #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3870
diff changeset
   160
     For BitArrays, this is 1"
3870
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   161
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   162
    ^ 1
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   163
!
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   164
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   165
minVal
3880
981c4604c1ce #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3870
diff changeset
   166
    "the minimum value which can be stored in instances of me.
981c4604c1ce #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3870
diff changeset
   167
     For BitArrays, this is 0"
3870
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   168
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   169
    ^ 0
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   170
! !
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   171
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
!BitArray methodsFor:'accessing'!
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
at:index
3278
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   175
    "retrieve the bit at index (1..)"
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   177
    |byte mask i0|
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   178
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   179
    (index between:1 and:tally) ifFalse:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   180
        ^ self subscriptBoundsError:index
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   181
    ].
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   182
    i0 := index - 1.
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   183
    byte := super basicAt:(i0 // 8)+1.
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   184
    mask := 1 bitShift:(7 - (i0 \\ 8)).
2129
d28f31f63e99 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2107
diff changeset
   185
    ^ (byte bitTest:mask) ifTrue:[1] ifFalse:[0]
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
    "
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
     (BitArray new:1000) at:555
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   189
     (BitArray new:1000) at:400 put:1; at:400
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
    "
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
    "
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
     |b|
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
     b := BitArray new:1000.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
     b at:555 put:1.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
     b at:555   
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
    "
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
!
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   201
at:index put:aNumber
3278
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   202
    "store the argument, aNumber at index (1..);    
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   203
     return the argument, aNumber (sigh)."
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   205
    |byte mask idx i0|
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   206
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   207
    (index between:1 and:tally) ifFalse:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   208
        ^ self subscriptBoundsError:index
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
    ].
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   210
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   211
    i0 := index - 1.
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   212
    idx := (i0 // 8) + 1.
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   213
    byte := super basicAt:idx.
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   214
    mask := 1 bitShift:(7 - (i0 \\ 8)).
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   215
    aNumber == 1 ifTrue:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   216
        byte := byte bitOr:mask
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   217
    ] ifFalse:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   218
        aNumber == 0 ifTrue:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   219
            byte := byte bitAnd:(mask bitInvert)
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   220
        ] ifFalse:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   221
            "/ not 0 or 1
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   222
            ^ self elementBoundsError:aNumber
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   223
        ]
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
    ].
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   225
    super basicAt:idx put:byte.
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   226
    ^ aNumber.
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
    "
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
     |b|
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
     b := BitArray new:1000.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
     b at:555 put:1.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
     b at:555    
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
    "
2093
bad0e519a18a changed #occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 2077
diff changeset
   235
!
bad0e519a18a changed #occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 2077
diff changeset
   236
2319
sr
parents: 2225
diff changeset
   237
byteAt:index
sr
parents: 2225
diff changeset
   238
    "retrieve 8 bits at index; the index is 1 for the first 8 bits, 2 for the next 8 bits etc."
sr
parents: 2225
diff changeset
   239
sr
parents: 2225
diff changeset
   240
    ^ self basicAt:index
sr
parents: 2225
diff changeset
   241
sr
parents: 2225
diff changeset
   242
    "
sr
parents: 2225
diff changeset
   243
     ((BitArray new:8) at:1 put:1); byteAt:1
sr
parents: 2225
diff changeset
   244
    "
sr
parents: 2225
diff changeset
   245
!
sr
parents: 2225
diff changeset
   246
sr
parents: 2225
diff changeset
   247
byteAt:index put:aByte
sr
parents: 2225
diff changeset
   248
    "store 8 bits at index; the index is 1 for the first 8 bits, 2 for the next 8 bits etc."
sr
parents: 2225
diff changeset
   249
sr
parents: 2225
diff changeset
   250
    ^ self basicAt:index put:aByte
sr
parents: 2225
diff changeset
   251
sr
parents: 2225
diff changeset
   252
    "
sr
parents: 2225
diff changeset
   253
     ((BitArray new:8) byteAt:1 put:128); at:1     
sr
parents: 2225
diff changeset
   254
    "
sr
parents: 2225
diff changeset
   255
!
sr
parents: 2225
diff changeset
   256
2093
bad0e519a18a changed #occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 2077
diff changeset
   257
occurrencesOf:anElement
3278
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   258
    "count the occurrences of the argument, anElement in the receiver"
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   259
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   260
    |nOnes|
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   261
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   262
    nOnes := self countOnes.
2093
bad0e519a18a changed #occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 2077
diff changeset
   263
    anElement == 1 ifTrue:[
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   264
        ^ nOnes
2093
bad0e519a18a changed #occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 2077
diff changeset
   265
    ].
bad0e519a18a changed #occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 2077
diff changeset
   266
    anElement == 0 ifTrue:[
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   267
        ^ tally - nOnes
2093
bad0e519a18a changed #occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 2077
diff changeset
   268
    ].
bad0e519a18a changed #occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 2077
diff changeset
   269
    ^ 0
3534
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   270
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   271
    "
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   272
     (BitArray new:10)
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   273
        at:4 put:1;
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   274
        at:6 put:1;
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   275
        at:7 put:1;
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   276
        occurrencesOf:1 
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   277
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   278
     (BitArray new:10)
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   279
        at:4 put:1;
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   280
        at:6 put:1;
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   281
        at:7 put:1;
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   282
        occurrencesOf:0    
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   283
    "
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   284
! !
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
1644
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   286
!BitArray methodsFor:'converting'!
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   287
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   288
bytes
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   289
    "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
   290
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   291
    |size bytes|
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   292
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   293
    size := self basicSize.
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   294
    bytes := ByteArray new:size.
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   295
    1 to:size do:[:index|
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   296
        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
   297
    ].
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   298
    ^ bytes
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   299
! !
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   300
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   301
!BitArray methodsFor:'filling & replacing'!
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   302
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   303
atAllPut:aNumber
3278
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   304
    "replace all elements of the collection by the argument, aNumber.
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   305
     The argument, aBoolean must be 0 or 1.
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   306
     Notice: This operation modifies the receiver, NOT a copy;
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   307
     therefore the change may affect all others referencing the receiver."
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   308
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   309
    |v lastIndex|
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   310
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   311
    lastIndex := self basicSize.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   312
    lastIndex == 0 ifTrue:[^ self].
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   313
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   314
    aNumber == 1 ifTrue:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   315
        v := 255
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   316
    ] ifFalse:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   317
        aNumber == 0 ifTrue:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   318
            v := 0
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   319
        ] ifFalse:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   320
            "/
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   321
            "/ booleanArrays can only hold true and false
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   322
            "/
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   323
            ^ self elementBoundsError:aNumber
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   324
        ]
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   325
    ].
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   326
    1 to:lastIndex-1 do:[:i |
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   327
        self basicAt:i put:v
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   328
    ].
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   329
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   330
    "/ ensure 0-bits above tally
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   331
    v := #[ 2r11111111
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   332
            2r10000000
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   333
            2r11000000
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   334
            2r11100000
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   335
            2r11110000
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   336
            2r11111000
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   337
            2r11111100
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   338
            2r11111110 ] at:(tally\\8)+1. 
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   339
    self basicAt:lastIndex put:v.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   340
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   341
    "
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   342
     ((self new:10) atAllPut:1) countOnes  
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   343
     ((self new:8) atAllPut:1) countOnes   
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   344
    "
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   345
! !
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   346
3748
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   347
!BitArray methodsFor:'logical operations'!
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   348
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   349
bitOr:aBitArray
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   350
    |new mySize "{ Class: SmallInteger }" otherSize "{ Class: SmallInteger }"|
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   351
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   352
    mySize := self basicSize.
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   353
    otherSize := aBitArray basicSize.
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   354
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   355
    new := self class basicNew:(mySize max:otherSize).
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   356
    new setTally:(self size max:aBitArray size).
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   357
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   358
    1 to:mySize do:[:i|
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   359
        new basicAt:i put:(self basicAt:i).
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   360
    ].
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   361
    1 to:otherSize do:[:i|
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   362
        new basicAt:i put:((new basicAt:i) bitOr:(aBitArray basicAt:i)).
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   363
    ].
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   364
    
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   365
    ^ new
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   366
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   367
    "
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   368
        ((BitArray new:5) at:3 put:1; yourself) bitOr:((BitArray new:8) at:5 put:1; yourself)
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   369
    "
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   370
! !
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   371
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   372
!BitArray methodsFor:'private'!
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   373
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   374
countOnes
3278
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   375
    "count the 1-bits in the receiver"
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   376
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   377
    |sz bI count|
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   378
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   379
    count := 0.
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   380
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   381
    "/ because remaining bits in the highest byte are always 0,
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   382
    "/ we can simply count the 1-bits in ALL bytes... (see lastByte handling in atAllPut:)
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   383
    bI := 1.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   384
    sz := self basicSize.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   385
    [bI <= sz] whileTrue:[
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   386
        count := count + (self basicAt:bI) bitCount.
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   387
        bI := bI + 1.
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   388
    ].
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   389
    ^ count
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   390
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   391
"/    |i nI bI bits count|
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   392
"/    i := bI := 1.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   393
"/    [
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   394
"/        nI := i + 8.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   395
"/        nI <= tally
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   396
"/    ] whileTrue:[
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   397
"/        bits := self basicAt:bI.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   398
"/        count := count + bits bitCount.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   399
"/        bI := bI + 1.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   400
"/        i := nI
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   401
"/    ].
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   402
"/    [i <= tally] whileTrue:[
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   403
"/        (self at:i) ifTrue:[ count := count + 1].
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   404
"/        i := i + 1.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   405
"/    ].
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   406
"/    ^ count
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   407
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   408
    "
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   409
     (BooleanArray new:100)
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   410
        at:14 put:true; 
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   411
        at:55 put:true; 
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   412
        countOnes
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   413
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   414
     (BooleanArray new:100)
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   415
        at:14 put:true; 
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   416
        at:55 put:true; 
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   417
        occurrencesOf:true
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   418
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   419
     (BooleanArray new:100)
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   420
        at:14 put:true; 
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   421
        at:55 put:true; 
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   422
        occurrencesOf:false
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   423
    "
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   424
!
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   425
2225
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   426
indexOfNth:n occurrenceOf:what
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   427
    "return the index of the nTh occurence of a value, or 0 if there are not that many"
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   428
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   429
    |sz byteIndex count countInByte|
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   430
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   431
    n > self size ifTrue:[^ 0].
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   432
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   433
    count := 0.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   434
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   435
    byteIndex := 1.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   436
    sz := self basicSize.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   437
    [byteIndex <= sz] whileTrue:[
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   438
        countInByte := (self basicAt:byteIndex) bitCount.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   439
        what = self defaultElement ifTrue:[
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   440
            countInByte := 8-countInByte.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   441
        ].
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   442
        count := count + countInByte.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   443
        count >= n ifTrue:[
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   444
            count := count - countInByte.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   445
            (byteIndex-1)*8+1 to:(byteIndex-1)*8+8 do:[:bitIndex |
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   446
                (self at:bitIndex) = what ifTrue:[
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   447
                    count := count + 1.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   448
                    count = n ifTrue:[
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   449
                        ^ bitIndex.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   450
                    ]
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   451
                ].
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   452
            ].
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   453
            ^ 0
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   454
        ].
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   455
        byteIndex := byteIndex + 1.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   456
    ].
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   457
    ^ 0
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   458
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   459
    "
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   460
     (BooleanArray new:100)
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   461
        at:1 put:true; 
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   462
        at:2 put:true; 
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   463
        at:4 put:true; 
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   464
        at:5 put:true; 
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   465
        at:6 put:true; 
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   466
        at:7 put:true; 
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   467
        at:8 put:true; 
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   468
        at:10 put:true; 
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   469
        indexOfNth:8 occurrenceOf:false         
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   470
    "
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   471
!
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   472
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   473
setTally:size
3551
eb641c9e4e7c class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3534
diff changeset
   474
    "set my tally - that is the actual number of bits in me
eb641c9e4e7c class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3534
diff changeset
   475
     (usually a little less than the number of bits in my byte array)"
eb641c9e4e7c class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3534
diff changeset
   476
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   477
    tally := size
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   478
! !
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   479
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   480
!BitArray methodsFor:'queries'!
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   481
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   482
defaultElement
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   483
    ^ 0
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   484
!
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   485
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   486
size
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   487
    "return the size of the receiver"
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   488
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   489
    ^ tally
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   490
! !
893
823d2fa809e2 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 736
diff changeset
   491
1459
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   492
!BitArray methodsFor:'visiting'!
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   493
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   494
acceptVisitor:aVisitor with:aParameter
3319
28048b638042 comment/format only
Claus Gittinger <cg@exept.de>
parents: 3279
diff changeset
   495
    "dispatch for visitor pattern; send #visitBitArray:with: to aVisitor"
1459
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   496
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   497
    ^ aVisitor visitBitArray:self with:aParameter
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   498
! !
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   499
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   500
!BitArray class methodsFor:'documentation'!
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   501
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   502
version
3747
837035fa4d2c #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3551
diff changeset
   503
    ^ '$Header$'
2319
sr
parents: 2225
diff changeset
   504
!
sr
parents: 2225
diff changeset
   505
sr
parents: 2225
diff changeset
   506
version_CVS
3747
837035fa4d2c #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3551
diff changeset
   507
    ^ '$Header$'
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   508
! !
3172
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   509