Skip to content

Commit

Permalink
ambr nodeInputPorts findInputPorts
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Aug 16, 2023
1 parent 4b105f4 commit 0eb3c5f
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 28 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# net

`nodeInputPortRecord` & `nodeOutputPortRecord` return `Record`

`rearrangeNodePorts` use record

# connected component
Expand Down
8 changes: 4 additions & 4 deletions src/lang/compose/findCurrentPortOrFail.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Net } from "../net"
import { findInputPorts } from "../net/findInputPorts"
import { findOutputPorts } from "../net/findOutputPorts"
import { findPortEntry } from "../net/findPortEntry"
import { nodeInputPorts } from "../net/nodeInputPorts"
import { nodeOutputPorts } from "../net/nodeOutputPorts"
import { Node } from "../node"
import { Port } from "../port"
import { ComposeOptions } from "./compose"
Expand Down Expand Up @@ -64,14 +64,14 @@ function findPortInNode(
portName: string,
node: Node,
): Port | undefined {
for (const port of nodeInputPorts(net, node)) {
for (const port of findInputPorts(net, node)) {
if (port.name === portName) {
const portEntry = findPortEntry(net, port)
return portEntry?.connection?.port
}
}

for (const port of nodeOutputPorts(net, node)) {
for (const port of findOutputPorts(net, node)) {
if (port.name === portName) {
const portEntry = findPortEntry(net, port)
return portEntry?.connection?.port
Expand Down
8 changes: 4 additions & 4 deletions src/lang/compose/rearrangeNodePorts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { arrayPickOut } from "../../utils/arrayPickOut"
import { countStringOccurrences } from "../../utils/countStringOccurrences"
import { Net } from "../net"
import { nodeInputPorts } from "../net/nodeInputPorts"
import { nodeOutputPorts } from "../net/nodeOutputPorts"
import { findInputPorts } from "../net/findInputPorts"
import { findOutputPorts } from "../net/findOutputPorts"
import { Node } from "../node"
import { Port } from "../port"
import { formatValue } from "../value/formatValue"
Expand All @@ -18,8 +18,8 @@ export function rearrangeNodePorts(
input: Array<Port>
output: Array<Port>
} {
const input = nodeInputPorts(net, node)
const output = nodeOutputPorts(net, node)
const input = findInputPorts(net, node)
const output = findOutputPorts(net, node)

for (const name of [...rearrangement.input, ...rearrangement.output]) {
const found =
Expand Down
8 changes: 4 additions & 4 deletions src/lang/net/deleteEdgesOfNode.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Net } from "../net"
import { Node } from "../node"
import { deleteEdge } from "./deleteEdge"
import { findInputPorts } from "./findInputPorts"
import { findOutputPorts } from "./findOutputPorts"
import { findPortEntry } from "./findPortEntry"
import { nodeInputPorts } from "./nodeInputPorts"
import { nodeOutputPorts } from "./nodeOutputPorts"

export function deleteEdgesOfNode(net: Net, node: Node): void {
for (const port of nodeInputPorts(net, node)) {
for (const port of findInputPorts(net, node)) {
const portEntry = findPortEntry(net, port)
portEntry?.connection && deleteEdge(net, portEntry.connection.edge)
}

for (const port of nodeOutputPorts(net, node)) {
for (const port of findOutputPorts(net, node)) {
const portEntry = findPortEntry(net, port)
portEntry?.connection && deleteEdge(net, portEntry.connection.edge)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Port } from "../port"
import { Net } from "./Net"
import { findPortRecordOrFail } from "./findPortRecordOrFail"

export function nodeInputPorts(net: Net, node: Node): Array<Port> {
export function findInputPorts(net: Net, node: Node): Array<Port> {
const portRecord = findPortRecordOrFail(net, node)
return Object.values(portRecord)
.filter(({ sign }) => sign === -1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Port } from "../port"
import { Net } from "./Net"
import { findPortRecordOrFail } from "./findPortRecordOrFail"

export function nodeOutputPorts(net: Net, node: Node): Array<Port> {
export function findOutputPorts(net: Net, node: Node): Array<Port> {
const portRecord = findPortRecordOrFail(net, node)
return Object.values(portRecord)
.filter(({ sign }) => sign === 1)
Expand Down
4 changes: 2 additions & 2 deletions src/lang/placeholder/addPlaceholderInputPortForPort.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Mod } from "../mod"
import { Net } from "../net"
import { addNode } from "../net/addNode"
import { nodeInputPorts } from "../net/nodeInputPorts"
import { findInputPorts } from "../net/findInputPorts"
import { Port } from "../port"

export function addPlaceholderInputPortForPort(
Expand All @@ -26,5 +26,5 @@ export function addPlaceholderInputPortForPort(
[],
)

return nodeInputPorts(net, node)[0]
return findInputPorts(net, node)[0]
}
4 changes: 2 additions & 2 deletions src/lang/placeholder/addPlaceholderOutputPortForPort.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Mod } from "../mod"
import { Net } from "../net"
import { addNode } from "../net/addNode"
import { nodeOutputPorts } from "../net/nodeOutputPorts"
import { findOutputPorts } from "../net/findOutputPorts"
import { Port } from "../port"

export function addPlaceholderOutputPortForPort(
Expand All @@ -26,5 +26,5 @@ export function addPlaceholderOutputPortForPort(
],
)

return nodeOutputPorts(net, node)[0]
return findOutputPorts(net, node)[0]
}
4 changes: 2 additions & 2 deletions src/lang/placeholder/addPlaceholderOutputPortFromType.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Mod } from "../mod"
import { Net } from "../net"
import { addNode } from "../net/addNode"
import { nodeOutputPorts } from "../net/nodeOutputPorts"
import { findOutputPorts } from "../net/findOutputPorts"
import { Port } from "../port"
import { Value } from "../value"

Expand All @@ -27,5 +27,5 @@ export function addPlaceholderOutputPortFromType(
],
)

return nodeOutputPorts(net, node)[0]
return findOutputPorts(net, node)[0]
}
8 changes: 4 additions & 4 deletions src/lang/placeholder/connectNodeWithPlaceholderPorts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { connect } from "../connect/connect"
import { Mod } from "../mod"
import { Net } from "../net"
import { nodeInputPorts } from "../net/nodeInputPorts"
import { nodeOutputPorts } from "../net/nodeOutputPorts"
import { findInputPorts } from "../net/findInputPorts"
import { findOutputPorts } from "../net/findOutputPorts"
import { Node } from "../node"
import { addPlaceholderInputPortForPort } from "./addPlaceholderInputPortForPort"
import { addPlaceholderOutputPortForPort } from "./addPlaceholderOutputPortForPort"
Expand All @@ -12,14 +12,14 @@ export function connectNodeWithPlaceholderPorts(
net: Net,
node: Node,
): void {
for (const port of nodeInputPorts(net, node)) {
for (const port of findInputPorts(net, node)) {
if (!port.isPrincipal) {
const placeholderPort = addPlaceholderOutputPortForPort(net, mod, port)
connect(net, port, placeholderPort)
}
}

for (const port of nodeOutputPorts(net, node)) {
for (const port of findOutputPorts(net, node)) {
if (!port.isPrincipal) {
const placeholderPort = addPlaceholderInputPortForPort(net, mod, port)
connect(net, port, placeholderPort)
Expand Down
4 changes: 2 additions & 2 deletions src/lang/run/releaseFreePorts.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { disconnect } from "../connect/disconnect"
import { Env } from "../env"
import { findInputPorts } from "../net/findInputPorts"
import { findPortEntry } from "../net/findPortEntry"
import { nodeInputPorts } from "../net/nodeInputPorts"
import { Node } from "../node"

export function releaseFreePorts(env: Env, closer: Node | undefined): void {
if (closer === undefined) {
return
}

for (const port of nodeInputPorts(env.net, closer)) {
for (const port of findInputPorts(env.net, closer)) {
if (port === undefined) {
return
}
Expand Down

0 comments on commit 0eb3c5f

Please sign in to comment.