From 4b105f49d0404bfa90e9fcd1e45054c163b4c6f0 Mon Sep 17 00:00:00 2001 From: Xie Yuheng Date: Wed, 16 Aug 2023 16:56:12 +0800 Subject: [PATCH] ambr NodePortRecord PortRecord --- TODO.md | 4 +++- src/lang/connect/connect.ts | 10 +++++----- src/lang/freshen/refreshNode.ts | 4 ++-- src/lang/interact/interact.ts | 6 +++--- .../{deleteNodePortRecord.ts => deletePortRecord.ts} | 2 +- ...NodePortRecordOrFail.ts => findPortRecordOrFail.ts} | 2 +- src/lang/net/nodeInputPorts.ts | 4 ++-- src/lang/net/nodeOutputPorts.ts | 4 ++-- 8 files changed, 19 insertions(+), 17 deletions(-) rename src/lang/net/{deleteNodePortRecord.ts => deletePortRecord.ts} (69%) rename src/lang/net/{findNodePortRecordOrFail.ts => findPortRecordOrFail.ts} (85%) diff --git a/TODO.md b/TODO.md index f84798f8..c099f97d 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,8 @@ # net -`nodeInputPorts` & `nodeOutputPorts` return `Record` instead of `Array` +`nodeInputPortRecord` & `nodeOutputPortRecord` return `Record` + +`rearrangeNodePorts` use record # connected component diff --git a/src/lang/connect/connect.ts b/src/lang/connect/connect.ts index 2e3e9e82..154a842b 100644 --- a/src/lang/connect/connect.ts +++ b/src/lang/connect/connect.ts @@ -1,7 +1,7 @@ import { checkPortSigns } from "../check/checkPortSigns" import { Net } from "../net" -import { findNodePortRecordOrFail } from "../net/findNodePortRecordOrFail" import { findPortEntry } from "../net/findPortEntry" +import { findPortRecordOrFail } from "../net/findPortRecordOrFail" import { Port } from "../port" import { formatValue } from "../value/formatValue" @@ -32,11 +32,11 @@ export function connect(net: Net, first: Port, second: Port): void { const edge = { first, second } - const firstNodePortRecord = findNodePortRecordOrFail(net, first.node) - firstNodePortRecord[first.name].connection = { edge, port: second } + const firstPortRecord = findPortRecordOrFail(net, first.node) + firstPortRecord[first.name].connection = { edge, port: second } - const secondNodePortRecord = findNodePortRecordOrFail(net, second.node) - secondNodePortRecord[second.name].connection = { edge, port: first } + const secondPortRecord = findPortRecordOrFail(net, second.node) + secondPortRecord[second.name].connection = { edge, port: first } if (first.isPrincipal && second.isPrincipal) { net.activeEdges.push(edge) diff --git a/src/lang/freshen/refreshNode.ts b/src/lang/freshen/refreshNode.ts index 7be3a779..d72fe9af 100644 --- a/src/lang/freshen/refreshNode.ts +++ b/src/lang/freshen/refreshNode.ts @@ -1,5 +1,5 @@ import { Net } from "../net" -import { findNodePortRecordOrFail } from "../net/findNodePortRecordOrFail" +import { findPortRecordOrFail } from "../net/findPortRecordOrFail" import { Node } from "../node" import { freshenType } from "./freshenType" @@ -19,7 +19,7 @@ export function refreshNode( ): void { const occurredNames = new Map() - const portRecord = findNodePortRecordOrFail(net, node) + const portRecord = findPortRecordOrFail(net, node) for (const portEntry of Object.values(portRecord)) { portEntry.t = freshenType(typeVarCounters, portEntry.t, occurredNames) } diff --git a/src/lang/interact/interact.ts b/src/lang/interact/interact.ts index b4d367a6..cfe37a78 100644 --- a/src/lang/interact/interact.ts +++ b/src/lang/interact/interact.ts @@ -4,7 +4,7 @@ import { Edge } from "../edge" import { Env } from "../env" import { lookupRuleByPorts } from "../mod/lookupRuleByPorts" import { deleteEdgesOfNode } from "../net/deleteEdgesOfNode" -import { deleteNodePortRecord } from "../net/deleteNodePortRecord" +import { deletePortRecord } from "../net/deletePortRecord" export type InteractOptions = { checking?: Checking @@ -31,6 +31,6 @@ export function interact( }) } - deleteNodePortRecord(env.net, activeEdge.first.node) - deleteNodePortRecord(env.net, activeEdge.second.node) + deletePortRecord(env.net, activeEdge.first.node) + deletePortRecord(env.net, activeEdge.second.node) } diff --git a/src/lang/net/deleteNodePortRecord.ts b/src/lang/net/deletePortRecord.ts similarity index 69% rename from src/lang/net/deleteNodePortRecord.ts rename to src/lang/net/deletePortRecord.ts index 2cfec429..9f43ea15 100644 --- a/src/lang/net/deleteNodePortRecord.ts +++ b/src/lang/net/deletePortRecord.ts @@ -2,6 +2,6 @@ import { Node } from "../node" import { nodeKeyId } from "../node/nodeKeyId" import { Net } from "./Net" -export function deleteNodePortRecord(net: Net, node: Node): void { +export function deletePortRecord(net: Net, node: Node): void { net.nodePortRecords.delete(nodeKeyId(node)) } diff --git a/src/lang/net/findNodePortRecordOrFail.ts b/src/lang/net/findPortRecordOrFail.ts similarity index 85% rename from src/lang/net/findNodePortRecordOrFail.ts rename to src/lang/net/findPortRecordOrFail.ts index d55ce62a..35bcfe98 100644 --- a/src/lang/net/findNodePortRecordOrFail.ts +++ b/src/lang/net/findPortRecordOrFail.ts @@ -3,7 +3,7 @@ import { formatNode } from "../node/formatNode" import { nodeKeyId } from "../node/nodeKeyId" import { Net, PortRecord } from "./Net" -export function findNodePortRecordOrFail(net: Net, node: Node): PortRecord { +export function findPortRecordOrFail(net: Net, node: Node): PortRecord { let ports = net.nodePortRecords.get(nodeKeyId(node)) if (ports === undefined) { throw new Error( diff --git a/src/lang/net/nodeInputPorts.ts b/src/lang/net/nodeInputPorts.ts index 7f81e130..6be1d76e 100644 --- a/src/lang/net/nodeInputPorts.ts +++ b/src/lang/net/nodeInputPorts.ts @@ -1,10 +1,10 @@ import { Node } from "../node" import { Port } from "../port" import { Net } from "./Net" -import { findNodePortRecordOrFail } from "./findNodePortRecordOrFail" +import { findPortRecordOrFail } from "./findPortRecordOrFail" export function nodeInputPorts(net: Net, node: Node): Array { - const portRecord = findNodePortRecordOrFail(net, node) + const portRecord = findPortRecordOrFail(net, node) return Object.values(portRecord) .filter(({ sign }) => sign === -1) .map((portEntry) => ({ diff --git a/src/lang/net/nodeOutputPorts.ts b/src/lang/net/nodeOutputPorts.ts index b0443239..06920132 100644 --- a/src/lang/net/nodeOutputPorts.ts +++ b/src/lang/net/nodeOutputPorts.ts @@ -1,10 +1,10 @@ import { Node } from "../node" import { Port } from "../port" import { Net } from "./Net" -import { findNodePortRecordOrFail } from "./findNodePortRecordOrFail" +import { findPortRecordOrFail } from "./findPortRecordOrFail" export function nodeOutputPorts(net: Net, node: Node): Array { - const portRecord = findNodePortRecordOrFail(net, node) + const portRecord = findPortRecordOrFail(net, node) return Object.values(portRecord) .filter(({ sign }) => sign === 1) .map((portEntry) => ({