Ast development

This commit is contained in:
Michael Schimmel
2025-09-02 17:49:30 +02:00
parent a83bbf4f54
commit eb7902d9e8
7 changed files with 257 additions and 83 deletions
+22 -27
View File
@@ -160,17 +160,21 @@ type
end;
TScalarMemberSeries = record
strict private
FKind: TScalarKind;
private
FDef: TScalarRecordDefinition;
FArray: TChunkArray<TScalarValue>;
FElement: Integer;
function GetCount: Int64; inline;
function GetItems(Idx: Integer): TScalarValue;
function GetItems(Idx: Integer): TScalar;
public
constructor Create(const ADef: TScalarRecordDefinition; const AArray: TChunkArray<TScalarValue>; AElement: Integer);
function GetKind: TScalarKind; inline;
property Count: Int64 read GetCount;
property Element: Integer read FElement;
property Items[Idx: Integer]: TScalarValue read GetItems; default;
property Items[Idx: Integer]: TScalar read GetItems; default;
property Kind: TScalarKind read GetKind;
end;
// A time series of scalar records, optimized for memory and access speed.
@@ -423,23 +427,13 @@ end;
function TScalarRecord.GetItems(const Name: String): TScalar;
var
i: Integer;
fieldDef: TScalarRecordField;
idx: Integer;
begin
// Find the index of the field by name (case-insensitive)
for i := 0 to High(FDef.Fields) do
begin
fieldDef := FDef.Fields[i];
if (CompareText(fieldDef.Name, Name) = 0) then
begin
// Found it. Construct the TScalar result from the kind and value.
Result.Create(fieldDef.Kind, FFields[i]);
exit;
end;
end;
idx := FDef.IndexOf(Name);
if idx < 0 then
raise EArgumentException.CreateFmt('Field "%s" not found in record definition.', [Name]);
// If we get here, the field was not found.
raise EArgumentException.CreateFmt('Field "%s" not found in record definition.', [Name]);
Result.Create(FDef.Fields[idx].Kind, FFields[idx]);
end;
{ TScalarSeries }
@@ -513,17 +507,20 @@ end;
function TScalarMemberSeries.GetCount: Int64;
begin
Result := FArray.Count;
Result := FArray.Count div Length(FDef.Fields);
end;
function TScalarMemberSeries.GetItems(Idx: Integer): TScalarValue;
function TScalarMemberSeries.GetItems(Idx: Integer): TScalar;
var
values: TArray<TScalarValue>;
fieldCount: Integer;
begin
fieldCount := Length(FDef.Fields);
SetLength(values, fieldCount);
Result := FArray.ItemRef[(FArray.Count - fieldCount) - (Idx * fieldCount)]^;
Result.Create(FDef.Fields[FElement].Kind, FArray.Items[(FArray.Count - fieldCount) - (Idx * fieldCount) + FElement]);
end;
function TScalarMemberSeries.GetKind: TScalarKind;
begin
Result := FDef.Fields[FElement].Kind;
end;
constructor TScalarRecordDefinition.Create(const AFields: TArray<TScalarRecordField>);
@@ -534,15 +531,13 @@ end;
function TScalarRecordDefinition.IndexOf(const Name: String): Integer;
var
i: Integer;
fieldDef: TScalarRecordField;
begin
// Find the index of the field by name (case-insensitive)
for i := 0 to High(FFields) do
begin
if (CompareText(FFields[i].Name, Name) = 0) then
exit(i);
// If we get here, the field was not found.
raise EArgumentException.CreateFmt('Field "%s" not found in record definition.', [Name]);
end;
Result := -1;
end;
initialization