Squeak Class Documentation category index | class index  
 
RunArray
  category: Collections-Arrayed
  superclass: ArrayedCollection
  subclasses:

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:

instance methods
  accessing
  =
at:
first
last
runLengthAt:
size
withStartStopAndValueDo:

  adding
  addFirst:
addLast:
addLast:times:
coalesce
repeatLast:ifEmpty:
repeatLastIfEmpty:

  copying
  ,
copyFrom:to:
copyReplaceFrom:to:with:

  enumerating
  runsAndValuesDo:

  printing
  printOn:
storeOn:
writeOn:
writeScanOn:

  private
  at:setRunOffsetAndValue:
mapValues:
runs
setRuns:setValues:
values

class methods
  instance creation
  new
new:withAll:
newFrom:
readFrom:
runs:values:
scanFrom:

instance methods
  accessing top  
 

=

Test if all my elements are equal to those of otherArray


 

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.


 

first

Answer the first element of the receiver.
Raise an error if the collection is empty.


 

last

Answer the last element of the receiver.
Raise an error if the collection is empty.


 

runLengthAt:

Answer the length remaining in run beginning at index.


 

size

Answer how many elements the receiver contains.


 

withStartStopAndValueDo:


  adding top  
 

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


 

coalesce

Try to combine adjacent runs


 

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)


  copying top  
 

,

Answer a new RunArray that is a concatenation of the receiver and
aRunArray.


 

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.


  enumerating top  
 

runsAndValuesDo:

Evaluate aBlock with run lengths and values from the receiver


  printing top  
 

printOn:

Append a sequence of characters that identify the receiver to aStream.


 

storeOn:

Refer to the comment in Object|storeOn:.


 

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


  private top  
 

at:setRunOffsetAndValue:

Supply all run information to aBlock.


 

mapValues:

NOTE: only meaningful to an entire set of runs


 

runs


 

setRuns:setValues:


 

values

Answer the values in the receiver.


class methods
  instance creation top  
 

new

Answer a new instance of me, with size = 0.


 

new:withAll:

Answer a new instance of me, whose every element is equal to the
argument, value.


 

newFrom:

Answer an instance of me containing the same elements as aCollection.


 

readFrom:

Answer an instance of me as described on the stream, aStream.


 

runs:values:

Answer an instance of me with runs and values specified by the
arguments.


 

scanFrom:

Read the style section of a fileOut or sources file. nextChunk has already been done. We need to return a RunArray of TextAttributes of various kinds.