Skip to content

Commit

Permalink
Merge pull request #24 from datastructures-js/add_fn
Browse files Browse the repository at this point in the history
getVertexValue
  • Loading branch information
eyas-ranjous authored Nov 7, 2022
2 parents 8464f80 + 6480510 commit 4b62d2c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [v5.3.0] - 2022-11-07
### Added
- `getVertexValue(key)` returns vertex value.

## [v5.2.0] - 2022-11-07
### Added
- `.getConnectedVertices(key)` to get connected nodes to a given node.
- `.getConnecetedEdges(key)`to get connected edges from a given node.
- `getConnectedVertices(key)` to get connected nodes to a given node.
- `getConnecetedEdges(key)`to get connected edges from a given node.
- `traverseDfs(key, cb, abortCb)` added abortCb optional param to abort traversal.
- `traverseBfs(key, cb, abortCb)` added abortCb optional param to abort traversal.

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Graph & Directed Graph implementation in javascript.
* [constructor](#constructor)
* [addVertex](#addvertex)
* [hasVertex](#hasvertex)
* [getVertexValue](#getvertexvalue)
* [getVerticesCount](#getverticescount)
* [addEdge](#addedge)
* [hasEdge](#hasedge)
Expand Down Expand Up @@ -96,6 +97,14 @@ console.log(directedGraph.hasVertex('v7')); // false
console.log(graph.hasVertex('v1')); // true
```

### getVertexValue
Returns the value associated with a vertex key.

```js
console.log(directedGraph.getVertexValue('v5')); // 5
console.log(graph.getVertexValue('v1')); // true
```

### getVerticesCount
Gets the number of vertices in the graph.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@datastructures-js/graph",
"version": "5.2.0",
"version": "5.3.0",
"description": "graph & directed graph implementation in javascript",
"main": "index.js",
"types": "index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/directedGraph.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export class DirectedGraph<T extends number|string, U = undefined> {
addVertex(key: T, value: U): DirectedGraph<T, U>;
hasVertex(key: T): boolean;
getVertexValue(key: T): U;
removeVertex(key: T): boolean;
getVerticesCount(): number;
getConnectedVertices(key: T): T[];
Expand Down
10 changes: 10 additions & 0 deletions src/directedGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ class DirectedGraph {
return this._vertices.has(key);
}

/**
* returns vertex value
* @public
* @param {number|string} key
* @return {object}
*/
getVertexValue(key) {
return this._vertices.get(key);
}

/**
* Removes a vertex and all its edges from the graph
* @public
Expand Down

0 comments on commit 4b62d2c

Please sign in to comment.