BooleanArray.st
author Stefan Vogel <sv@exept.de>
Fri, 18 Jan 2008 20:40:51 +0100
changeset 1922 be14f1a04953
parent 1176 8224efd15c5a
child 2076 57efa314833a
permissions -rw-r--r--
#add:beforeIndex: - make immune against redefinition of #add: using #add:beforeIndex in subclasses (and leading to recursion).
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
"
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
905
d6fced2d6d12 category change
Claus Gittinger <cg@exept.de>
parents: 847
diff changeset
    27
"{ Package: 'stx:libbasic2' }"
d6fced2d6d12 category change
Claus Gittinger <cg@exept.de>
parents: 847
diff changeset
    28
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
ArrayedCollection variableByteSubclass:#BooleanArray
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
	instanceVariableNames:'tally'
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
	classVariableNames:''
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
	poolDictionaries:''
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
	category:'Collections-Arrayed'
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
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
!BooleanArray class methodsFor:'documentation'!
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
copyright
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
"
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
 COPYRIGHT (c) 1995 by Claus Gittinger
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
              All Rights Reserved
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
 This software is furnished under a license and may be used
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
 only in accordance with the terms of that license and with the
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
 inclusion of the above copyright notice.   This software may not
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
 be provided or otherwise made available to, or used by, any
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
 other person.  No title to or ownership of the software is
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
 hereby transferred.
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
 This is a demo example:
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
 THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
 ARE DISCLAIMED.  IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
 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
    62
 SUCH DAMAGE.
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
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
documentation
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
"
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
    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
    69
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    example for bulk boolean data (requires only 1/32th the memory
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
    compared to an array of booleans).
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    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
    74
    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
    75
    variable (tally).
552
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
    76
    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
    77
750
4a5176b04075 Fix accessing of bits 8, 16 ...
Stefan Vogel <sv@exept.de>
parents: 736
diff changeset
    78
    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
    79
    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
    80
    in the BER.
4a5176b04075 Fix accessing of bits 8, 16 ...
Stefan Vogel <sv@exept.de>
parents: 736
diff changeset
    81
736
db164846b078 documentation
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
    82
    [memory requirements:]
db164846b078 documentation
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
    83
        OBJ-HEADER + ((size + 7) // 8)
db164846b078 documentation
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
    84
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
    [see also:]
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
        ByteArray WordArray Array
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    [author:]
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
        Claus Gittinger
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
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
examples
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
"
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
                                                                        [exBegin]
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
    (BooleanArray new:7) inspect
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
                                                                        [exEnd]
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
                                                                        [exBegin]
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
    (BooleanArray new:7) basicInspect
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
                                                                        [exEnd]
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
                                                                        [exBegin]
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
    |flags|
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
    flags := BooleanArray new:1000000.
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
    (flags at:9999) printNL.
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
    flags at:9999 put:true.
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
    (flags at:9999) printNL.
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
                                                                        [exEnd]
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
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
!BooleanArray class methodsFor:'instance creation'!
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
new:size
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
    "return a new instance, capable of holding size booleans"
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
    |nBytes|
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
    nBytes := size // 8.
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
    (size \\ 8) ~~ 0 ifTrue:[nBytes := nBytes + 1].
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
    ^ (super new:nBytes) setTally:size
907
4ef63236d698 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 906
diff changeset
   122
4ef63236d698 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 906
diff changeset
   123
    "
4ef63236d698 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 906
diff changeset
   124
     BooleanArray new:10
4ef63236d698 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 906
diff changeset
   125
    "
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
! !
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
!BooleanArray methodsFor:'accessing'!
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
at:index
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
    "retrieve the boolean at index"
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
846
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   133
    |byte mask i0|
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
846
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   135
    (index between:1 and:tally) ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   136
        ^ self subscriptBoundsError:index
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
    ].
846
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   138
    i0 := index - 1.
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   139
    byte := super basicAt:(i0 // 8)+1.
847
936c917d01d1 Fix bit order for ASN.1/BER
Stefan Vogel <sv@exept.de>
parents: 846
diff changeset
   140
    mask := 1 bitShift:(7 - (i0 \\ 8)).
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
    ^ (byte bitAnd:mask) ~~ 0
552
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   142
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   143
    "
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   144
     (BooleanArray new:1000) at:555
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   145
    "
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   146
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   147
    "
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   148
     |b|
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   149
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   150
     b := BooleanArray new:1000.
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   151
     b at:555 put:true.
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   152
     b at:555   
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   153
    "
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   154
750
4a5176b04075 Fix accessing of bits 8, 16 ...
Stefan Vogel <sv@exept.de>
parents: 736
diff changeset
   155
    "Modified: / 31.7.1997 / 18:37:25 / cg"
4a5176b04075 Fix accessing of bits 8, 16 ...
Stefan Vogel <sv@exept.de>
parents: 736
diff changeset
   156
    "Modified: / 23.5.1999 / 20:02:57 / stefan"
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
!
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
at:index put:aBoolean
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
    "store the argument, aBoolean at index; return aBoolean."
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
846
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   162
    |byte mask idx i0|
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
846
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   164
    (index between:1 and:tally) ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   165
        ^ self subscriptBoundsError:index
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
    ].
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
846
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   168
    i0 := index - 1.
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   169
    idx := (i0 // 8) + 1.
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   170
    byte := super basicAt:idx.
847
936c917d01d1 Fix bit order for ASN.1/BER
Stefan Vogel <sv@exept.de>
parents: 846
diff changeset
   171
    mask := 1 bitShift:(7 - (i0 \\ 8)).
846
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   172
    aBoolean == true ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   173
        byte := byte bitOr:mask
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
    ] ifFalse:[
846
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   175
        aBoolean == false ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   176
            byte := byte bitAnd:(mask bitInvert)
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   177
        ] ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   178
            "/ not true or false
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   179
            ^ self elementBoundsError:aBoolean
846
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   180
        ]
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
    ].
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   182
    super basicAt:idx put:byte.
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
    ^ aBoolean.
552
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   184
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   185
    "
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   186
     |b|
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   187
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   188
     b := BooleanArray new:1000.
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   189
     b at:555 put:true.
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   190
     b at:555   
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   191
    "
21cfe670f469 comment
Claus Gittinger <cg@exept.de>
parents: 377
diff changeset
   192
750
4a5176b04075 Fix accessing of bits 8, 16 ...
Stefan Vogel <sv@exept.de>
parents: 736
diff changeset
   193
    "Modified: / 31.7.1997 / 18:37:35 / cg"
4a5176b04075 Fix accessing of bits 8, 16 ...
Stefan Vogel <sv@exept.de>
parents: 736
diff changeset
   194
    "Modified: / 23.5.1999 / 20:02:42 / stefan"
905
d6fced2d6d12 category change
Claus Gittinger <cg@exept.de>
parents: 847
diff changeset
   195
! !
d6fced2d6d12 category change
Claus Gittinger <cg@exept.de>
parents: 847
diff changeset
   196
d6fced2d6d12 category change
Claus Gittinger <cg@exept.de>
parents: 847
diff changeset
   197
!BooleanArray methodsFor:'filling & replacing'!
d6fced2d6d12 category change
Claus Gittinger <cg@exept.de>
parents: 847
diff changeset
   198
846
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   199
atAllPut:aBoolean
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   200
    |v|
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   201
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   202
    aBoolean == true ifTrue:[
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   203
        v := 255
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   204
    ] ifFalse:[
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   205
        aBoolean == false ifTrue:[
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   206
            v := 0
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   207
        ] ifFalse:[
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   208
            "/
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   209
            "/ booleanArrays can only hold true and false
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   210
            "/
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   211
            ^ self elementBoundsError:aBoolean
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   212
        ]
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   213
    ].
846
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   214
    1 to:self basicSize do:[:i |
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   215
        super basicAt:i put:v
Claus Gittinger <cg@exept.de>
parents: 825
diff changeset
   216
    ].
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
! !
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
!BooleanArray methodsFor:'private'!
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
setTally:size
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
    tally := size
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
! !
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
906
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
   225
!BooleanArray methodsFor:'queries'!
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
   226
907
4ef63236d698 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 906
diff changeset
   227
defaultElement
4ef63236d698 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 906
diff changeset
   228
    ^ false
4ef63236d698 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 906
diff changeset
   229
!
4ef63236d698 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 906
diff changeset
   230
906
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
   231
size
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
   232
    "return the size of the receiver"
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
   233
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
   234
    ^ tally
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
   235
! !
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
   236
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
!BooleanArray class methodsFor:'documentation'!
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
version
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 907
diff changeset
   240
    ^ '$Header: /cvs/stx/stx/libbasic2/BooleanArray.st,v 1.11 2003-04-22 09:38:23 cg Exp $'
377
3be86dc85537 moved from goodies
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
! !