feat: add flat_tree allgorithm
This commit is contained in:
@ -1,27 +1,29 @@
|
||||
<script lang="ts">
|
||||
import Grid from "$lib/grid";
|
||||
import Graph from "@nodes/graph-interface";
|
||||
import GraphInterface from "@nodes/graph-interface";
|
||||
import { MemoryRuntimeExecutor } from "$lib/runtime-executor";
|
||||
import { MemoryNodeRegistry, RemoteNodeRegistry } from "$lib/node-registry";
|
||||
import * as templates from "$lib/graph-templates";
|
||||
import type { Graph } from "@nodes/types";
|
||||
|
||||
const memNodeRegistry = new MemoryNodeRegistry();
|
||||
const nodeRegistry = new RemoteNodeRegistry("http://localhost:3001");
|
||||
const runtimeExecutor = new MemoryRuntimeExecutor(nodeRegistry);
|
||||
|
||||
let res = 0;
|
||||
let res = "2";
|
||||
let time = 0;
|
||||
|
||||
let graph = localStorage.getItem("graph")
|
||||
? JSON.parse(localStorage.getItem("graph")!)
|
||||
: templates.grid(3, 3);
|
||||
|
||||
function handleResult(event) {
|
||||
console.log("Res", event);
|
||||
function handleResult(event: CustomEvent<Graph>) {
|
||||
let a = performance.now();
|
||||
res = runtimeExecutor.execute(event.detail);
|
||||
time = performance.now() - a;
|
||||
console.log(res);
|
||||
}
|
||||
|
||||
function handleSave(event) {
|
||||
function handleSave(event: CustomEvent<Graph>) {
|
||||
localStorage.setItem("graph", JSON.stringify(event.detail));
|
||||
}
|
||||
</script>
|
||||
@ -30,11 +32,13 @@
|
||||
<header>header</header>
|
||||
<Grid.Row>
|
||||
<Grid.Cell>
|
||||
{res}
|
||||
result: {res}
|
||||
<br />
|
||||
time: {time}ms
|
||||
</Grid.Cell>
|
||||
<Grid.Cell>
|
||||
{#key graph}
|
||||
<Graph
|
||||
<GraphInterface
|
||||
registry={nodeRegistry}
|
||||
{graph}
|
||||
on:result={handleResult}
|
||||
|
20
app/src/routes/test/+page.svelte
Normal file
20
app/src/routes/test/+page.svelte
Normal file
@ -0,0 +1,20 @@
|
||||
<script lang="ts">
|
||||
import { decode, encode } from "$lib/helpers/flat_tree";
|
||||
|
||||
const input = [5, [6, 1], [7, 2, [5, 1]]];
|
||||
// const input = [5, [], [6, []], []];
|
||||
// const input = [52];
|
||||
|
||||
console.log("INPUT");
|
||||
console.log(input);
|
||||
|
||||
const encoded = encode(input);
|
||||
console.log("ENCODED");
|
||||
console.log(encoded);
|
||||
|
||||
const decoded = decode(encoded);
|
||||
console.log("DECODED");
|
||||
console.log(decoded);
|
||||
|
||||
console.log("EQUALS", JSON.stringify(input) === JSON.stringify(decoded));
|
||||
</script>
|
Reference in New Issue
Block a user