type InterfaceCost = { serverId: number; interface: string; areaId: string; cost: number | null } export const ospfCostKey = (serverId: number, iface: string, areaId: string) => JSON.stringify([serverId, iface, areaId]) export function buildOspfCostIndex(interfaces: InterfaceCost[]): Map { const result = new Map() for (const iface of interfaces) { const key = ospfCostKey(iface.serverId, iface.interface, iface.areaId) const cost = iface.cost !== null && Number.isInteger(iface.cost) && iface.cost >= 0 && iface.cost <= 65535 ? iface.cost : null result.set(key, result.has(key) && result.get(key) !== cost ? null : cost) } return result }