feat: solution for 'Повторный экзамен: Граф с рефлексией и доработкой'

This commit is contained in:
2026-07-01 14:40:09 +03:00
parent f14d41830d
commit 153b04b33c
10 changed files with 312 additions and 95 deletions
+15
View File
@@ -0,0 +1,15 @@
export abstract class BaseNode {
id: string;
type: string;
inputs: Map<string, any>;
outputs: Map<string, any>;
constructor(id: string, type: string) {
this.id = id;
this.type = type;
this.inputs = new Map();
this.outputs = new Map();
}
abstract process(): void;
}
+14
View File
@@ -0,0 +1,14 @@
import { BaseNode } from './baseNode';
export class ReflectionNode extends BaseNode {
constructor(id: string) {
super(id, 'reflection');
}
process(): void {
// Copy all inputs to outputs with the same keys
this.inputs.forEach((value, key) => {
this.outputs.set(key, value);
});
}
}
+19
View File
@@ -0,0 +1,19 @@
import { BaseNode } from './baseNode';
export type RewriteFunction = (value: any) => any;
export class RewriteNode extends BaseNode {
private func: RewriteFunction;
constructor(id: string, func: RewriteFunction) {
super(id, 'rewrite');
this.func = func;
}
process(): void {
this.inputs.forEach((value, key) => {
const newValue = this.func(value);
this.outputs.set(key, newValue);
});
}
}