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