File Misc.str
Version 1.0


This file contains various functions that are used by a variety of other stream components.


Component Summary
int->int Saturation
          Saturates a stream of integers, forcing them to lie within a specified range.
int->int BoundedSaturation
          Saturates a stream of integers known to lie within some larger range, forcing them to lie within a specified range.
int->int DivideBy
          Divide every value in the stream by a given number, truncating to the nearest integer.

Component Detail

Saturation

int->int Saturation(int min, int max)
Saturates a stream of integers, forcing them to lie within a specified range. Values greater than the maximum are saturated to have the max value, and values less than the minimum are saturated to have the minimum value.

Input:
<int> - A stream of integers.
Output:
<int> - A stream of integers lying between min and max, inclusive.
Parameters:
min - The minimum value any integer in the stream is allowed to assume.
max - The maximum value any integer in the stream is allowed to assume.

BoundedSaturation

int->int BoundedSaturation(int min, int max, int worst_input_min, int worst_input_max)
Saturates a stream of integers known to lie within some larger range, forcing them to lie within a specified range. Values greater than the maximum are saturated to have the max value, and values less than the minimum are saturated to have the minimum value. If a value lies outside of the great range behavior is undefined. The BoundedSaturation, without the initialization cost, is roughly twice as fast as the regular Saturation.

Input:
<int> - A stream of integers.
Output:
<int> - A stream of integers lying between min and max, inclusive.
Parameters:
min - The minimum value any integer in the stream is allowed to assume.
max - The maximum value any integer in the stream is allowed to assume.
worst_input_min - The absolute minimum value any input could ever take on.
worst_input_max - The absolute maximum value any input could ever take on.

DivideBy

int->int DivideBy(int div)
Divide every value in the stream by a given number, truncating to the nearest integer.

Input:
<int> - An integer
Output:
<int> - An integer related to the input by output = floor(input / div)
Parameters:
div - The denominator in the division.

Please contact the author (Matthew Drake) for more information.