unit Myc.Data.Records; interface uses System.SysUtils, 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) private FFields: TArray>; // IKeywordMapping implementation function GetItems(Idx: Integer): TPair; function GetFields(const Key: IKeyword): TDataValue; function GetCount: Integer; public constructor Create(const AFields: TArray>); function IndexOf(const Key: IKeyword): Integer; end; implementation { TDynamicRecord } constructor TDynamicRecord.Create(const AFields: TArray>); begin inherited Create; FFields := AFields; end; function TDynamicRecord.GetCount: Integer; begin Result := Length(FFields); end; function TDynamicRecord.GetFields(const Key: IKeyword): TDataValue; var idx: Integer; begin idx := IndexOf(Key); if idx < 0 then raise EArgumentException.CreateFmt('Field "%s" not found in dynamic record.', [Key.Name]); Result := FFields[idx].Value; end; function TDynamicRecord.GetItems(Idx: Integer): TPair; begin Result := FFields[Idx]; end; function TDynamicRecord.IndexOf(const Key: IKeyword): Integer; var i: Integer; begin // Linear search (O(n)). Fast enough for typical records. // Keyword comparison is integer-based (Idx), so this is efficient. for i := 0 to High(FFields) do begin if FFields[i].Key.Idx = Key.Idx then begin Result := i; exit; end; end; Result := -1; end; end.