BooleanArray.st
author Claus Gittinger <cg@exept.de>
Thu, 09 Jun 2016 18:09:58 +0200
changeset 3934 3fc6968232c1
parent 3277 06babe114ad2
child 4049 7eaa1952713c
permissions -rw-r--r--
class: exept_expecco_plugin class definition
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 This is a demo example:
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
 THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
 ARE DISCLAIMED.  IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
 SUCH DAMAGE.
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
"
905
d6fced2d6d12 category change
Claus Gittinger <cg@exept.de>
parents: 847
diff changeset
    26
"{ Package: 'stx:libbasic2' }"
d6fced2d6d12 category change
Claus Gittinger <cg@exept.de>
parents: 847
diff changeset
    27
2095
758fae28f72b inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2092
diff changeset
    28
BitArray variableByteSubclass:#BooleanArray
758fae28f72b inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2092
diff changeset
    29
	instanceVariableNames:''
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
	classVariableNames:''
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
	poolDictionaries:''
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
	category:'Collections-Arrayed'
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
!
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
!BooleanArray class methodsFor:'documentation'!
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
copyright
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
"
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
 COPYRIGHT (c) 1995 by Claus Gittinger
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
              All Rights Reserved
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
 This software is furnished under a license and may be used
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
 only in accordance with the terms of that license and with the
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
 inclusion of the above copyright notice.   This software may not
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
 be provided or otherwise made available to, or used by, any
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
 other person.  No title to or ownership of the software is
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
 hereby transferred.
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
 This is a demo example:
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
 THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
 ARE DISCLAIMED.  IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
 SUCH DAMAGE.
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
"
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
!
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
documentation
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
"
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
    This is a simple demo class only; currently not used in the system.
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
    example for bulk boolean data (requires only 1/32th the memory
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    compared to an array of booleans).
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    This one stores 8 booleans per byte. Since instances store bits in multiples
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    of 8, we have to keep the real size of the collection in an extra instance
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
    variable (tally).
552
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
    75
    It may be useful if huge boolean arrays are to be used.
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
750
4a5176b04075 Fix accessing of bits 8, 16 ...
Stefan Vogel <sv@exept.de>
parents: 736
diff changeset
    77
    Bits 1 to 8 of the BooleanArray are stored in bits 8 to 1 of the
4a5176b04075 Fix accessing of bits 8, 16 ...
Stefan Vogel <sv@exept.de>
parents: 736
diff changeset
    78
    corresponding byte, to allow easy mapping to ASN.1 BIT STRING encoding
4a5176b04075 Fix accessing of bits 8, 16 ...
Stefan Vogel <sv@exept.de>
parents: 736
diff changeset
    79
    in the BER.
4a5176b04075 Fix accessing of bits 8, 16 ...
Stefan Vogel <sv@exept.de>
parents: 736
diff changeset
    80
736
db164846b078 documentation
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
    81
    [memory requirements:]
db164846b078 documentation
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
    82
        OBJ-HEADER + ((size + 7) // 8)
db164846b078 documentation
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
    83
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
    [see also:]
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
        ByteArray WordArray Array
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
    [author:]
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
        Claus Gittinger
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
"
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
!
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
examples
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
"
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
                                                                        [exBegin]
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
    (BooleanArray new:7) inspect
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
                                                                        [exEnd]
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
                                                                        [exBegin]
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
    (BooleanArray new:7) basicInspect
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
                                                                        [exEnd]
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
                                                                        [exBegin]
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
    |flags|
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
    flags := BooleanArray new:1000000.
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
    (flags at:9999) printNL.
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
    flags at:9999 put:true.
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
    (flags at:9999) printNL.
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
                                                                        [exEnd]
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
"
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
! !
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
!BooleanArray methodsFor:'accessing'!
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
at:index
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
    "retrieve the boolean at index"
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
2095
758fae28f72b inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2092
diff changeset
   116
    ^ (super at:index) == 1
552
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   117
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   118
    "
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   119
     (BooleanArray new:1000) at:555
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   120
    "
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   121
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   122
    "
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   123
     |b|
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   124
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   125
     b := BooleanArray new:1000.
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   126
     b at:555 put:true.
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   127
     b at:555   
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   128
    "
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   129
750
4a5176b04075 Fix accessing of bits 8, 16 ...
Stefan Vogel <sv@exept.de>
parents: 736
diff changeset
   130
    "Modified: / 31.7.1997 / 18:37:25 / cg"
4a5176b04075 Fix accessing of bits 8, 16 ...
Stefan Vogel <sv@exept.de>
parents: 736
diff changeset
   131
    "Modified: / 23.5.1999 / 20:02:57 / stefan"
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
!
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
at:index put:aBoolean
2076
57efa314833a comment
Claus Gittinger <cg@exept.de>
parents: 1176
diff changeset
   135
    "store the argument, aBoolean at index; return aBoolean (sigh)."
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
2106
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   137
    |v|
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   138
846
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   139
    aBoolean == true ifTrue:[
2106
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   140
        v := 1.
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
    ] ifFalse:[
846
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   142
        aBoolean == false ifTrue:[
2106
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   143
            v := 0.
846
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   144
        ] ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   145
            "/ not true or false
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   146
            ^ self elementBoundsError:aBoolean
846
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   147
        ]
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
    ].
2106
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   149
    super at:index put:v.
2095
758fae28f72b inheritance reversed
Claus Gittinger <cg@exept.de>
parents: 2092
diff changeset
   150
    ^ aBoolean
552
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   151
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   152
    "
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   153
     |b|
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   154
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   155
     b := BooleanArray new:1000.
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   156
     b at:555 put:true.
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   157
     b at:555   
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   158
    "
2092
65369379b094 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2076
diff changeset
   159
!
65369379b094 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2076
diff changeset
   160
65369379b094 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2076
diff changeset
   161
occurrencesOf:anElement
3277
06babe114ad2 class: BooleanArray
Claus Gittinger <cg@exept.de>
parents: 2106
diff changeset
   162
    "count the occurrences of the argument, anElement in the receiver"
06babe114ad2 class: BooleanArray
Claus Gittinger <cg@exept.de>
parents: 2106
diff changeset
   163
2106
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   164
    |nOnes|
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   165
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   166
    nOnes := self countOnes.
2092
65369379b094 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2076
diff changeset
   167
    anElement == true ifTrue:[
2106
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   168
        ^ nOnes
2092
65369379b094 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2076
diff changeset
   169
    ].
65369379b094 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2076
diff changeset
   170
    anElement == false ifTrue:[
2106
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   171
        ^ tally - nOnes
2092
65369379b094 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2076
diff changeset
   172
    ].
65369379b094 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2076
diff changeset
   173
    ^ 0
2106
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   174
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   175
    "
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   176
     (BooleanArray new:10)
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   177
        at:4 put:true;
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   178
        at:6 put:true;
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   179
        at:7 put:true;
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   180
        occurrencesOf:true
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   181
    "
905
d6fced2d6d12 category change
Claus Gittinger <cg@exept.de>
parents: 847
diff changeset
   182
! !
d6fced2d6d12 category change
Claus Gittinger <cg@exept.de>
parents: 847
diff changeset
   183
d6fced2d6d12 category change
Claus Gittinger <cg@exept.de>
parents: 847
diff changeset
   184
!BooleanArray methodsFor:'filling & replacing'!
d6fced2d6d12 category change
Claus Gittinger <cg@exept.de>
parents: 847
diff changeset
   185
846
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   186
atAllPut:aBoolean
3277
06babe114ad2 class: BooleanArray
Claus Gittinger <cg@exept.de>
parents: 2106
diff changeset
   187
    "replace all elements of the collection by the argument, aBoolean.
06babe114ad2 class: BooleanArray
Claus Gittinger <cg@exept.de>
parents: 2106
diff changeset
   188
     The argument, aBoolean must be true or false.
06babe114ad2 class: BooleanArray
Claus Gittinger <cg@exept.de>
parents: 2106
diff changeset
   189
     Notice: This operation modifies the receiver, NOT a copy;
06babe114ad2 class: BooleanArray
Claus Gittinger <cg@exept.de>
parents: 2106
diff changeset
   190
     therefore the change may affect all others referencing the receiver."
06babe114ad2 class: BooleanArray
Claus Gittinger <cg@exept.de>
parents: 2106
diff changeset
   191
2106
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   192
    |v|
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   193
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   194
    aBoolean == true ifTrue:[
2106
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   195
        v := 1
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   196
    ] ifFalse:[
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   197
        aBoolean == false ifTrue:[
2106
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   198
            v := 0
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   199
        ] ifFalse:[
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   200
            "/ booleanArrays can only hold true and false
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   201
            ^ self elementBoundsError:aBoolean
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   202
        ]
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   203
    ].
2106
a445665aa66a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2095
diff changeset
   204
    super atAllPut:v
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
! !
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
906
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
   207
!BooleanArray methodsFor:'queries'!
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
   208
907
4ef63236d698 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 906
diff changeset
   209
defaultElement
4ef63236d698 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 906
diff changeset
   210
    ^ false
906
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
   211
! !
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
   212
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
!BooleanArray class methodsFor:'documentation'!
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
version
3277
06babe114ad2 class: BooleanArray
Claus Gittinger <cg@exept.de>
parents: 2106
diff changeset
   216
    ^ '$Header: /cvs/stx/stx/libbasic2/BooleanArray.st,v 1.16 2014-05-13 09:07:40 cg Exp $'
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
! !
3277
06babe114ad2 class: BooleanArray
Claus Gittinger <cg@exept.de>
parents: 2106
diff changeset
   218