Collections-Arrayed

Array
I present an ArrayedCollection whose elements are objects.
+*
Premultiply aCollection by self. aCollection should be an Array or Matrix.
The name of this method is APL's +.x squished into Smalltalk syntax.
asArray
Answer with the receiver itself.
atWrap:
Optimized to go through the primitive if possible
atWrap:put:
Optimized to go through the primitive if possible
braceStream:
braceWith:
braceWith:with:
braceWith:with:with:
braceWith:with:with:with:
braceWithNone
byteEncode:
copyWithDependent:
Answer a new collection with newElement added (as last
element if sequenceable).
elementsExchangeIdentityWith:
This primitive performs a bulk mutation, causing all pointers to the elements of this array to be replaced by pointers to the corresponding elements of otherArray. At the same time, all pointers to the elements of otherArray are replaced by pointers to the corresponding elements of this array. The identityHashes remain with the pointers rather than with the objects so that objects in hashed structures should still be properly indexed after the mutation.
elementsForwardIdentityTo:
This primitive performs a bulk mutation, causing all pointers to the elements of this array to be replaced by pointers to the corresponding elements of otherArray. The identityHashes remain with the pointers rather than with the objects so that the objects in this array should still be properly indexed in any existing hashed structures after the mutation.
elementsForwardIdentityTo:copyHash:
This primitive performs a bulk mutation, causing all pointers to the elements of this array to be replaced by pointers to the corresponding elements of otherArray. The identityHashes remain with the pointers rather than with the objects so that the objects in this array should still be properly indexed in any existing hashed structures after the mutation.
evalStrings
Allows you to construct literal arrays.
#(true false nil '5@6' 'Set new' '''text string''') evalStrings
gives an array with true, false, nil, a Point, a Set, and a String
instead of just a bunch of Symbols
hasLiteral:
Answer true if literal is identical to any literal in this array, even
if imbedded in further array structure. This method is only intended
for private use by CompiledMethod hasLiteralSymbol:
hasLiteralSuchThat:
Answer true if testBlock returns true for any literal in this array, even if imbedded in further Arrays or CompiledMethods. This method is only intended for private use by CompiledMethod hasLiteralSuchThat:
isArray
isLiteral
Answer whether the receiver has a literal text form recognized by the
compiler.
isSelfEvaluating
literalEqual:
new:
objectForDataStream:
I am about to be written on an object file. If I am one of two shared global arrays, write a proxy instead.
preMultiplyByArray:
Answer a+*self where a is an Array. Arrays are always understood as column vectors,
so an n element Array is an n*1 Array. This multiplication is legal iff self size = 1.
preMultiplyByMatrix:
Answer m+*self where m is a Matrix.
printAsLiteralFormOn:
printAsSelfEvaluatingFormOn:
printOn:
Append a sequence of characters that identify the receiver to aStream.
refersToLiteral:
Answer true if literal is identical to any literal in this array, even if imbedded in further array structures or closure methods
replaceFrom:to:with:startingAt:
Primitive. This destructively replaces elements from start to stop in the receiver starting at index, repStart, in the collection, replacement. Answer the receiver. Range checks are performed in the primitive only. Optional. See Object documentation whatIsAPrimitive.
storeOn:
Use the literal form if possible.
storeOnStream:
ByteArray
I represent an ArrayedCollection whose elements are integers between 0 and 255.
asByteArray
Answer a ByteArray whose elements are the elements of the receiver.
asByteArrayOfSize:
'34523' asByteArray asByteArrayOfSize: 100.
(((
| repeats bytes |
repeats := 1000000.
bytes := '123456789123456789123456789123456789123456789123456789' asByteArray.
[repeats timesRepeat: (bytes asByteArrayOfSize: 1024) ] timeToRun.
)))
asByteArrayPointer
Return a ByteArray describing a pointer to the contents of the receiver.
asIpString
asMIMEDocument
asMIMEDocumentType:
asSocketAddress
asString
Convert to a String with Characters for each byte.
Fast code uses primitive that avoids character conversion
asWideString
atAllPut:
Fill the receiver with the given value
bitXor:
byteAt:
byteAt:put:
byteSize
bytesPerElement
Number of bytes in each item. This multiplied by (self size)*8 gives the number of bits stored.
defaultElement
destroy
doubleAt:bigEndian:
Return a 64 bit float starting from the given byte index
doubleAt:put:bigEndian:
Store a 64 bit float starting from the given byte index
floatAt:bigEndian:
hash
#hash is implemented, because #= is implemented
hashBytes:startingWith:
hex
isLiteral
so that #(1 #[1 2 3] 5) prints itself
lastIndexOfPKSignature:
Answer the last index in me where aSignature (4 bytes long) occurs, or 0 if not found
longAt:bigEndian:
Return a 32bit integer quantity starting from the given byte index
longAt:put:bigEndian:
Return a 32bit integer quantity starting from the given byte index
nsReadStreamClass
nsWriteStreamClass
printOn:
Append a sequence of characters that identify the receiver to aStream.
renderOn:
Override this method to customize how objects (not components) are rendered when passed as an argument to #render:. The default is the return value of #displayString.
Just remember that you can not use #callback:, #on:of:, or #call:
replaceFrom:to:with:startingAt:
Primitive. This destructively replaces elements from start to stop in the receiver starting at index, repStart, in the collection, replacement. Answer the receiver. Range checks are performed in the primitive only. Optional. See Object documentation whatIsAPrimitive.
shortAt:bigEndian:
Return a 16 bit integer quantity starting from the given byte index
shortAt:put:bigEndian:
Store a 16 bit integer quantity starting from the given byte index
storeOn:
Refer to the comment in Object|storeOn:.
unsignedLongAt:bigEndian:
Return a 32bit unsigned integer quantity starting from the given byte index
unsignedLongAt:put:bigEndian:
Store a 32bit unsigned integer quantity starting from the given byte index
unsignedShortAt:bigEndian:
Return a 16 bit unsigned integer quantity starting from the given byte index
unsignedShortAt:put:bigEndian:
Store a 16 bit unsigned integer quantity starting from the given byte index
ColorArray
A ColorArray is xxxxxxxxx.
Instance Variables
asColorArray
at:
Primitive. Assumes receiver is indexable. Answer the value of an
indexable element in the receiver. Fail if the argument index is not an
Integer or is out of bounds. Essential. See Object documentation
whatIsAPrimitive.
at:put:
Primitive. Assumes receiver is indexable. Store the argument value in
the indexable element of the receiver indicated by index. Fail if the
index is not an Integer or is out of bounds. Or fail if the value is not of
the right type for this kind of collection. Answer the value that was
stored. Essential. See Object documentation whatIsAPrimitive.
bytesPerElement
FloatArray
FloatArrays store 32bit IEEE floating point numbers.
*
*=
+
+=
-
-=
/
/=
=
Answer true if the receiver is equivalent to the otherCollection.
First test for identity, then rule out different species and sizes of
collections. As a last resort, examine each element of the receiver
and the otherCollection.
\\=
adaptToNumber:andSend:
If I am involved in arithmetic with a Number. If possible,
convert it to a float and perform the (more efficient) primitive operation.
asFloatArray
Answer a FloatArray whose elements are the elements of the receiver, in
the same order.
at:
Primitive. Assumes receiver is indexable. Answer the value of an
indexable element in the receiver. Fail if the argument index is not an
Integer or is out of bounds. Essential. See Object documentation
whatIsAPrimitive.
at:put:
Primitive. Assumes receiver is indexable. Store the argument value in
the indexable element of the receiver indicated by index. Fail if the
index is not an Integer or is out of bounds. Or fail if the value is not of
the right type for this kind of collection. Answer the value that was
stored. Essential. See Object documentation whatIsAPrimitive.
defaultElement
Return the default element of the receiver
dot:
Primitive. Return the dot product of the receiver and the argument.
Fail if the argument is not of the same size as the receiver.
hash
Answer an integer hash value for the receiver such that,
-- the hash value of an unchanged object is constant over time, and
-- two equal objects have equal hash values
inspectorClass
Answer the class of the inspector to be used on the receiver. Called by inspect;
use basicInspect to get a normal (less useful) type of inspector.
length
Return the length of the receiver
negated
Negated value of all elements in the collection
primAddArray:
primAddScalar:
primDivArray:
primDivScalar:
primMulArray:
primMulScalar:
primSubArray:
primSubScalar:
replaceFrom:to:with:startingAt:
Primitive. This destructively replaces elements from start to stop in the receiver starting at index, repStart, in the collection, replacement. Answer the receiver. Range checks are performed in the primitive only. Optional. See Object documentation whatIsAPrimitive.
squaredLength
Return the squared length of the receiver
sum
This is implemented using a variant of the normal inject:into: pattern.
The reason for this is that it is not known whether we're in the normal
number line, i.e. whether 0 is a good initial value for the sum.
Consider a collection of measurement objects, 0 would be the unitless
value and would not be appropriate to add with the unit-ed objects.
IntegerArray
IntegerArrays store 32bit signed Integer values.
Negative values are stored as 2's complement.
asIntegerArray
Answer an IntegerArray whose elements are the elements of the receiver, in
the same order.
at:
Primitive. Assumes receiver is indexable. Answer the value of an
indexable element in the receiver. Fail if the argument index is not an
Integer or is out of bounds. Essential. See Object documentation
whatIsAPrimitive.
at:put:
Primitive. Assumes receiver is indexable. Store the argument value in
the indexable element of the receiver indicated by index. Fail if the
index is not an Integer or is out of bounds. Or fail if the value is not of
the right type for this kind of collection. Answer the value that was
stored. Essential. See Object documentation whatIsAPrimitive.
atAllPut:
Put anObject at every one of the receiver's indices.
defaultElement
Return the default element of the receiver
primFill:
Fill the receiver, an indexable bytes or words object, with the given positive integer. The range of possible fill values is [0..255] for byte arrays and [0..(2^32 - 1)] for word arrays.
KedamaFloatArray
A KedamaFloatArray is xxxxxxxxx.
Instance Variables
*
*=
+
+=
-
-=
/
/=
primAddArray:and:into:
^ KedamaPlugin doPrimitive: #primitiveAddArrays.
primAddScalar:and:into:
^ KedamaPlugin doPrimitive: #primitiveAddScalar.
primDivArray:and:into:
^ KedamaPlugin doPrimitive: #primitiveDivArrays.
primDivScalar:and:into:
^ KedamaPlugin doPrimitive: #primitiveDivScalar.
primMulArray:and:into:
^ KedamaPlugin doPrimitive: #primitiveMulArrays.
primMulScalar:and:into:
^ KedamaPlugin doPrimitive: #primitiveMulScalar.
primSubArray:and:into:
^ KedamaPlugin doPrimitive: #primitiveSubArrays.
primSubScalar:and:into:
^ KedamaPlugin doPrimitive: #primitiveSubScalar.
RunArray
My instances provide space-efficient storage of data which tends to be constant over long runs of the possible indices. Essentially repeated values are stored singly and then associated with a "run" length that denotes the number of consecutive occurrences of the value.
My two important variables are
runs An array of how many elements are in each run
values An array of what the value is over those elements
The variables lastIndex, lastRun and lastOffset cache the last access
so that streaming through RunArrays is not an N-squared process.
Many complexities of access can be bypassed by using the method
RunArray withStartStopAndValueDo:
,
Answer a new RunArray that is a concatenation of the receiver and
aRunArray.
=
Test if all my elements are equal to those of otherArray
addFirst:
Add value as the first element of the receiver.
addLast:
Add value as the last element of the receiver.
addLast:times:
Add value as the last element of the receiver, the given number of times
at:
Primitive. Assumes receiver is indexable. Answer the value of an
indexable element in the receiver. Fail if the argument index is not an
Integer or is out of bounds. Essential. See Object documentation
whatIsAPrimitive.
at:put:
Set an element of the RunArray
at:setRunOffsetAndValue:
Supply all run information to aBlock.
coalesce
Try to combine adjacent runs
copyFrom:to:
Answer a copy of a subset of the receiver, starting from element at
index start until element at index stop.
copyReplaceFrom:to:with:
Answer a copy of the receiver satisfying the following conditions: If
stop is less than start, then this is an insertion; stop should be exactly
start-1, start = 1 means insert before the first character, start = size+1
means append after last character. Otherwise, this is a replacement; start
and stop have to be within the receiver's bounds.
first
Answer the first element of the receiver
isSelfEvaluating
last
Answer the last element of the receiver
mapValues:
NOTE: only meaningful to an entire set of runs
new
new:
new:withAll:
newFrom:
printOn:
Append a sequence of characters that identify the receiver to aStream.
rangeOf:startingAt:
Answer an interval that gives the range of attr at index position startPos. An empty interval with start value startPos is returned when the attribute attr is not present at position startPos. self size > 0 is assumed, it is the responsibility of the caller to test for emptiness of self.
Note that an attribute may span several adjancent runs.
readFrom:
repeatLast:ifEmpty:
add the last value back again, the given number of times. If we are empty, add (defaultBlock value)
repeatLastIfEmpty:
add the last value back again. If we are empty, add (defaultBlock value)
reversed
Answer a copy of the receiver with element order reversed.
runLengthAt:
Answer the length remaining in run beginning at index.
runs
runs:values:
runsAndValuesDo:
Evaluate aBlock with run lengths and values from the receiver
runsFrom:to:do:
Evaluate aBlock with all existing runs in the range from start to stop
scanFrom:
setRuns:setValues:
size
Answer how many elements the receiver contains.
storeOn:
Refer to the comment in Object|storeOn:.
values
Answer the values in the receiver.
withStartStopAndValueDo:
writeOn:
Store the array of bits onto the argument, aStream. (leading byte ~= 16r80) identifies this as raw bits (uncompressed). Always store in Big Endian (Mac) byte order. Do the writing at BitBlt speeds. We only intend this for non-pointer arrays. Do nothing if I contain pointers.
writeScanOn:
Write out the format used for text runs in source files. (14 50 312)f1,f1b,f1LInteger +;i
SparseLargeTable
Derivated from Stephan Pair's LargeArray, but to hold a sparse table, in which most of the entries are the same default value, it uses some tricks.
allDefaultValueSubtableAt:
analyzeSpaceSaving
arrayClass
at:
Primitive. Assumes receiver is indexable. Answer the value of an
indexable element in the receiver. Fail if the argument index is not an
Integer or is out of bounds. Essential. See Object documentation
whatIsAPrimitive.
at:put:
Primitive. Assumes receiver is indexable. Store the argument value in
the indexable element of the receiver indicated by index. Fail if the
index is not an Integer or is out of bounds. Or fail if the value is not of
the right type for this kind of collection. Answer the value that was
stored. Essential. See Object documentation whatIsAPrimitive.
base
chunkSize
copyEmpty
Answer a copy of the receiver that contains no elements.
defaultChunkSize
defaultChunkSizeForFiles
findLastNonNilSubTable
initChunkSize:size:arrayClass:base:defaultValue:
new:
new:chunkSize:
new:chunkSize:arrayClass:
new:chunkSize:arrayClass:base:
new:chunkSize:arrayClass:base:defaultValue:
noCheckAt:
noCheckAt:put:
printElementsOn:
The original code used #skip:, but some streams do not support that,
and we don't really need it.
printOn:
Append a sequence of characters that identify the receiver to aStream.
privateSize:
pvtCheckIndex:
similarInstance
similarInstance:
similarSpeciesInstance
similarSpeciesInstance:
size
Answer how many elements the receiver contains.
speciesNew
speciesNew:
storeOn:
Refer to the comment in Object|storeOn:.
zapDefaultOnlyEntries
WordArray
WordArrays store 32-bit unsigned Integer values.
*
+
-
/
asWordArray
Answer a WordArray whose elements are the elements of the receiver, in
the same order.
atAllPut:
Fill the receiver with the given value
bobsTest
byteSize
bytesPerElement
Number of bytes in each item. This multiplied by (self size)*8 gives the number of bits stored.
defaultElement
Return the default element of the receiver
primAddArray:and:into:
^ KedamaPlugin doPrimitive: #primitiveAddArrays.
primAddScalar:and:into:
^ KedamaPlugin doPrimitive: #primitiveAddScalar.
primDivArray:and:into:
^ KedamaPlugin doPrimitive: #primitiveDivArrays.
primDivScalar:and:into:
^ KedamaPlugin doPrimitive: #primitiveDivScalar.
primMulArray:and:into:
^ KedamaPlugin doPrimitive: #primitiveMulArrays.
primMulScalar:and:into:
^ KedamaPlugin doPrimitive: #primitiveMulScalar.
primSubArray:and:into:
^ KedamaPlugin doPrimitive: #primitiveSubArrays.
primSubScalar:and:into:
^ KedamaPlugin doPrimitive: #primitiveSubScalar.
replaceFrom:to:with:startingAt:
This destructively replaces elements from start to stop in the receiver
starting at index, repStart, in the sequenceable collection,
replacementCollection. Answer the receiver. No range checks are
performed.
WordArrayForSegment
A WordArrayForSegment is xxxxxxxxx.
Instance Variables
restoreEndianness
This word object was just read in from a stream. Do not correct the Endianness because the load primitive will reverse bytes as needed.
writeOn:
Write quickly and disregard the endianness of the words. Store the array of bits onto the argument, aStream. (leading byte ~= 16r80) identifies this as raw bits (uncompressed).