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