From bac4df0e24a6af674ab87f46542b8bce3fc3c00a Mon Sep 17 00:00:00 2001 From: skycurtain Date: Tue, 21 Oct 2025 17:05:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E8=AE=A1tracer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tracers.ts/index.ts | 102 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/tracers.ts/index.ts diff --git a/src/tracers.ts/index.ts b/src/tracers.ts/index.ts new file mode 100644 index 0000000..7995091 --- /dev/null +++ b/src/tracers.ts/index.ts @@ -0,0 +1,102 @@ +const TracerType = { + ArrayTracer: 'ArrayTracer', + StackTracer: 'StackTracer', + QueueTracer: 'QueueTracer', + MatrixTracer: 'MatrixTracer', + SortTracer: 'SortTracer', + LinkTracer: 'LinkTracer', + TreeTracer: 'TreeTracer', + GraphTracer: 'GraphTracer', +} as const; + +type TracerTypeKey = keyof typeof TracerType; + +type TracerTypeVal = (typeof TracerType)[TracerTypeKey]; + +const Action = { + Define: 'define', + + Preset: 'preset', + Expand: 'expand', + Reduce: 'reduce', + Pick: 'pick', + Drop: 'drop', + Patch: 'patch', + Reset: 'reset', +} as const; + +type ActionKey = keyof typeof Action; + +type ActionVal = (typeof Action)[ActionKey]; + +class TracerRegistry { + private tracers: Record; + + private constructor() { + this.tracers = { + ArrayTracer: [], + StackTracer: [], + QueueTracer: [], + MatrixTracer: [], + SortTracer: [], + LinkTracer: [], + TreeTracer: [], + GraphTracer: [], + }; + } + + public register(tracerType: TracerTypeVal, tracerId: string) { + this.tracers[tracerType].push(tracerId); + } +} + +interface Command { + tracer: string; + action: ActionVal; + params: any; +} + +class Commander { + private commands: Command[]; + + private constructor() { + this.commands = []; + } + + public static command() {} + + public static serialize() {} +} + +export interface ArrayTracerOption { + description: string; + serializeFn?: (value: T) => string; +} + +export class ArrayTracer { + private tracerId: string; + private serializeFn?: (value: T) => string; + + private constructor(option: ArrayTracerOption) { + this.tracerId = crypto.randomUUID(); + this.serializeFn = option.serializeFn; + } + + public static define(option: ArrayTracerOption): ArrayTracer { + return new ArrayTracer(option); + } + + public preset(array: T[]) {} + + public expand(size: number) {} + + public reduce(size: number) {} + + public pick(index: number) {} + + public drop(index: number) {} + + public patch(index: number, value: T) {} + + public reset(index: number) {} +}