UNPKG

@crstrskp/graph

Version:

High-performance TypeScript graph algorithms library optimized for trading bots and arbitrage detection

42 lines 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Edge = void 0; class Edge { /** * */ constructor(start, end) { this.start = start; this.end = end; this.cost = -1; this.attributes = {}; this.id = 0; // Will be set by GraphImpl.generateId() } getCost() { if (this.cost !== -1) { return this.cost; } else { const payload = this.getAttribute("payload"); if (typeof payload === 'number') { return payload; } else if (payload && typeof payload.getCost === 'function') { return payload.getCost(); } else { return 1; // default cost } } } setCost(cost) { this.cost = cost; } getPrev() { return this.prev; } setPrev(p) { this.prev = p; } getId() { return this.id; } setAttribute(key, value) { this.attributes[key] = value; } getAttribute(key) { return this.attributes[key]; } } exports.Edge = Edge; //# sourceMappingURL=Edge.js.map