|
Class: BooleanArray
Object
|
+--Collection
|
+--SequenceableCollection
|
+--ArrayedCollection
|
+--BitArray
|
+--BooleanArray
- Package:
- stx:libbasic
- Category:
- Collections-Arrayed
- Version:
- rev:
1.9
date: 2022/07/11 14:46:57
- user: cg
- file: BooleanArray.st directory: libbasic
- module: stx stc-classLibrary: libbasic
BooleanArrays are specially tuned to store booleans (true and false),
and are useful for bulk bit/boolean data.
Instances require only 1/32th (32bit machines) or even 1/64th (64bit machines)
of memory compared to a regular array of booleans.
They store 8 booleans per byte.
Since instances store bits in multiples of 8,
the real size of the collection is kept in an extra instance variable (tally).
It may be useful if huge boolean arrays are to be used.
BooleanArrays can be used as literals i.e. you can enter BooleanArrays-constants as:
#B( element1 element2 .... elementN ) // B stands for Boolean in contrast to 'b' for bit
for example:
#B(true false false true )
ATTENTION:
inheriting from BitArray, bits 1 to 8 of the BooleanArray are stored in bits 8 to 1
of the corresponding byte, to allow easy mapping to ASN.1 BIT STRING encoding
in the BER.
Do not change this.
[memory requirements:]
OBJ-HEADER + ((size + 7) // 8)
[complexity:]
see Array
copyrightCOPYRIGHT (c) 1995 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
This is a demo example:
THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTOR ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTOR BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
queries
-
isValidElement: anObject
-
return true, if instances of me can hold this kind of object
-
literalTokenPrefix
-
accessing
-
at: index
-
retrieve the boolean at index
Usage example(s):
(BooleanArray new:1000) at:555
|
Usage example(s):
|b|
b := BooleanArray new:1000.
b at:555 put:true.
b at:555
|
-
at: index put: aBoolean
-
store the argument, aBoolean at index; return aBoolean (sigh).
Usage example(s):
|b|
b := BooleanArray new:1000.
b at:555 put:true.
b at:555
|
-
occurrencesOf: anElement
-
count the occurrences of the argument, anElement in the receiver
Usage example(s):
(BooleanArray new:10)
at:4 put:true;
at:6 put:true;
at:7 put:true;
occurrencesOf:true
|
filling & replacing
-
atAllPut: aBoolean
-
replace all elements of the collection by the argument, aBoolean.
Return the receiver.
The argument, aBoolean must be true or false.
Notice: This operation modifies the receiver, NOT a copy;
therefore the change may affect all others referencing the receiver.
queries
-
defaultElement
-
(BooleanArray new:7) inspect
|
(BooleanArray new:7) basicInspect
|
|flags|
flags := BooleanArray new:1000000.
(flags at:9999) printNL.
flags at:9999 put:true.
(flags at:9999) printNL.
|
|