@ralfderijcke/graph
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "@ralfderijcke/graph", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Basic graph data structure to store data", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# Graph | ||
[![npm version](https://img.shields.io/npm/v/@ralfderijcke/graph)](https://www.npmjs.com/package/@ralfderijcke/graph) | ||
Basic graph data structure to store data. | ||
## Installation | ||
[@ralfderijcke/graph](https://www.npmjs.com/package/@ralfderijcke/graph) is available as a npm. | ||
```sh | ||
npm install @ralfderijcke/graph --save | ||
``` | ||
## Getting Started | ||
@@ -17,2 +27,2 @@ | ||
const edge1 = graph.addEdge(vertex1, vertex2); | ||
``` | ||
``` |
import { Edge } from "./edge"; | ||
import { Random } from "./random"; | ||
import { Vertex } from "./vertex"; | ||
@@ -29,10 +28,14 @@ | ||
// const nextEdge = targetEdges.find(e => !e.equals(edge)); // Not itself | ||
// Take random edge | ||
const nextEdges = targetEdges.filter(e => !e.equals(edge)); | ||
const nextEdges = targetEdges.filter(e => !e.equals(edge)); // Not itself | ||
if (!nextEdges.length) { | ||
return; | ||
} | ||
const n = Random.number(0, nextEdges.length); | ||
console.log(n); | ||
function randomNumber(min: number, max: number): number { | ||
min = Math.ceil(min); | ||
max = Math.floor(max); | ||
return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive | ||
} | ||
const n = randomNumber(0, nextEdges.length); | ||
const nextEdge = nextEdges[n]; | ||
@@ -39,0 +42,0 @@ |
@@ -1,5 +0,3 @@ | ||
import { Random } from "./random"; | ||
export class Vertex { | ||
public readonly graphKey: string = Random.string(8, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); | ||
public readonly graphKey: string = window.crypto.randomUUID(); | ||
public readonly value: object; | ||
@@ -6,0 +4,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28
14853
6
147