Data pipeline refactoring
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1083,7 +1083,7 @@ procedure TForm1.SeriesTestButtonClick(Sender: TObject);
|
|||||||
var
|
var
|
||||||
ast: IAstNode;
|
ast: IAstNode;
|
||||||
resultValue: TDataValue;
|
resultValue: TDataValue;
|
||||||
series: TScalarRecordSeries;
|
series: IWriteableScalarRecordSeries;
|
||||||
recordDef: IScalarRecordDefinition;
|
recordDef: IScalarRecordDefinition;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
values: TArray<TScalar.TValue>;
|
values: TArray<TScalar.TValue>;
|
||||||
|
|||||||
@@ -405,7 +405,7 @@ var
|
|||||||
baseValue, indexValue: TDataValue;
|
baseValue, indexValue: TDataValue;
|
||||||
index: Int64;
|
index: Int64;
|
||||||
series: ISeries;
|
series: ISeries;
|
||||||
recSeries: IRecordSeries;
|
recSeries: IScalarRecordSeries;
|
||||||
i, fieldCount: Integer;
|
i, fieldCount: Integer;
|
||||||
values: TArray<TScalar.TValue>;
|
values: TArray<TScalar.TValue>;
|
||||||
key: IKeyword;
|
key: IKeyword;
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ unit Myc.Data.Pipeline;
|
|||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
{$M+}
|
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Myc.Signals,
|
Myc.Signals,
|
||||||
Myc.Mutable,
|
Myc.Mutable,
|
||||||
@@ -13,12 +11,12 @@ type
|
|||||||
TTag = Pointer;
|
TTag = Pointer;
|
||||||
|
|
||||||
// A generic interface for components that consume data of type T.
|
// A generic interface for components that consume data of type T.
|
||||||
IConsumer<T> = interface
|
IConsumer<T> = interface(IInvokable)
|
||||||
function Consume(const Value: T): TState;
|
function Consume(const Value: T): TState;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// A producer generates data and distributes it to linked consumers.
|
// A producer generates data and distributes it to linked consumers.
|
||||||
IProducer<T> = interface
|
IProducer<T> = interface(IInvokable)
|
||||||
function Link(const Consumer: IConsumer<T>): TTag;
|
function Link(const Consumer: IConsumer<T>): TTag;
|
||||||
procedure Unlink(Tag: TTag);
|
procedure Unlink(Tag: TTag);
|
||||||
end;
|
end;
|
||||||
|
|||||||
@@ -179,23 +179,27 @@ type
|
|||||||
procedure Add(const Item: TScalar.TValue; Lookback: Int64 = -1);
|
procedure Add(const Item: TScalar.TValue; Lookback: Int64 = -1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
IRecordSeries = interface
|
IScalarRecordSeries = interface
|
||||||
{$region 'private'}
|
{$region 'private'}
|
||||||
function GetCount: Int64;
|
function GetCount: Int64;
|
||||||
function GetDef: IScalarRecordDefinition;
|
function GetDef: IScalarRecordDefinition;
|
||||||
function GetTotalCount: Int64;
|
|
||||||
function GetFields(const Key: IKeyword): ISeries;
|
function GetFields(const Key: IKeyword): ISeries;
|
||||||
|
function GetTotalCount: Int64;
|
||||||
{$endregion}
|
{$endregion}
|
||||||
procedure Add(const Item: IScalarRecord; Lookback: Int64 = -1);
|
|
||||||
procedure AddRaw(const Data; Lookback: Int64 = -1);
|
|
||||||
property Count: Int64 read GetCount;
|
property Count: Int64 read GetCount;
|
||||||
property Def: IScalarRecordDefinition read GetDef;
|
property Def: IScalarRecordDefinition read GetDef;
|
||||||
property Fields[const Key: IKeyword]: ISeries read GetFields; default;
|
property Fields[const Key: IKeyword]: ISeries read GetFields; default;
|
||||||
property TotalCount: Int64 read GetTotalCount;
|
property TotalCount: Int64 read GetTotalCount;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
IWriteableScalarRecordSeries = interface(IScalarRecordSeries)
|
||||||
|
{$region 'private'}
|
||||||
|
{$endregion}
|
||||||
|
procedure Add(const Item: IScalarRecord; Lookback: Int64 = -1);
|
||||||
|
end;
|
||||||
|
|
||||||
// A series of scalar records, optimized for memory and access speed.
|
// A series of scalar records, optimized for memory and access speed.
|
||||||
TScalarRecordSeries = class(TInterfacedObject, IRecordSeries)
|
TScalarRecordSeries = class(TInterfacedObject, IWriteableScalarRecordSeries)
|
||||||
type
|
type
|
||||||
TMemberSeries = class(TGenericContainedObject<TScalarRecordSeries>, ISeries)
|
TMemberSeries = class(TGenericContainedObject<TScalarRecordSeries>, ISeries)
|
||||||
private
|
private
|
||||||
@@ -222,10 +226,8 @@ type
|
|||||||
public
|
public
|
||||||
constructor Create(const ADef: IScalarRecordDefinition);
|
constructor Create(const ADef: IScalarRecordDefinition);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure Add(const Item: IScalarRecord; Lookback: Int64 = -1);
|
|
||||||
|
|
||||||
// Copies data directly from the Data reference (zero-copy wrapper)
|
procedure Add(const Item: IScalarRecord; Lookback: Int64 = -1);
|
||||||
procedure AddRaw(const Data; Lookback: Int64 = -1);
|
|
||||||
|
|
||||||
property Count: Int64 read GetCount;
|
property Count: Int64 read GetCount;
|
||||||
property Fields[const Key: IKeyword]: ISeries read GetFields; default;
|
property Fields[const Key: IKeyword]: ISeries read GetFields; default;
|
||||||
@@ -809,18 +811,6 @@ begin
|
|||||||
inc(FTotalCount);
|
inc(FTotalCount);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TScalarRecordSeries.AddRaw(const Data; Lookback: Int64 = -1);
|
|
||||||
begin
|
|
||||||
var lb := FDef.Count * Integer(Lookback);
|
|
||||||
var P: TScalar.PValue := @Data;
|
|
||||||
for var i := 0 to FDef.Count - 1 do
|
|
||||||
begin
|
|
||||||
FArray.Add(P^, lb);
|
|
||||||
inc(P);
|
|
||||||
end;
|
|
||||||
inc(FTotalCount);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TScalarRecordSeries.GetFields(const Key: IKeyword): ISeries;
|
function TScalarRecordSeries.GetFields(const Key: IKeyword): ISeries;
|
||||||
begin
|
begin
|
||||||
var elem := FDef.IndexOf(Key);
|
var elem := FDef.IndexOf(Key);
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ type
|
|||||||
|
|
||||||
class function Map(const SourceSeries: ISeries; const MapperFunc: TFunc): ISeries; static;
|
class function Map(const SourceSeries: ISeries; const MapperFunc: TFunc): ISeries; static;
|
||||||
|
|
||||||
class function FromRecordSeries(const AValue: IRecordSeries): TDataValue; static; inline;
|
class function FromRecordSeries(const AValue: IWriteableScalarRecordSeries): TDataValue; static; inline;
|
||||||
class function FromScalarRecord(const AValue: IScalarRecord): TDataValue; static; inline;
|
class function FromScalarRecord(const AValue: IScalarRecord): TDataValue; static; inline;
|
||||||
class function FromGenericRecord(const AValue: IKeywordMapping<TDataValue>): TDataValue; static; inline;
|
class function FromGenericRecord(const AValue: IKeywordMapping<TDataValue>): TDataValue; static; inline;
|
||||||
class function FromSeries(const AValue: ISeries): TDataValue; static; inline;
|
class function FromSeries(const AValue: ISeries): TDataValue; static; inline;
|
||||||
@@ -86,7 +86,7 @@ type
|
|||||||
function AsScalar: TScalar; inline;
|
function AsScalar: TScalar; inline;
|
||||||
function AsMethod: TFunc; inline;
|
function AsMethod: TFunc; inline;
|
||||||
function AsText: String; inline;
|
function AsText: String; inline;
|
||||||
function AsRecordSeries: IRecordSeries; inline;
|
function AsRecordSeries: IWriteableScalarRecordSeries; inline;
|
||||||
function AsScalarRecord: IScalarRecord; inline;
|
function AsScalarRecord: IScalarRecord; inline;
|
||||||
function AsGenericRecord: IKeywordMapping<TDataValue>; inline;
|
function AsGenericRecord: IKeywordMapping<TDataValue>; inline;
|
||||||
function AsSeries: ISeries; inline;
|
function AsSeries: ISeries; inline;
|
||||||
@@ -205,11 +205,11 @@ begin
|
|||||||
Result := IKeywordMapping<TDataValue>(FInterface);
|
Result := IKeywordMapping<TDataValue>(FInterface);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TDataValue.AsRecordSeries: IRecordSeries;
|
function TDataValue.AsRecordSeries: IWriteableScalarRecordSeries;
|
||||||
begin
|
begin
|
||||||
if (FKind <> vkRecordSeries) then
|
if (FKind <> vkRecordSeries) then
|
||||||
raise EInvalidCast.Create('Cannot read value as RecordSeries.');
|
raise EInvalidCast.Create('Cannot read value as RecordSeries.');
|
||||||
Result := IRecordSeries(FInterface);
|
Result := IWriteableScalarRecordSeries(FInterface);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TDataValue.AsScalar: TScalar;
|
function TDataValue.AsScalar: TScalar;
|
||||||
@@ -266,7 +266,7 @@ begin
|
|||||||
Result.FInterface := AValue;
|
Result.FInterface := AValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TDataValue.FromRecordSeries(const AValue: IRecordSeries): TDataValue;
|
class function TDataValue.FromRecordSeries(const AValue: IWriteableScalarRecordSeries): TDataValue;
|
||||||
begin
|
begin
|
||||||
Result.FKind := vkRecordSeries;
|
Result.FKind := vkRecordSeries;
|
||||||
Result.FInterface := AValue;
|
Result.FInterface := AValue;
|
||||||
|
|||||||
Reference in New Issue
Block a user