BitArray.st
author Stefan Vogel <sv@exept.de>
Thu, 08 Nov 2007 15:03:20 +0100
changeset 1909 c76efba26558
parent 1644 540979f371b3
child 2077 1ee59d1df2de
permissions -rw-r--r--
Methods to get all addresses for a given hostname (multihomed hosts)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 This is a demo example:
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
 THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
 ARE DISCLAIMED.  IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
 SUCH DAMAGE.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
893
823d2fa809e2 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 736
diff changeset
    28
"{ Package: 'stx:libbasic2' }"
823d2fa809e2 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 736
diff changeset
    29
736
db164846b078 documentation
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
    30
BooleanArray variableByteSubclass:#BitArray
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
	instanceVariableNames:''
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
	classVariableNames:''
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
	poolDictionaries:''
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
	category:'Collections-Arrayed'
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
!
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
!BitArray class methodsFor:'documentation'!
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
copyright
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
 COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
              All Rights Reserved
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
 This software is furnished under a license and may be used
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
 only in accordance with the terms of that license and with the
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
 inclusion of the above copyright notice.   This software may not
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
 be provided or otherwise made available to, or used by, any
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
 other person.  No title to or ownership of the software is
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
 hereby transferred.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
 This is a demo example:
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
 THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
 ARE DISCLAIMED.  IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
 SUCH DAMAGE.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
!
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
documentation
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    like a booleanArray, but storing & returning 0's and 1's.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
736
db164846b078 documentation
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
    72
    [memory requirements:]
db164846b078 documentation
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
    73
        OBJ-HEADER + ((size + 7) // 8)
db164846b078 documentation
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
    74
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
    [author:]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
        Claus Gittinger
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
    [see also:]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
        BooleanArray ByteArray WordArray Array
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
!
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
examples
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
                                                                        [exBegin]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    (BitArray new:7) inspect
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
                                                                        [exEnd]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
                                                                        [exBegin]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
    (BitArray new:7) basicInspect
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
                                                                        [exEnd]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
                                                                        [exBegin]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
    |bits|
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
    bits := BitArray new:1000000.
1644
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
    95
    (bits at:9999) printCR.
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
    bits at:9999 put:1.
1644
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
    97
    (bits at:9999) printCR.
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
                                                                        [exEnd]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
! !
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
!BitArray methodsFor:'accessing'!
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
at:index
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
    "retrieve the bit at index"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
    ^ (super at:index) ifTrue:[1] ifFalse:[0]
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
    "
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
     (BitArray new:1000) at:555
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
    "
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    "
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
     |b|
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
     b := BitArray new:1000.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
     b at:555 put:1.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
     b at:555   
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
    "
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
    "Created: 5.9.1997 / 12:36:38 / cg"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
    "Modified: 5.9.1997 / 12:38:38 / cg"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
!
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
at:index put:aBit
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
    "store the argument, aBit at index; return aBit."
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
    aBit == 0 ifTrue:[
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
        super at:index put:false.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
        ^ aBit.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
    ].
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
    aBit == 1 ifTrue:[
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
        super at:index put:true.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
        ^ aBit.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
    ].
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
    "/
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
    "/ bitArrays can only hold 0's and 1's
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
    "/
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   139
    ^ self elementBoundsError:aBit
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
    "
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
     |b|
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
     b := BitArray new:1000.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
     b at:555 put:1.
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
     b at:555    
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
    "
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
    "Created: 5.9.1997 / 12:37:28 / cg"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
    "Modified: 5.9.1997 / 12:41:18 / cg"
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
! !
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
1644
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   153
!BitArray methodsFor:'converting'!
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   154
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   155
bytes
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   156
    "answer myself as a ByteArray containing my bytes"
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   157
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   158
    |size bytes|
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   159
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   160
    size := self basicSize.
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   161
    bytes := ByteArray new:size.
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   162
    1 to:size do:[:index|
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   163
        bytes at:index put:(self byteAt:index)
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   164
    ].
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   165
    ^ bytes
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   166
! !
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   167
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   168
!BitArray methodsFor:'filling & replacing'!
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   169
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   170
atAllPut:aBit
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   171
    aBit == 0 ifTrue:[
1241
ed1613417ba2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1176
diff changeset
   172
        ^ super atAllPut:false
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   173
    ].
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   174
    aBit == 1 ifTrue:[
1241
ed1613417ba2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1176
diff changeset
   175
        ^ super atAllPut:true
1176
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   176
    ].
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   177
    "/
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   178
    "/ bitArrays can only hold 0's and 1's
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   179
    "/
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   180
    ^ self elementBoundsError:aBit
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   181
! !
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   182
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   183
!BitArray methodsFor:'queries'!
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   184
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   185
defaultElement
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   186
    ^ 0
8224efd15c5a elementBoundsError -> elementBoundsError:
Claus Gittinger <cg@exept.de>
parents: 893
diff changeset
   187
! !
893
823d2fa809e2 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 736
diff changeset
   188
1644
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   189
1459
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   190
!BitArray methodsFor:'visiting'!
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   191
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   192
acceptVisitor:aVisitor with:aParameter
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   193
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   194
    ^ aVisitor visitBitArray:self with:aParameter
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   195
! !
914d762066f0 Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 1241
diff changeset
   196
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
!BitArray class methodsFor:'documentation'!
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
version
1644
540979f371b3 Allow to access the bytes of a BitArray: #bytes
Stefan Vogel <sv@exept.de>
parents: 1459
diff changeset
   200
    ^ '$Header: /cvs/stx/stx/libbasic2/BitArray.st,v 1.7 2006-06-29 08:24:49 stefan Exp $'
565
ce41ffaf3b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
! !