BitArray.st
author Claus Gittinger <cg@exept.de>
Sun, 05 Jun 2016 09:53:36 +0200
changeset 3880 981c4604c1ce
parent 3870 467b4e336955
child 3881 16890fe7ef2e
permissions -rw-r--r--
#DOCUMENTATION by cg class: BitArray comment/format in: #maxVal #minVal
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 
b1906422c6d5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
    71
    (requires only 1/32th the memory compared to an array of booleans).
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
    72
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
    73
    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
    74
    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
    75
    variable (tally).
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
    76
    It may be useful if huge boolean arrays are to be used.
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
    77
3279
b1906422c6d5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
    78
    There are 10 types of people in this world: 
b1906422c6d5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
    79
        Those who understand binary, & those who don't.
b1906422c6d5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
    80
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
    81
    ATTENTION:
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
    82
    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
    83
    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
    84
    in the BER. (i.e. MSB-first)
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
736
db164846b078 documentation
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
    86
    [memory requirements:]
db164846b078 documentation
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
    87
        OBJ-HEADER + ((size + 7) // 8)
db164846b078 documentation
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
    88
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
    [author:]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
        Claus Gittinger
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
    [see also:]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
        BooleanArray ByteArray WordArray Array
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
"
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
examples
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
                                                                        [exBegin]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
    (BitArray new:7) inspect
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
                                                                        [exEnd]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
                                                                        [exBegin]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
    (BitArray new:7) basicInspect
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
                                                                        [exEnd]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
                                                                        [exBegin]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
    |bits|
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
    bits := BitArray new:1000000.
1644
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   109
    (bits at:9999) printCR.
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
    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
   111
    (bits at:9999) printCR.
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
                                                                        [exEnd]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
"
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
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   116
!BitArray class methodsFor:'instance creation'!
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   117
3172
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   118
fromBytes:aByteArray
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   119
    "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
   120
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   121
    |a|
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   122
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   123
    a := self new: aByteArray size*8.
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   124
    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
   125
    ^ a
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   126
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
     BitArray fromBytes:#[ 2r00001111 2r10101010 2r01010101]
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   129
    "
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
3823
f10f46475b8c #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3748
diff changeset
   132
new
f10f46475b8c #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3748
diff changeset
   133
    "return a new instance, capable of holding size bits"
f10f46475b8c #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3748
diff changeset
   134
f10f46475b8c #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3748
diff changeset
   135
    ^ self new:0
f10f46475b8c #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3748
diff changeset
   136
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
     BitArray new
f10f46475b8c #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3748
diff changeset
   139
    "
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
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   142
new:size
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   143
    "return a new instance, capable of holding size bits"
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   144
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   145
    |nBytes|
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   146
3747
837035fa4d2c #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3551
diff changeset
   147
    nBytes := (size + 7) // 8.
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   148
    ^ (super new:nBytes) setTally:size
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   149
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
     BitArray new:10
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   152
    "
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
3870
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   155
!BitArray class methodsFor:'queries'!
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   156
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   157
maxVal
3880
981c4604c1ce #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3870
diff changeset
   158
    "the minimum value which can be stored in instances of me.
981c4604c1ce #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3870
diff changeset
   159
     For BitArrays, this is 1"
3870
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   160
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   161
    ^ 1
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   162
!
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
minVal
3880
981c4604c1ce #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3870
diff changeset
   165
    "the minimum value which can be stored in instances of me.
981c4604c1ce #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3870
diff changeset
   166
     For BitArrays, this is 0"
3870
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   167
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   168
    ^ 0
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   169
! !
467b4e336955 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3823
diff changeset
   170
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
!BitArray methodsFor:'accessing'!
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
at:index
3278
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   174
    "retrieve the bit at index (1..)"
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   176
    |byte mask i0|
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   177
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   178
    (index between:1 and:tally) ifFalse:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   179
        ^ self subscriptBoundsError:index
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   180
    ].
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   181
    i0 := index - 1.
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   182
    byte := super basicAt:(i0 // 8)+1.
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   183
    mask := 1 bitShift:(7 - (i0 \\ 8)).
2129
d28f31f63e99 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2107
diff changeset
   184
    ^ (byte bitTest:mask) ifTrue:[1] ifFalse:[0]
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
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
     (BitArray new:1000) at:555
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   188
     (BitArray new:1000) at:400 put:1; at:400
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
    "
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
     |b|
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
     b := BitArray new:1000.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
     b at:555 put:1.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
     b at:555   
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
    "
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
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   200
at:index put:aNumber
3278
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   201
    "store the argument, aNumber at index (1..);    
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   202
     return the argument, aNumber (sigh)."
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   204
    |byte mask idx i0|
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   205
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   206
    (index between:1 and:tally) ifFalse:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   207
        ^ self subscriptBoundsError:index
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
    ].
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   209
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   210
    i0 := index - 1.
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   211
    idx := (i0 // 8) + 1.
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   212
    byte := super basicAt:idx.
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   213
    mask := 1 bitShift:(7 - (i0 \\ 8)).
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   214
    aNumber == 1 ifTrue:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   215
        byte := byte bitOr:mask
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   216
    ] ifFalse:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   217
        aNumber == 0 ifTrue:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   218
            byte := byte bitAnd:(mask bitInvert)
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   219
        ] ifFalse:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   220
            "/ not 0 or 1
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   221
            ^ self elementBoundsError:aNumber
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   222
        ]
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
    ].
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   224
    super basicAt:idx put:byte.
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   225
    ^ aNumber.
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
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
     |b|
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
     b := BitArray new:1000.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
     b at:555 put:1.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
     b at:555    
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
    "
2093
bad0e519a18a changed #occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 2077
diff changeset
   234
!
bad0e519a18a changed #occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 2077
diff changeset
   235
2319
sr
parents: 2225
diff changeset
   236
byteAt:index
sr
parents: 2225
diff changeset
   237
    "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
   238
sr
parents: 2225
diff changeset
   239
    ^ self basicAt:index
sr
parents: 2225
diff changeset
   240
sr
parents: 2225
diff changeset
   241
    "
sr
parents: 2225
diff changeset
   242
     ((BitArray new:8) at:1 put:1); byteAt:1
sr
parents: 2225
diff changeset
   243
    "
sr
parents: 2225
diff changeset
   244
!
sr
parents: 2225
diff changeset
   245
sr
parents: 2225
diff changeset
   246
byteAt:index put:aByte
sr
parents: 2225
diff changeset
   247
    "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
   248
sr
parents: 2225
diff changeset
   249
    ^ self basicAt:index put:aByte
sr
parents: 2225
diff changeset
   250
sr
parents: 2225
diff changeset
   251
    "
sr
parents: 2225
diff changeset
   252
     ((BitArray new:8) byteAt:1 put:128); at:1     
sr
parents: 2225
diff changeset
   253
    "
sr
parents: 2225
diff changeset
   254
!
sr
parents: 2225
diff changeset
   255
2093
bad0e519a18a changed #occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 2077
diff changeset
   256
occurrencesOf:anElement
3278
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   257
    "count the occurrences of the argument, anElement in the receiver"
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   258
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   259
    |nOnes|
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   260
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   261
    nOnes := self countOnes.
2093
bad0e519a18a changed #occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 2077
diff changeset
   262
    anElement == 1 ifTrue:[
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   263
        ^ nOnes
2093
bad0e519a18a changed #occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 2077
diff changeset
   264
    ].
bad0e519a18a changed #occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 2077
diff changeset
   265
    anElement == 0 ifTrue:[
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   266
        ^ tally - nOnes
2093
bad0e519a18a changed #occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 2077
diff changeset
   267
    ].
bad0e519a18a changed #occurrencesOf:
Claus Gittinger <cg@exept.de>
parents: 2077
diff changeset
   268
    ^ 0
3534
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   269
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
     (BitArray new:10)
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   272
        at:4 put:1;
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   273
        at:6 put:1;
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   274
        at:7 put:1;
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   275
        occurrencesOf:1 
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   276
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   277
     (BitArray new:10)
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   278
        at:4 put:1;
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   279
        at:6 put:1;
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   280
        at:7 put:1;
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   281
        occurrencesOf:0    
d714931725e1 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3319
diff changeset
   282
    "
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
! !
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   284
1644
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   285
!BitArray methodsFor:'converting'!
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   286
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   287
bytes
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   288
    "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
   289
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   290
    |size bytes|
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   291
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   292
    size := self basicSize.
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   293
    bytes := ByteArray new:size.
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   294
    1 to:size do:[:index|
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   295
        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
   296
    ].
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   297
    ^ bytes
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   298
! !
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   299
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   300
!BitArray methodsFor:'filling & replacing'!
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   301
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   302
atAllPut:aNumber
3278
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   303
    "replace all elements of the collection by the argument, aNumber.
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   304
     The argument, aBoolean must be 0 or 1.
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   305
     Notice: This operation modifies the receiver, NOT a copy;
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   306
     therefore the change may affect all others referencing the receiver."
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   307
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   308
    |v lastIndex|
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   309
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   310
    lastIndex := self basicSize.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   311
    lastIndex == 0 ifTrue:[^ self].
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   312
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   313
    aNumber == 1 ifTrue:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   314
        v := 255
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   315
    ] ifFalse:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   316
        aNumber == 0 ifTrue:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   317
            v := 0
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   318
        ] ifFalse:[
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   319
            "/
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   320
            "/ booleanArrays can only hold true and false
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   321
            "/
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   322
            ^ self elementBoundsError:aNumber
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   323
        ]
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   324
    ].
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   325
    1 to:lastIndex-1 do:[:i |
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   326
        self basicAt:i put:v
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   327
    ].
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   328
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   329
    "/ ensure 0-bits above tally
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   330
    v := #[ 2r11111111
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   331
            2r10000000
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   332
            2r11000000
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   333
            2r11100000
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   334
            2r11110000
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   335
            2r11111000
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   336
            2r11111100
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   337
            2r11111110 ] at:(tally\\8)+1. 
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   338
    self basicAt:lastIndex put:v.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   339
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
     ((self new:10) atAllPut:1) countOnes  
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   342
     ((self new:8) atAllPut:1) countOnes   
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   343
    "
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   344
! !
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   345
3748
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   346
!BitArray methodsFor:'logical operations'!
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   347
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   348
bitOr:aBitArray
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   349
    |new mySize "{ Class: SmallInteger }" otherSize "{ Class: SmallInteger }"|
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   350
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   351
    mySize := self basicSize.
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   352
    otherSize := aBitArray basicSize.
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   353
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   354
    new := self class basicNew:(mySize max:otherSize).
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   355
    new setTally:(self size max:aBitArray size).
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   356
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   357
    1 to:mySize do:[:i|
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   358
        new basicAt:i put:(self basicAt:i).
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   359
    ].
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   360
    1 to:otherSize do:[:i|
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   361
        new basicAt:i put:((new basicAt:i) bitOr:(aBitArray basicAt:i)).
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   362
    ].
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   363
    
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   364
    ^ new
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   365
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   366
    "
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   367
        ((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
   368
    "
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   369
! !
9b4c9e26c360 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 3747
diff changeset
   370
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   371
!BitArray methodsFor:'private'!
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   372
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   373
countOnes
3278
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   374
    "count the 1-bits in the receiver"
913769db4ee5 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3172
diff changeset
   375
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   376
    |sz bI count|
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   377
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   378
    count := 0.
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   379
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   380
    "/ because remaining bits in the highest byte are always 0,
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   381
    "/ 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
   382
    bI := 1.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   383
    sz := self basicSize.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   384
    [bI <= sz] whileTrue:[
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   385
        count := count + (self basicAt:bI) bitCount.
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   386
        bI := bI + 1.
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   387
    ].
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   388
    ^ count
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   389
2107
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   390
"/    |i nI bI bits count|
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   391
"/    i := bI := 1.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   392
"/    [
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   393
"/        nI := i + 8.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   394
"/        nI <= tally
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   395
"/    ] whileTrue:[
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   396
"/        bits := self basicAt:bI.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   397
"/        count := count + bits bitCount.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   398
"/        bI := bI + 1.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   399
"/        i := nI
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   400
"/    ].
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   401
"/    [i <= tally] whileTrue:[
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   402
"/        (self at:i) ifTrue:[ count := count + 1].
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   403
"/        i := i + 1.
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   404
"/    ].
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   405
"/    ^ count
87f43d56c755 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2094
diff changeset
   406
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   407
    "
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   408
     (BooleanArray new:100)
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   409
        at:14 put:true; 
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   410
        at:55 put:true; 
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   411
        countOnes
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   412
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   413
     (BooleanArray new:100)
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   414
        at:14 put:true; 
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   415
        at:55 put:true; 
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   416
        occurrencesOf:true
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   417
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   418
     (BooleanArray new:100)
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   419
        at:14 put:true; 
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   420
        at:55 put:true; 
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   421
        occurrencesOf:false
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   422
    "
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
2225
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   425
indexOfNth:n occurrenceOf:what
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   426
    "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
   427
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   428
    |sz byteIndex count countInByte|
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   429
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   430
    n > self size ifTrue:[^ 0].
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   431
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   432
    count := 0.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   433
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   434
    byteIndex := 1.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   435
    sz := self basicSize.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   436
    [byteIndex <= sz] whileTrue:[
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   437
        countInByte := (self basicAt:byteIndex) bitCount.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   438
        what = self defaultElement ifTrue:[
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   439
            countInByte := 8-countInByte.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   440
        ].
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   441
        count := count + countInByte.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   442
        count >= n ifTrue:[
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   443
            count := count - countInByte.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   444
            (byteIndex-1)*8+1 to:(byteIndex-1)*8+8 do:[:bitIndex |
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   445
                (self at:bitIndex) = what ifTrue:[
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   446
                    count := count + 1.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   447
                    count = n ifTrue:[
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   448
                        ^ bitIndex.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   449
                    ]
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
            ^ 0
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   453
        ].
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   454
        byteIndex := byteIndex + 1.
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   455
    ].
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   456
    ^ 0
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   457
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
     (BooleanArray new:100)
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   460
        at:1 put:true; 
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   461
        at:2 put:true; 
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   462
        at:4 put:true; 
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   463
        at:5 put:true; 
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   464
        at:6 put:true; 
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   465
        at:7 put:true; 
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   466
        at:8 put:true; 
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   467
        at:10 put:true; 
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   468
        indexOfNth:8 occurrenceOf:false         
32bc555a4510 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   469
    "
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
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   472
setTally:size
3551
eb641c9e4e7c class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3534
diff changeset
   473
    "set my tally - that is the actual number of bits in me
eb641c9e4e7c class: BitArray
Claus Gittinger <cg@exept.de>
parents: 3534
diff changeset
   474
     (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
   475
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   476
    tally := size
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   477
! !
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
!BitArray methodsFor:'queries'!
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   480
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   481
defaultElement
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   482
    ^ 0
2094
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   483
!
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
size
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   486
    "return the size of the receiver"
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   487
b3c3f0e17cdb inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2093
diff changeset
   488
    ^ tally
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   489
! !
893
823d2fa809e2 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 736
diff changeset
   490
1459
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   491
!BitArray methodsFor:'visiting'!
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   492
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   493
acceptVisitor:aVisitor with:aParameter
3319
28048b638042 comment/format only
Claus Gittinger <cg@exept.de>
parents: 3279
diff changeset
   494
    "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
   495
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   496
    ^ aVisitor visitBitArray:self with:aParameter
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   497
! !
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   498
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
!BitArray class methodsFor:'documentation'!
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   500
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   501
version
3747
837035fa4d2c #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3551
diff changeset
   502
    ^ '$Header$'
2319
sr
parents: 2225
diff changeset
   503
!
sr
parents: 2225
diff changeset
   504
sr
parents: 2225
diff changeset
   505
version_CVS
3747
837035fa4d2c #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3551
diff changeset
   506
    ^ '$Header$'
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   507
! !
3172
19f296c2d001 class: BitArray
Claus Gittinger <cg@exept.de>
parents: 2319
diff changeset
   508