Numeric sequences v0.1.0
PartialSum<T>
pub func PartialSum<T>(
items: T[..],
into: var T[..]
) -> bool
Writes the running sums of items into into: element i becomes the sum of the first i + 1 elements.
into may be items itself. Requires + on the element type, with whatever overflow it has.
Runs in time proportional to the length and allocates nothing.
Type parameters
| Name | Description |
|---|---|
T | the element type |
Parameters
| Name | Type | Description |
|---|---|---|
items | T[..] | the sequence to sum |
into | var T[..] | where the sums go, at least as long as items |
Returns: whether into was long enough; nothing is written when it was not
InclusiveScan<T>
pub func InclusiveScan<T>(
items: T[..],
into: var T[..],
combine: func(T, T) -> T
) -> bool
Writes the running combination of items into into: element i becomes the first i + 1 elements combined
left to right with combine. PartialSum is this scan with +.
into may be items itself.
Runs in time proportional to the length and allocates nothing beyond whatever combine does.
Type parameters
| Name | Description |
|---|---|
T | the element type |
Parameters
| Name | Type | Description |
|---|---|---|
items | T[..] | the sequence to scan |
into | var T[..] | where the results go, at least as long as items |
combine | func(T, T) -> T | how two values combine |
Returns: whether into was long enough; nothing is written when it was not
ExclusiveScan<T>
pub func ExclusiveScan<T>(
items: T[..],
into: var T[..],
initial: T,
combine: func(T, T) -> T
) -> bool
Writes the running combination of items before each element into into: element i becomes initial
combined with the first i elements, so the first result is initial and the last element of items takes part
in none.
into may be items itself.
Runs in time proportional to the length and allocates nothing beyond whatever combine does.
Type parameters
| Name | Description |
|---|---|
T | the element type |
Parameters
| Name | Type | Description |
|---|---|---|
items | T[..] | the sequence to scan |
into | var T[..] | where the results go, at least as long as items |
initial | T | the value before anything is combined |
combine | func(T, T) -> T | how two values combine |
Returns: whether into was long enough; nothing is written when it was not
Iota<T>
pub func Iota<T>(into: var T[..], start: T, step: T)
Fills into with start, start + step, start + 2 * step and so on.
Requires + on the element type, with whatever overflow it has.
Runs in time proportional to the length and allocates nothing.
Type parameters
| Name | Description |
|---|---|
T | the element type |
Parameters
| Name | Type | Description |
|---|---|---|
into | var T[..] | the sequence to fill |
start | T | the first value |
step | T | what each value adds to the one before |
Midpoint
pub func Midpoint(a: int64, b: int64) -> int64
pub func Midpoint(a: int32, b: int32) -> int32
pub func Midpoint(a: uint64, b: uint64) -> uint64
pub func Midpoint(a: uint32, b: uint32) -> uint32
pub func Midpoint(a: float64, b: float64) -> float64
Halfway between a and b, without overflowing to infinity when both are near the largest finite value.
| Overload | Summary |
|---|---|
pub func Midpoint(a: int64, b: int64) -> int64 | Halfway between a and b, rounded toward a, without overflowing however far apart they are. |
pub func Midpoint(a: int32, b: int32) -> int32 | Halfway between a and b, rounded toward a, without overflowing however far apart they are. |
pub func Midpoint(a: uint64, b: uint64) -> uint64 | Halfway between a and b, rounded toward a, without overflowing however far apart they are. |
pub func Midpoint(a: uint32, b: uint32) -> uint32 | Halfway between a and b, rounded toward a, without overflowing however far apart they are. |
pub func Midpoint(a: float64, b: float64) -> float64 | Halfway between a and b, without overflowing to infinity when both are near the largest finite value. |
Parameters
| Name | Type | Description |
|---|---|---|
a | int64 / int32 / uint64 / uint32 / float64 | one end |
b | int64 / int32 / uint64 / uint32 / float64 | the other end |
Returns: the midpoint