eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'IntegerArray':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: IntegerArray


Inheritance:

   Object
   |
   +--Collection
      |
      +--SequenceableCollection
         |
         +--ArrayedCollection
            |
            +--UninterpretedBytes
               |
               +--AbstractNumberVector
                  |
                  +--UnboxedIntegerArray
                     |
                     +--IntegerArray

Package:
stx:libbasic
Category:
Collections-Arrayed
Version:
rev: 1.15 date: 2024/02/14 11:39:35
user: cg
file: IntegerArray.st directory: libbasic
module: stx stc-classLibrary: libbasic

Description:


IntegerArrays store unsigned 32bit integers in the range 0..16rFFFFFFFF.
In contrast to normal arrays (which store pointers to their elements),
integerArrays store the values in a dense & compact way. 
Since the representation fits the underlying C-language systems representation
of unsigned int32's, this is also useful to pass bulk data to c primitive code.

IntegerArrays can be used as literals i.e. you can enter IntegerArray-constants as: 
    #u32( element1 element2 .... elementN ) 
    #s32( element1 element2 .... elementN ) 
for example:
    #u32(1 2 3 4 5 6 7 8)
    #s32(1 2 3 4 -1 -2 -3 -4)

Aliased as UInt32Array.

[memory requirements:]
    OBJ-HEADER + (size * 4)


[caveat:]
    should probably be renamed to UInt32Array
    (there is an alias named 'UInt32Array', but when inspected,
    it presents itself as IntegerArray)
    

copyright

COPYRIGHT (c) 1997 by eXept Software AG 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.

Class protocol:

queries
o  elementByteSize
for bit-like containers, return the number of bytes stored per element.
Here, 4 is returned

o  literalTokenPrefix

o  maxVal
the maximum value which can be stored in instances of me

o  minVal
the minimum value which can be stored in instances of me


Instance protocol:

accessing
o  unsignedInt32At: byteIndex MSB: msb
return the 4-bytes starting at byteIndex as an (unsigned) Integer.
The byteIndex is a smalltalk index (i.e. 1-based).
The value is retrieved MSB (high 8 bits at lower index) if msb is true;
LSB-first (i.e. low 8-bits at lower byte index) if it's false.
Notice:
the index is a byte index; thus, this allows for unaligned access to
words on any boundary.

Usage example(s):

     (#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:1) hexPrintString:8  => '00000201'
     (#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:2) hexPrintString:8  => '03000002'
     (#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:3) hexPrintString:8  => '04030000'
     (#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:4) hexPrintString:8  => '00040300'
     (#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:5) hexPrintString:8  => '00000403'

     (#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:1 MSB:false) hexPrintString:8  => '00000201'
     (#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:5 MSB:false) hexPrintString:8  => '00000403'
     (#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:9 MSB:false) hexPrintString:8  => '00000605'

     (#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:2 MSB:false) hexPrintString:8  => '03000002'
     (#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:3 MSB:false) hexPrintString:8  => '04030000'
     (#(16r0201 16r0403 16r0605) asIntegerArray unsignedInt32At:4 MSB:false) hexPrintString:8  => '00040300'

     (#(16rFFEE 16r0403 16r0605) asIntegerArray unsignedInt32At:1 MSB:false) hexPrintString:8  => '0000FFEE'
     (#(16rFFEE 16r0403 16r0605) asIntegerArray unsignedInt32At:1 MSB:true ) hexPrintString:8  => 'EEFF0000'

comparing
o  < anIntegerArray
Compare each element of the receiver against corresponding elements of the argument
and return true if all receiver elements are greater than the corresponding argument element.
Otherwise return false.
If the receiver has less arguments than the argument, and all elements so far
are equal, true is returned.
Redefined for speed (xpath handling)

Usage example(s):

        (IntegerArray newFrom:#[1 2 3 4 5]) < (IntegerArray newFrom:#[1 2 3 4 5]) 
        (IntegerArray newFrom:#[1 2 3 4 5]) < (IntegerArray newFrom:#[1 2 3 4])   
        (IntegerArray newFrom:#[1 2 3 4]) < (IntegerArray newFrom:#[1 2 3 4 5])  
        (IntegerArray newFrom:#[1 2 3 4 5]) < (IntegerArray newFrom:#[1 2 3 4 6])
        (IntegerArray newFrom:#[]) < (IntegerArray newFrom:#[1 2 3 4 6])

converting
o  asIntegerArray
return a new IntegerArray with the collection's elements.
That's the receiver itself here

filling and replacing
o  equalFrom: start to: stop with: aCollection startingAt: replStart
compare elements in the receiver between index start and stop,
with elements taken from aCollection starting at repStart.
Return true if the values are equal, false if not.

Usage example(s):

     #u32(1 2 3 4 5 6 7 8 9 0) equalFrom:5 to:7 with:#(1 2 3 4) startingAt:3        => false
     #u32(1 2 3 4 5 6 7 8 9 0) equalFrom:5 to:7 with:#(0 0 5 6 7) startingAt:3      => true
     #u32(1 2 3 4 5 6 7 8 9 0) equalFrom:5 to:7 with:#u32(0 0 5 6 7) startingAt:3   => true
     #u32(1 2 3 4 5 6 7 8 9 0) equalFrom:5 to:7 with:#u32(5 6 7) startingAt:1       => true
     #u32(1 2 3 4 5 6 7 8 9 0) equalFrom:5 to:7 with:#u32(5 6 8) startingAt:1       => false
     #u32(1 2 3 4 5 6 7 8 9 0) equalFrom:5 to:7 with:#u32(5 7 8) startingAt:1       => false
     #u32(1 2 3 4 5 6 7 8 9 0) equalFrom:5 to:7 with:#u32(6 7 8) startingAt:1       => false

o  replaceFrom: start to: stop with: aCollection startingAt: replStart
replace elements in the receiver between index start and stop,
with elements taken from aCollection starting at repStart.
Return the receiver.

Usage example(s):

     |f1 f2|

     f1 := (100 to:105) asUnsignedInt32Array.
     f2 := #(1 2 3 4 5 6 7 8) asUnsignedInt32Array.
     f1 replaceFrom:1 to:3 with:f2 startingAt:3.
     self assert:(f1 = #u32( 3 4 5 103 104 105) )

Usage example(s):

     |f1 f2|

     f1 := (100 to:105) asUnsignedInt32Array.
     f2 := #(1 2 3 4 5 6 7 8) asSignedWordArray.
     f1 replaceFrom:1 to:3 with:f2 startingAt:3.
     self assert:(f1 = #u32( 3 4 5 103 104 105) )

Usage example(s):

     |f1 f2|

     f1 := (100 to:107) asUnsignedInt32Array.
     f2 := #(1 2 3 4 5 6 7 8) asSignedWordArray.
     f1 replaceFrom:3 to:6 with:f2 startingAt:2.
     self assert:(f1 = #u32(100 101 2 3 4 5 106 107) )

Usage example(s):

     |f1 f2|

     f1 := (100 to:105) asUnsignedInt32Array.
     f2 := #(1 2 3 4 5 6 7 8) asSignedWordArray.
     f1 replaceFrom:1 to:6 with:f2 startingAt:1.
     self assert:(f1 = #u32(1 2 3 4 5 6) )

Usage example(s):

     |d s|
     d := IntegerArray new:1000.
     s := (1 to:1000) asUnsignedInt32Array.
     (Time toRun:[
        100 timesRepeat:[ d replaceFrom:1 to:1000 with:s startingAt:1 ]
     ]) / 100.   260ns 330ns 330ns 
                 old: 41µs  38µs 39µs



ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Mon, 18 Nov 2024 08:45:14 GMT