import { NULL_POINTER } from "../../BinaryTopology.js";
import { bt_edge_get } from "../../query/bt_edge_get.js";
import { bt_edge_create } from "./bt_edge_create.js";

/**
 * Ensure an edge between two vertices
 * NOTE: works without having to use a separate hash map, resulting in faster execution and smaller RAM requirement
 * @param {BinaryTopology} mesh
 * @param {number} v0
 * @param {number} v1
 * @returns {number} edge ID
 */
export function bt_edge_get_or_create(mesh, v0, v1) {
    const existing = bt_edge_get(mesh, v0, v1);

    if (existing !== NULL_POINTER) {
        return existing;
    }

    return bt_edge_create(mesh, v0, v1);
}
