Files
MycLib/Src/Data/Myc.Data.Records.pas
T
Michael Schimmel 7aa0056799 Renaming
2025-12-08 10:54:22 +01:00

49 lines
1.3 KiB
ObjectPascal

unit Myc.Data.Records;
interface
uses
System.Generics.Collections,
Myc.Data.Keyword,
Myc.Data.Value;
type
// Runtime implementation for generic records using linear search (optimized for small record sizes)
TDynamicRecord = class(TInterfacedObject, IKeywordMapping<TDataValue>)
private
FFields: TArray<TPair<IKeyword, TDataValue>>;
function GetFields: TArray<TPair<IKeyword, TDataValue>>;
public
constructor Create(const AFields: TArray<TPair<IKeyword, TDataValue>>);
function IndexOf(const Key: IKeyword): Integer;
end;
implementation
{ TDynamicRecord }
constructor TDynamicRecord.Create(const AFields: TArray<TPair<IKeyword, TDataValue>>);
begin
inherited Create;
FFields := AFields;
end;
function TDynamicRecord.GetFields: TArray<TPair<IKeyword, TDataValue>>;
begin
Result := FFields;
end;
function TDynamicRecord.IndexOf(const Key: IKeyword): Integer;
begin
// Linear search (O(n)). Fast enough for typical records.
// Keyword comparison is integer-based (Idx), so this is efficient.
for Result := 0 to High(FFields) do
begin
if FFields[Result].Key.Idx = Key.Idx then
exit;
end;
Result := -1;
end;
end.