import { DifferenceStreamWriter, LinearUnaryOperator } from '../graph.js' import { StreamBuilder } from '../d2.js' import type { IStreamBuilder, PipedOperator } from '../types.js' import type { MultiSet } from '../multiset.js' /** * Operator that negates the multiplicities in the input stream */ export class NegateOperator extends LinearUnaryOperator { inner(collection: MultiSet): MultiSet { return collection.negate() } } /** * Negates the multiplicities in the input stream */ export function negate(): PipedOperator { return (stream: IStreamBuilder): IStreamBuilder => { const output = new StreamBuilder( stream.graph, new DifferenceStreamWriter(), ) const operator = new NegateOperator( stream.graph.getNextOperatorId(), stream.connectReader(), output.writer, ) stream.graph.addOperator(operator) return output } }