The OpenD Programming Language

unionSeries

Merges multiple (time) series into one. Makes exactly one memory allocation for two series union and two memory allocation for three and more series union.

Return Value

Type: auto

sorted GC-allocated series. See_also Series.opBinary makeUnionSeries

Examples

import mir.date: Date;

//////////////////////////////////////
// Constructs two time-series.
//////////////////////////////////////
auto index0 = [1,3,4];
auto data0 = [1.0, 3, 4];
auto series0 = index0.series(data0);

auto index1 = [1,2,5];
auto data1 = [10.0, 20, 50];
auto series1 = index1.series(data1);

//////////////////////////////////////
// Merges multiple series into one.
//////////////////////////////////////
// Order is matter.
// The first slice has higher priority.
auto m0 = unionSeries(series0, series1);
auto m1 = unionSeries(series1, series0);

assert(m0.index == m1.index);
assert(m0.data == [ 1, 20,  3,  4, 50]);
assert(m1.data == [10, 20,  3,  4, 50]);
import mir.date: Date;

//////////////////////////////////////
// Constructs three time-series.
//////////////////////////////////////
auto index0 = [1,3,4];
auto data0 = [1.0, 3, 4];
auto series0 = index0.series(data0);

auto index1 = [1,2,5];
auto data1 = [10.0, 20, 50];
auto series1 = index1.series(data1);

auto index2 = [1, 6];
auto data2 = [100.0, 600];
auto series2 = index2.series(data2);

//////////////////////////////////////
// Merges multiple series into one.
//////////////////////////////////////
// Order is matter.
// The first slice has higher priority.
auto m0 = unionSeries(series0, series1, series2);
auto m1 = unionSeries(series1, series0, series2);
auto m2 = unionSeries(series2, series0, series1);

assert(m0.index == m1.index);
assert(m0.index == m2.index);
assert(m0.data == [  1, 20,  3,  4, 50, 600]);
assert(m1.data == [ 10, 20,  3,  4, 50, 600]);
assert(m2.data == [100, 20,  3,  4, 50, 600]);

Meta