From e3cbca922505386e2cdcb86be5a08d71843d74e9 Mon Sep 17 00:00:00 2001 From: Bruno Peixoto Date: Fri, 14 Jan 2022 17:02:56 -0300 Subject: [PATCH] Cycles and graph density are private --- src/data-structures/graph/Graph.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/data-structures/graph/Graph.js b/src/data-structures/graph/Graph.js index d1a87a50..4ec29a8c 100644 --- a/src/data-structures/graph/Graph.js +++ b/src/data-structures/graph/Graph.js @@ -2,6 +2,7 @@ import { cyclicSort, getAllIndexes } from '../../utils/arrays/arrays.js' export default class Graph { #cycles; + #density; /** * @param {boolean} isDirected @@ -10,12 +11,21 @@ export default class Graph { this.vertices = {}; this.edges = {}; this.isDirected = isDirected; - this.#cycles = []; + this.#cycles = []; + this.#density = 0; } get cycles(){ - return this.allCycles(); - } + return this.cyclicPaths(); + } + + get density(){ + let n_vertices = this.getNumVertices(); + let n_dense = n_vertices*(n_vertices-1)/2; + let n_edges = this.getAllEdges().length; + + return n_edges/n_dense; + } /** * @param {GraphVertex} newVertex