Socket
Socket
Sign inDemoInstall

@antv/graphlib

Package Overview
Dependencies
0
Maintainers
58
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.0 to 1.2.0

coverage/lcov-report/src/algorithm/PriorityQueue/index.html

571

docs/classes/Graph.md

@@ -7,9 +7,15 @@ [@antv/graphlib](../README.md) / [Exports](../modules.md) / Graph

| Name | Type |
| :----------- | :------------------------- |
| `NodeIDType` | `string` |
| `NodeType` | `Record`<`string`, `any`\> |
| `EdgeType` | `Record`<`string`, `any`\> |
| `GraphType` | `string` |
| Name | Type |
| :------ | :------ |
| `NodeIDType` | `string` |
| `NodeType` | `Record`<`string`, `any`\> |
| `EdgeType` | `Record`<`string`, `any`\> |
| `GraphType` | `string` |
## Hierarchy
- **`Graph`**
↳ [`GraphWithEvent`](GraphWithEvent.md)
## Table of contents

@@ -23,3 +29,3 @@

- [GRAPH_NODE](Graph.md#graph_node)
- [GRAPH\_NODE](Graph.md#graph_node)
- [childrenMap](Graph.md#childrenmap)

@@ -48,3 +54,2 @@ - [compound](Graph.md#compound)

- [children](Graph.md#children)
- [countSelfLoops](Graph.md#countselfloops)
- [edge](Graph.md#edge)

@@ -102,13 +107,13 @@ - [edgeCount](Graph.md#edgecount)

| Name | Type |
| :----------- | :------------------------- |
| `NodeIDType` | `string` |
| `NodeType` | `Record`<`string`, `any`\> |
| `EdgeType` | `Record`<`string`, `any`\> |
| `GraphType` | `string` |
| Name | Type |
| :------ | :------ |
| `NodeIDType` | `string` |
| `NodeType` | `Record`<`string`, `any`\> |
| `EdgeType` | `Record`<`string`, `any`\> |
| `GraphType` | `string` |
#### Parameters
| Name | Type |
| :-------- | :------------ |
| Name | Type |
| :------ | :------ |
| `options` | `GraphOption` |

@@ -118,15 +123,15 @@

[Graph/index.ts:112](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L112)
[Graph/index.ts:112](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L112)
## Properties
### GRAPH_NODE
### GRAPH\_NODE
• `Private` **GRAPH_NODE**: `NodeIDType`
• `Private` **GRAPH\_NODE**: `NodeIDType`
#### Defined in
[Graph/index.ts:73](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L73)
[Graph/index.ts:73](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L73)
---
___

@@ -143,5 +148,5 @@ ### childrenMap

[Graph/index.ts:139](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L139)
[Graph/index.ts:139](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L139)
---
___

@@ -154,5 +159,5 @@ ### compound

[Graph/index.ts:71](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L71)
[Graph/index.ts:71](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L71)
---
___

@@ -173,7 +178,7 @@ ### defaultEdgeLabelFn

| Name | Type |
| :------ | :----------- |
| `v` | `NodeIDType` |
| `w` | `NodeIDType` |
| `name?` | `string` |
| Name | Type |
| :------ | :------ |
| `v` | `NodeIDType` |
| `w` | `NodeIDType` |
| `name?` | `string` |

@@ -186,5 +191,5 @@ ##### Returns

[Graph/index.ts:106](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L106)
[Graph/index.ts:106](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L106)
---
___

@@ -205,5 +210,5 @@ ### defaultNodeLabelFn

| Name | Type |
| :--- | :----------- |
| `v` | `NodeIDType` |
| Name | Type |
| :------ | :------ |
| `v` | `NodeIDType` |

@@ -216,5 +221,5 @@ ##### Returns

[Graph/index.ts:100](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L100)
[Graph/index.ts:100](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L100)
---
___

@@ -227,5 +232,5 @@ ### directed

[Graph/index.ts:67](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L67)
[Graph/index.ts:67](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L67)
---
___

@@ -244,5 +249,5 @@ ### edgeCountNum

[Graph/index.ts:94](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L94)
[Graph/index.ts:94](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L94)
---
___

@@ -259,5 +264,5 @@ ### edgesLabelsMap

[Graph/index.ts:173](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L173)
[Graph/index.ts:173](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L173)
---
___

@@ -274,5 +279,5 @@ ### edgesMap

[Graph/index.ts:167](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L167)
[Graph/index.ts:167](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L167)
---
___

@@ -289,5 +294,5 @@ ### inEdgesMap

[Graph/index.ts:147](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L147)
[Graph/index.ts:147](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L147)
---
___

@@ -306,5 +311,5 @@ ### label

[Graph/index.ts:80](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L80)
[Graph/index.ts:80](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L80)
---
___

@@ -317,5 +322,5 @@ ### multigraph

[Graph/index.ts:69](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L69)
[Graph/index.ts:69](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L69)
---
___

@@ -334,5 +339,5 @@ ### nodeCountNum

[Graph/index.ts:87](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L87)
[Graph/index.ts:87](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L87)
---
___

@@ -345,5 +350,5 @@ ### nodesLabelMap

[Graph/index.ts:141](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L141)
[Graph/index.ts:141](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L141)
---
___

@@ -356,5 +361,5 @@ ### outEdgesMap

[Graph/index.ts:149](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L149)
[Graph/index.ts:149](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L149)
---
___

@@ -371,5 +376,5 @@ ### parentMap

[Graph/index.ts:133](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L133)
[Graph/index.ts:133](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L133)
---
___

@@ -386,5 +391,5 @@ ### predecessorsMap

[Graph/index.ts:155](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L155)
[Graph/index.ts:155](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L155)
---
___

@@ -401,5 +406,5 @@ ### successorsMap

[Graph/index.ts:161](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L161)
[Graph/index.ts:161](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L161)
---
___

@@ -420,13 +425,13 @@ ### fromJSON

| Name | Type |
| :----------- | :------------------------- |
| `NodeIDType` | `string` |
| `NodeType` | `Record`<`string`, `any`\> |
| `EdgeType` | `Record`<`string`, `any`\> |
| `GraphType` | `string` |
| Name | Type |
| :------ | :------ |
| `NodeIDType` | `string` |
| `NodeType` | `Record`<`string`, `any`\> |
| `EdgeType` | `Record`<`string`, `any`\> |
| `GraphType` | `string` |
##### Parameters
| Name | Type |
| :----- | :-------------------------------------------------------------- |
| Name | Type |
| :------ | :------ |
| `json` | `JSONGraph`<`NodeIDType`, `NodeType`, `EdgeType`, `GraphType`\> |

@@ -440,3 +445,3 @@

[Graph/index.ts:762](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L762)
[Graph/index.ts:762](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L762)

@@ -459,5 +464,5 @@ ## Methods

[Graph/index.ts:335](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L335)
[Graph/index.ts:335](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L335)
---
___

@@ -474,4 +479,4 @@ ### children

| Name | Type |
| :------ | :----------- |
| Name | Type |
| :------ | :------ |
| `node?` | `NodeIDType` |

@@ -485,24 +490,6 @@

[Graph/index.ts:408](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L408)
[Graph/index.ts:408](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L408)
---
___
### countSelfLoops
▸ **countSelfLoops**(): `number`
**`description`** Count the total edges with self loop
**`description.zh-cn`** 计算节点的自环边的数量
#### Returns
`number`
#### Defined in
[Graph/index.ts:816](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L816)
---
### edge

@@ -514,12 +501,12 @@

**`description.zh-cn`** 从 edgeObj 获得两个节点中的一条边
**`description.zh-cn`** 从edgeObj获得两个节点中的一条边
#### Parameters
| Name | Type |
| :-------------- | :----------- |
| `edgeObj` | `Object` |
| `edgeObj.name?` | `any` |
| `edgeObj.v` | `NodeIDType` |
| `edgeObj.w` | `NodeIDType` |
| Name | Type |
| :------ | :------ |
| `edgeObj` | `Object` |
| `edgeObj.name?` | `any` |
| `edgeObj.v` | `NodeIDType` |
| `edgeObj.w` | `NodeIDType` |

@@ -532,5 +519,5 @@ #### Returns

[Graph/index.ts:660](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L660)
[Graph/index.ts:660](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L660)
---
___

@@ -553,5 +540,5 @@ ### edgeCount

[Graph/index.ts:579](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L579)
[Graph/index.ts:579](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L579)
---
___

@@ -568,7 +555,7 @@ ### edgeFromArgs

| Name | Type |
| :------ | :----------- |
| `v` | `NodeIDType` |
| `w` | `NodeIDType` |
| `name?` | `any` |
| Name | Type |
| :------ | :------ |
| `v` | `NodeIDType` |
| `w` | `NodeIDType` |
| `name?` | `any` |

@@ -581,5 +568,5 @@ #### Returns

[Graph/index.ts:650](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L650)
[Graph/index.ts:650](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L650)
---
___

@@ -600,5 +587,5 @@ ### edges

[Graph/index.ts:716](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L716)
[Graph/index.ts:716](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L716)
---
___

@@ -615,4 +602,4 @@ ### filterNodes

| Name | Type |
| :------- | :---------------------------------- |
| Name | Type |
| :------ | :------ |
| `filter` | (`node`: `NodeIDType`) => `boolean` |

@@ -626,5 +613,5 @@

[Graph/index.ts:480](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L480)
[Graph/index.ts:480](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L480)
---
___

@@ -647,5 +634,5 @@ ### graph

[Graph/index.ts:212](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L212)
[Graph/index.ts:212](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L212)
---
___

@@ -662,7 +649,7 @@ ### hasEdge

| Name | Type |
| :------ | :----------- |
| `v` | `NodeIDType` |
| `w` | `NodeIDType` |
| `name?` | `any` |
| Name | Type |
| :------ | :------ |
| `v` | `NodeIDType` |
| `w` | `NodeIDType` |
| `name?` | `any` |

@@ -675,5 +662,5 @@ #### Returns

[Graph/index.ts:672](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L672)
[Graph/index.ts:672](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L672)
---
___

@@ -690,4 +677,4 @@ ### hasNode

| Name | Type |
| :----- | :----------- |
| Name | Type |
| :------ | :------ |
| `node` | `NodeIDType` |

@@ -701,5 +688,5 @@

[Graph/index.ts:329](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L329)
[Graph/index.ts:329](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L329)
---
___

@@ -716,5 +703,5 @@ ### inEdges

| Name | Type |
| :--- | :----------- |
| `v` | `NodeIDType` |
| Name | Type |
| :------ | :------ |
| `v` | `NodeIDType` |
| `u?` | `NodeIDType` |

@@ -728,5 +715,5 @@

[Graph/index.ts:725](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L725)
[Graph/index.ts:725](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L725)
---
___

@@ -749,5 +736,5 @@ ### isCompound

[Graph/index.ts:194](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L194)
[Graph/index.ts:194](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L194)
---
___

@@ -770,5 +757,5 @@ ### isDirected

[Graph/index.ts:180](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L180)
[Graph/index.ts:180](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L180)
---
___

@@ -785,4 +772,4 @@ ### isLeaf

| Name | Type |
| :----- | :----------- |
| Name | Type |
| :------ | :------ |
| `node` | `NodeIDType` |

@@ -796,5 +783,5 @@

[Graph/index.ts:467](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L467)
[Graph/index.ts:467](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L467)
---
___

@@ -817,5 +804,5 @@ ### isMultigraph

[Graph/index.ts:187](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L187)
[Graph/index.ts:187](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L187)
---
___

@@ -832,4 +819,4 @@ ### neighbors

| Name | Type |
| :----- | :----------- |
| Name | Type |
| :------ | :------ |
| `node` | `NodeIDType` |

@@ -843,5 +830,5 @@

[Graph/index.ts:454](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L454)
[Graph/index.ts:454](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L454)
---
___

@@ -858,5 +845,5 @@ ### node

| Name | Type |
| :--- | :----------- |
| `n` | `NodeIDType` |
| Name | Type |
| :------ | :------ |
| `n` | `NodeIDType` |

@@ -869,5 +856,5 @@ #### Returns

[Graph/index.ts:240](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L240)
[Graph/index.ts:240](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L240)
---
___

@@ -890,5 +877,5 @@ ### nodeCount

[Graph/index.ts:234](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L234)
[Graph/index.ts:234](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L234)
---
___

@@ -905,4 +892,4 @@ ### nodeDegree

| Name | Type |
| :----- | :----------- |
| Name | Type |
| :------ | :------ |
| `node` | `NodeIDType` |

@@ -916,5 +903,5 @@

[Graph/index.ts:796](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L796)
[Graph/index.ts:796](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L796)
---
___

@@ -931,5 +918,5 @@ ### nodeEdges

| Name | Type |
| :--- | :----------- |
| `v` | `NodeIDType` |
| Name | Type |
| :------ | :------ |
| `v` | `NodeIDType` |
| `w?` | `NodeIDType` |

@@ -943,5 +930,5 @@

[Graph/index.ts:755](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L755)
[Graph/index.ts:755](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L755)
---
___

@@ -958,4 +945,4 @@ ### nodeInDegree

| Name | Type |
| :----- | :----------- |
| Name | Type |
| :------ | :------ |
| `node` | `NodeIDType` |

@@ -969,5 +956,5 @@

[Graph/index.ts:772](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L772)
[Graph/index.ts:772](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L772)
---
___

@@ -984,4 +971,4 @@ ### nodeOutDegree

| Name | Type |
| :----- | :----------- |
| Name | Type |
| :------ | :------ |
| `node` | `NodeIDType` |

@@ -995,5 +982,5 @@

[Graph/index.ts:784](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L784)
[Graph/index.ts:784](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L784)
---
___

@@ -1014,5 +1001,5 @@ ### nodes

[Graph/index.ts:247](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L247)
[Graph/index.ts:247](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L247)
---
___

@@ -1029,5 +1016,5 @@ ### outEdges

| Name | Type |
| :--- | :----------- |
| `w` | `NodeIDType` |
| Name | Type |
| :------ | :------ |
| `w` | `NodeIDType` |
| `u?` | `NodeIDType` |

@@ -1041,5 +1028,5 @@

[Graph/index.ts:740](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L740)
[Graph/index.ts:740](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L740)
---
___

@@ -1056,4 +1043,4 @@ ### parent

| Name | Type |
| :----- | :----------- |
| Name | Type |
| :------ | :------ |
| `node` | `NodeIDType` |

@@ -1067,5 +1054,5 @@

[Graph/index.ts:347](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L347)
[Graph/index.ts:347](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L347)
---
___

@@ -1082,4 +1069,4 @@ ### predecessors

| Name | Type |
| :----- | :----------- |
| Name | Type |
| :------ | :------ |
| `node` | `NodeIDType` |

@@ -1093,9 +1080,9 @@

[Graph/index.ts:432](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L432)
[Graph/index.ts:432](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L432)
---
___
### removeEdge
▸ **removeEdge**(`v_`, `w_`, `name?`): `this`
▸ **removeEdge**(`v_`, `w_`, `name?`): [`Graph`](Graph.md)<`NodeIDType`, `NodeType`, `EdgeType`, `GraphType`\>

@@ -1108,17 +1095,17 @@ **`description`** remove a specific edge

| Name | Type |
| :------ | :----------- |
| `v_` | `NodeIDType` |
| `w_` | `NodeIDType` |
| `name?` | `any` |
| Name | Type |
| :------ | :------ |
| `v_` | `NodeIDType` |
| `w_` | `NodeIDType` |
| `name?` | `any` |
#### Returns
`this`
[`Graph`](Graph.md)<`NodeIDType`, `NodeType`, `EdgeType`, `GraphType`\>
#### Defined in
[Graph/index.ts:684](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L684)
[Graph/index.ts:684](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L684)
---
___

@@ -1135,8 +1122,8 @@ ### removeEdgeObj

| Name | Type |
| :------------------------ | :----------- |
| `__namedParameters` | `Object` |
| `__namedParameters.name?` | `any` |
| `__namedParameters.v` | `NodeIDType` |
| `__namedParameters.w` | `NodeIDType` |
| Name | Type |
| :------ | :------ |
| `__namedParameters` | `Object` |
| `__namedParameters.name?` | `any` |
| `__namedParameters.v` | `NodeIDType` |
| `__namedParameters.w` | `NodeIDType` |

@@ -1149,5 +1136,5 @@ #### Returns

[Graph/index.ts:708](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L708)
[Graph/index.ts:708](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L708)
---
___

@@ -1164,4 +1151,4 @@ ### removeFromParentsChildList

| Name | Type |
| :----- | :----------- |
| Name | Type |
| :------ | :------ |
| `node` | `NodeIDType` |

@@ -1175,9 +1162,9 @@

[Graph/index.ts:361](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L361)
[Graph/index.ts:361](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L361)
---
___
### removeNode
▸ **removeNode**(`node`): `this`
▸ **removeNode**(`node`): [`Graph`](Graph.md)<`NodeIDType`, `NodeType`, `EdgeType`, `GraphType`\>

@@ -1190,4 +1177,4 @@ **`description`** Remove node from graph

| Name | Type |
| :----- | :----------- |
| Name | Type |
| :------ | :------ |
| `node` | `NodeIDType` |

@@ -1197,9 +1184,9 @@

`this`
[`Graph`](Graph.md)<`NodeIDType`, `NodeType`, `EdgeType`, `GraphType`\>
#### Defined in
[Graph/index.ts:527](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L527)
[Graph/index.ts:527](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L527)
---
___

@@ -1212,8 +1199,8 @@ ### setDefaultEdgeLabel

**`description.zh-cn`** 设置默认获取边 Label 的方法,如果传入不是函数的,那么默认 label 的值只会是传入值
**`description.zh-cn`** 设置默认获取边Label的方法,如果传入不是函数的,那么默认label 的值只会是传入值
#### Parameters
| Name | Type |
| :----------- | :---- |
| Name | Type |
| :------ | :------ |
| `newDefault` | `any` |

@@ -1227,5 +1214,5 @@

[Graph/index.ts:565](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L565)
[Graph/index.ts:565](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L565)
---
___

@@ -1238,8 +1225,8 @@ ### setDefaultNodeLabel

**`description.zh-cn`** 设置默认获取节点 Label 的方法,如果传入不是函数的,那么默认 label 的值只会是传入值
**`description.zh-cn`** 设置默认获取节点Label的方法,如果传入不是函数的,那么默认label 的值只会是传入值
#### Parameters
| Name | Type | Description |
| :----------- | :---- | :----------------------- |
| Name | Type | Description |
| :------ | :------ | :------ |
| `newDefault` | `any` | (node) => label \| label |

@@ -1255,9 +1242,9 @@

[Graph/index.ts:220](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L220)
[Graph/index.ts:220](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L220)
---
___
### setEdge
▸ **setEdge**(`v_`, `w_`, `value?`, `name?`): `this`
▸ **setEdge**(`v_`, `w_`, `value?`, `name?`): [`Graph`](Graph.md)<`NodeIDType`, `NodeType`, `EdgeType`, `GraphType`\>

@@ -1270,18 +1257,18 @@ **`description`** set edge value, if nodes or edges not exsit then add to graph

| Name | Type |
| :------- | :----------- |
| `v_` | `NodeIDType` |
| `w_` | `NodeIDType` |
| `value?` | `any` |
| `name?` | `string` |
| Name | Type |
| :------ | :------ |
| `v_` | `NodeIDType` |
| `w_` | `NodeIDType` |
| `value?` | `any` |
| `name?` | `string` |
#### Returns
`this`
[`Graph`](Graph.md)<`NodeIDType`, `NodeType`, `EdgeType`, `GraphType`\>
#### Defined in
[Graph/index.ts:590](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L590)
[Graph/index.ts:590](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L590)
---
___

@@ -1294,6 +1281,6 @@ ### setEdgeObj

| Name | Type |
| :-------- | :------------------------------------------- |
| Name | Type |
| :------ | :------ |
| `edgeObj` | `DefaultEdgeType`<`NodeIDType`, `EdgeType`\> |
| `value?` | `EdgeType` |
| `value?` | `EdgeType` |

@@ -1306,5 +1293,5 @@ #### Returns

[Graph/index.ts:623](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L623)
[Graph/index.ts:623](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L623)
---
___

@@ -1321,4 +1308,4 @@ ### setGraph

| Name | Type |
| :------- | :---------- |
| Name | Type |
| :------ | :------ |
| `label?` | `GraphType` |

@@ -1332,30 +1319,30 @@

[Graph/index.ts:202](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L202)
[Graph/index.ts:202](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L202)
---
___
### setNode
▸ **setNode**(`node`, `value?`): `this`
▸ **setNode**(`node`, `value?`): [`Graph`](Graph.md)<`NodeIDType`, `NodeType`, `EdgeType`, `GraphType`\>
**`description`** Set Node label in graph if node not in graph then create it
**`description.zh-cn`** 设置节点的 label,如果这个节点不在图中,则在图中创建这个节点
**`description.zh-cn`** 设置节点的label,如果这个节点不在图中,则在图中创建这个节点
#### Parameters
| Name | Type |
| :------- | :----------- |
| `node` | `NodeIDType` |
| `value?` | `NodeType` |
| Name | Type |
| :------ | :------ |
| `node` | `NodeIDType` |
| `value?` | `NodeType` |
#### Returns
`this`
[`Graph`](Graph.md)<`NodeIDType`, `NodeType`, `EdgeType`, `GraphType`\>
#### Defined in
[Graph/index.ts:270](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L270)
[Graph/index.ts:270](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L270)
---
___

@@ -1372,6 +1359,6 @@ ### setNodes

| Name | Type |
| :------- | :------------- |
| `nodes` | `NodeIDType`[] |
| `value?` | `NodeType` |
| Name | Type |
| :------ | :------ |
| `nodes` | `NodeIDType`[] |
| `value?` | `NodeType` |

@@ -1384,5 +1371,5 @@ #### Returns

[Graph/index.ts:318](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L318)
[Graph/index.ts:318](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L318)
---
___

@@ -1399,5 +1386,5 @@ ### setParent

| Name | Type |
| :-------- | :----------- |
| `node` | `NodeIDType` |
| Name | Type |
| :------ | :------ |
| `node` | `NodeIDType` |
| `parent?` | `NodeIDType` |

@@ -1411,5 +1398,5 @@

[Graph/index.ts:373](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L373)
[Graph/index.ts:373](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L373)
---
___

@@ -1426,6 +1413,6 @@ ### setPath

| Name | Type |
| :------- | :------------- |
| `edges` | `NodeIDType`[] |
| `value?` | `any` |
| Name | Type |
| :------ | :------ |
| `edges` | `NodeIDType`[] |
| `value?` | `any` |

@@ -1438,5 +1425,5 @@ #### Returns

[Graph/index.ts:634](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L634)
[Graph/index.ts:634](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L634)
---
___

@@ -1449,3 +1436,3 @@ ### sinks

**`description`** 返回图中所有终点节点(出度为 0)
**`description`** 返回图中所有终点节点(出度为0)

@@ -1458,5 +1445,5 @@ #### Returns

[Graph/index.ts:261](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L261)
[Graph/index.ts:261](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L261)
---
___

@@ -1473,4 +1460,4 @@ ### source

| Name | Type |
| :----- | :------------------------------------------- |
| Name | Type |
| :------ | :------ |
| `edge` | `DefaultEdgeType`<`NodeIDType`, `EdgeType`\> |

@@ -1484,5 +1471,5 @@

[Graph/index.ts:804](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L804)
[Graph/index.ts:804](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L804)
---
___

@@ -1495,3 +1482,3 @@ ### sources

**`description`** 返回图中所有源头节点(入度为 0)
**`description`** 返回图中所有源头节点(入度为0)

@@ -1504,5 +1491,5 @@ #### Returns

[Graph/index.ts:254](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L254)
[Graph/index.ts:254](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L254)
---
___

@@ -1519,4 +1506,4 @@ ### successors

| Name | Type |
| :----- | :----------- |
| Name | Type |
| :------ | :------ |
| `node` | `NodeIDType` |

@@ -1530,5 +1517,5 @@

[Graph/index.ts:443](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L443)
[Graph/index.ts:443](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L443)
---
___

@@ -1545,4 +1532,4 @@ ### target

| Name | Type |
| :----- | :------------------------------------------- |
| Name | Type |
| :------ | :------ |
| `edge` | `DefaultEdgeType`<`NodeIDType`, `EdgeType`\> |

@@ -1556,5 +1543,5 @@

[Graph/index.ts:810](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L810)
[Graph/index.ts:810](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L810)
---
___

@@ -1571,2 +1558,2 @@ ### toJSON

[Graph/index.ts:764](https://github.com/antvis/graphlib/blob/630e2c1/src/Graph/index.ts#L764)
[Graph/index.ts:764](https://github.com/antvis/graphlib/blob/7513e82/src/Graph/index.ts#L764)

@@ -11,2 +11,4 @@ [@antv/graphlib](README.md) / Exports

- [comparision](modules/comparision.md)
- [essence](modules/essence.md)
- [generate](modules/generate.md)

@@ -16,25 +18,2 @@ ### Classes

- [Graph](classes/Graph.md)
### Functions
- [isGraph](modules.md#isgraph)
## Functions
### isGraph
▸ **isGraph**(`obj`): `boolean`
#### Parameters
| Name | Type |
| :---- | :---- |
| `obj` | `any` |
#### Returns
`boolean`
#### Defined in
[util.ts:95](https://github.com/antvis/graphlib/blob/630e2c1/src/util.ts#L95)
- [GraphWithEvent](classes/GraphWithEvent.md)

@@ -30,4 +30,4 @@ [@antv/graphlib](../README.md) / [Exports](../modules.md) / algorithm

| Name |
| :----------- |
| Name |
| :------ |
| `NodeIDType` |

@@ -38,3 +38,3 @@

| Name | Type |
| :-- | :-- |
| :------ | :------ |
| `graph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `Record`<`string`, `any`\>, `Record`<`string`, `any`\>, `string`\> |

@@ -48,5 +48,5 @@

[algorithm/components.ts:3](https://github.com/antvis/graphlib/blob/630e2c1/src/algorithm/components.ts#L3)
[algorithm/components.ts:3](https://github.com/antvis/graphlib/blob/7513e82/src/algorithm/components.ts#L3)
---
___

@@ -63,4 +63,4 @@ ### dfs

| Name | Type |
| :----------- | :---- |
| Name | Type |
| :------ | :------ |
| `NodeIDType` | `any` |

@@ -70,7 +70,7 @@

| Name | Type |
| :------ | :----------------------------------------------------------------- |
| Name | Type |
| :------ | :------ |
| `graph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `any`, `any`\> |
| `node` | `NodeIDType` \| `NodeIDType`[] |
| `order` | `"pre"` \| `"post"` |
| `node` | `NodeIDType` \| `NodeIDType`[] |
| `order` | ``"pre"`` \| ``"post"`` |

@@ -83,5 +83,5 @@ #### Returns

[algorithm/dfs.ts:33](https://github.com/antvis/graphlib/blob/630e2c1/src/algorithm/dfs.ts#L33)
[algorithm/dfs.ts:33](https://github.com/antvis/graphlib/blob/7513e82/src/algorithm/dfs.ts#L33)
---
___

@@ -100,15 +100,15 @@ ### dijkstra

| Name |
| :----------- |
| Name |
| :------ |
| `NodeIDType` |
| `EdgeType` |
| `EdgeType` |
#### Parameters
| Name | Type |
| :---------- | :------------------------------------------------------------------------- |
| `graph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `EdgeType`, `string`\> |
| `source` | `NodeIDType` |
| `weightFn?` | (`node`: `DefaultEdgeType`<`NodeIDType`, `EdgeType`\>) => `number` |
| `edgeFn?` | (`node`: `NodeIDType`) => `DefaultEdgeType`<`NodeIDType`, `EdgeType`\>[] |
| Name | Type |
| :------ | :------ |
| `graph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `EdgeType`, `string`\> |
| `source` | `NodeIDType` |
| `weightFn?` | (`node`: `DefaultEdgeType`<`NodeIDType`, `EdgeType`\>) => `number` |
| `edgeFn?` | (`node`: `NodeIDType`) => `DefaultEdgeType`<`NodeIDType`, `EdgeType`\>[] |

@@ -121,5 +121,5 @@ #### Returns

[algorithm/dijkstra.ts:11](https://github.com/antvis/graphlib/blob/630e2c1/src/algorithm/dijkstra.ts#L11)
[algorithm/dijkstra.ts:11](https://github.com/antvis/graphlib/blob/7513e82/src/algorithm/dijkstra.ts#L11)
---
___

@@ -132,4 +132,4 @@ ### dijkstraAll

| Name |
| :--------- |
| Name |
| :------ |
| `NodeType` |

@@ -140,7 +140,7 @@ | `EdgeType` |

| Name | Type |
| :---------- | :----------------------------------------------------------------------- |
| `graph` | [`Graph`](../classes/Graph.md)<`NodeType`, `any`, `EdgeType`, `string`\> |
| `weightFn?` | (`node`: `DefaultEdgeType`<`NodeType`, `EdgeType`\>) => `number` |
| `edgeFn?` | (`node`: `NodeType`) => `DefaultEdgeType`<`NodeType`, `EdgeType`\>[] |
| Name | Type |
| :------ | :------ |
| `graph` | [`Graph`](../classes/Graph.md)<`NodeType`, `any`, `EdgeType`, `string`\> |
| `weightFn?` | (`node`: `DefaultEdgeType`<`NodeType`, `EdgeType`\>) => `number` |
| `edgeFn?` | (`node`: `NodeType`) => `DefaultEdgeType`<`NodeType`, `EdgeType`\>[] |

@@ -153,5 +153,5 @@ #### Returns

[algorithm/dijkstra-all.ts:4](https://github.com/antvis/graphlib/blob/630e2c1/src/algorithm/dijkstra-all.ts#L4)
[algorithm/dijkstra-all.ts:4](https://github.com/antvis/graphlib/blob/7513e82/src/algorithm/dijkstra-all.ts#L4)
---
___

@@ -164,4 +164,4 @@ ### findCycles

| Name |
| :--------- |
| Name |
| :------ |
| `NodeType` |

@@ -172,3 +172,3 @@

| Name | Type |
| :-- | :-- |
| :------ | :------ |
| `graph` | [`Graph`](../classes/Graph.md)<`NodeType`, `Record`<`string`, `any`\>, `Record`<`string`, `any`\>, `string`\> |

@@ -182,5 +182,5 @@

[algorithm/find-cycles.ts:4](https://github.com/antvis/graphlib/blob/630e2c1/src/algorithm/find-cycles.ts#L4)
[algorithm/find-cycles.ts:4](https://github.com/antvis/graphlib/blob/7513e82/src/algorithm/find-cycles.ts#L4)
---
___

@@ -193,14 +193,14 @@ ### floydWarshall

| Name |
| :----------- |
| Name |
| :------ |
| `NodeIDType` |
| `EdgeType` |
| `EdgeType` |
#### Parameters
| Name | Type |
| :---------- | :------------------------------------------------------------------------- |
| `graph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `EdgeType`, `string`\> |
| `weightFn?` | (`node`: `DefaultEdgeType`<`NodeIDType`, `EdgeType`\>) => `number` |
| `edgeFn?` | (`node`: `NodeIDType`) => `DefaultEdgeType`<`NodeIDType`, `EdgeType`\>[] |
| Name | Type |
| :------ | :------ |
| `graph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `EdgeType`, `string`\> |
| `weightFn?` | (`node`: `DefaultEdgeType`<`NodeIDType`, `EdgeType`\>) => `number` |
| `edgeFn?` | (`node`: `NodeIDType`) => `DefaultEdgeType`<`NodeIDType`, `EdgeType`\>[] |

@@ -213,5 +213,5 @@ #### Returns

[algorithm/floyd-warshall.ts:5](https://github.com/antvis/graphlib/blob/630e2c1/src/algorithm/floyd-warshall.ts#L5)
[algorithm/floyd-warshall.ts:5](https://github.com/antvis/graphlib/blob/7513e82/src/algorithm/floyd-warshall.ts#L5)
---
___

@@ -225,3 +225,3 @@ ### isAcyclic

| Name | Type |
| :-- | :-- |
| :------ | :------ |
| `graph` | [`Graph`](../classes/Graph.md)<`string`, `Record`<`string`, `any`\>, `Record`<`string`, `any`\>, `string`\> |

@@ -235,5 +235,5 @@

[algorithm/is-acyclic.ts:4](https://github.com/antvis/graphlib/blob/630e2c1/src/algorithm/is-acyclic.ts#L4)
[algorithm/is-acyclic.ts:4](https://github.com/antvis/graphlib/blob/7513e82/src/algorithm/is-acyclic.ts#L4)
---
___

@@ -246,4 +246,4 @@ ### postorder

| Name |
| :--------- |
| Name |
| :------ |
| `NodeType` |

@@ -253,6 +253,6 @@

| Name | Type |
| :------ | :--------------------------------------------------------------- |
| Name | Type |
| :------ | :------ |
| `graph` | [`Graph`](../classes/Graph.md)<`NodeType`, `any`, `any`, `any`\> |
| `nodes` | `NodeType` \| `NodeType`[] |
| `nodes` | `NodeType` \| `NodeType`[] |

@@ -265,5 +265,5 @@ #### Returns

[algorithm/postorder.ts:4](https://github.com/antvis/graphlib/blob/630e2c1/src/algorithm/postorder.ts#L4)
[algorithm/postorder.ts:4](https://github.com/antvis/graphlib/blob/7513e82/src/algorithm/postorder.ts#L4)
---
___

@@ -276,4 +276,4 @@ ### preorder

| Name |
| :--------- |
| Name |
| :------ |
| `NodeType` |

@@ -283,6 +283,6 @@

| Name | Type |
| :------ | :--------------------------------------------------------------- |
| Name | Type |
| :------ | :------ |
| `graph` | [`Graph`](../classes/Graph.md)<`NodeType`, `any`, `any`, `any`\> |
| `nodes` | `NodeType` \| `NodeType`[] |
| `nodes` | `NodeType` \| `NodeType`[] |

@@ -295,5 +295,5 @@ #### Returns

[algorithm/preorder.ts:4](https://github.com/antvis/graphlib/blob/630e2c1/src/algorithm/preorder.ts#L4)
[algorithm/preorder.ts:4](https://github.com/antvis/graphlib/blob/7513e82/src/algorithm/preorder.ts#L4)
---
___

@@ -306,14 +306,14 @@ ### prim

| Name |
| :----------- |
| Name |
| :------ |
| `NodeIdType` |
| `NodeType` |
| `EdgeType` |
| `NodeType` |
| `EdgeType` |
#### Parameters
| Name | Type |
| :--------- | :------------------------------------------------------------------------------ |
| `graph` | [`Graph`](../classes/Graph.md)<`NodeIdType`, `NodeType`, `EdgeType`, `string`\> |
| `weightFn` | (`node`: `DefaultEdgeType`<`NodeIdType`, `EdgeType`\>) => `number` |
| Name | Type |
| :------ | :------ |
| `graph` | [`Graph`](../classes/Graph.md)<`NodeIdType`, `NodeType`, `EdgeType`, `string`\> |
| `weightFn` | (`node`: `DefaultEdgeType`<`NodeIdType`, `EdgeType`\>) => `number` |

@@ -326,5 +326,5 @@ #### Returns

[algorithm/prim.ts:4](https://github.com/antvis/graphlib/blob/630e2c1/src/algorithm/prim.ts#L4)
[algorithm/prim.ts:4](https://github.com/antvis/graphlib/blob/7513e82/src/algorithm/prim.ts#L4)
---
___

@@ -343,4 +343,4 @@ ### tarjan

| Name |
| :----------- |
| Name |
| :------ |
| `NodeIDType` |

@@ -351,3 +351,3 @@

| Name | Type |
| :-- | :-- |
| :------ | :------ |
| `graph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `Record`<`string`, `any`\>, `Record`<`string`, `any`\>, `string`\> |

@@ -361,5 +361,5 @@

[algorithm/tarjan.ts:16](https://github.com/antvis/graphlib/blob/630e2c1/src/algorithm/tarjan.ts#L16)
[algorithm/tarjan.ts:16](https://github.com/antvis/graphlib/blob/7513e82/src/algorithm/tarjan.ts#L16)
---
___

@@ -372,4 +372,4 @@ ### topsort

| Name |
| :----------- |
| Name |
| :------ |
| `NodeIDType` |

@@ -380,3 +380,3 @@

| Name | Type |
| :-- | :-- |
| :------ | :------ |
| `graph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `Record`<`string`, `any`\>, `Record`<`string`, `any`\>, `string`\> |

@@ -390,2 +390,2 @@

[algorithm/topsort.ts:5](https://github.com/antvis/graphlib/blob/630e2c1/src/algorithm/topsort.ts#L5)
[algorithm/topsort.ts:5](https://github.com/antvis/graphlib/blob/7513e82/src/algorithm/topsort.ts#L5)

@@ -15,2 +15,3 @@ [@antv/graphlib](../README.md) / [Exports](../modules.md) / comparision

- [getSameNodes](comparision.md#getsamenodes)
- [isGraphComplement](comparision.md#isgraphcomplement)
- [isGraphContainsAnother](comparision.md#isgraphcontainsanother)

@@ -32,11 +33,11 @@ - [isGraphOptionSame](comparision.md#isgraphoptionsame)

| Name | Type |
| :----------- | :---- |
| Name | Type |
| :------ | :------ |
| `NodeIDType` | `any` |
| `EdgeType` | `any` |
| `EdgeType` | `any` |
#### Parameters
| Name | Type |
| :------- | :---------------------------------------------------------------------- |
| Name | Type |
| :------ | :------ |
| `aGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `EdgeType`, `any`\> |

@@ -51,5 +52,5 @@ | `bGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `EdgeType`, `any`\> |

[comparison.ts:96](https://github.com/antvis/graphlib/blob/630e2c1/src/comparison.ts#L96)
[comparision/contain.ts:102](https://github.com/antvis/graphlib/blob/7513e82/src/comparision/contain.ts#L102)
---
___

@@ -66,4 +67,4 @@ ### containAllSameNodes

| Name | Type |
| :----------- | :---- |
| Name | Type |
| :------ | :------ |
| `NodeIDType` | `any` |

@@ -73,4 +74,4 @@

| Name | Type |
| :------- | :----------------------------------------------------------------- |
| Name | Type |
| :------ | :------ |
| `aGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `any`, `any`\> |

@@ -85,5 +86,5 @@ | `bGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `any`, `any`\> |

[comparison.ts:84](https://github.com/antvis/graphlib/blob/630e2c1/src/comparison.ts#L84)
[comparision/contain.ts:90](https://github.com/antvis/graphlib/blob/7513e82/src/comparision/contain.ts#L90)
---
___

@@ -100,4 +101,4 @@ ### containSameEdges

| Name | Type |
| :----------- | :---- |
| Name | Type |
| :------ | :------ |
| `NodeIDType` | `any` |

@@ -108,5 +109,5 @@

| Name | Type |
| :-- | :-- |
| `aGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `Record`<`string`, `any`\>, `Record`<`string`, `any`\>, `string`\> |
| `bGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `Record`<`string`, `any`\>, `Record`<`string`, `any`\>, `string`\> |
| :------ | :------ |
| `aGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `any`, `string`\> |
| `bGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `any`, `string`\> |

@@ -119,5 +120,5 @@ #### Returns

[comparison.ts:25](https://github.com/antvis/graphlib/blob/630e2c1/src/comparison.ts#L25)
[comparision/contain.ts:31](https://github.com/antvis/graphlib/blob/7513e82/src/comparision/contain.ts#L31)
---
___

@@ -134,4 +135,4 @@ ### containSameNodes

| Name | Type |
| :----------- | :---- |
| Name | Type |
| :------ | :------ |
| `NodeIDType` | `any` |

@@ -142,3 +143,3 @@

| Name | Type |
| :-- | :-- |
| :------ | :------ |
| `aGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `Record`<`string`, `any`\>, `Record`<`string`, `any`\>, `string`\> |

@@ -153,5 +154,5 @@ | `bGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `Record`<`string`, `any`\>, `Record`<`string`, `any`\>, `string`\> |

[comparison.ts:7](https://github.com/antvis/graphlib/blob/630e2c1/src/comparison.ts#L7)
[comparision/contain.ts:13](https://github.com/antvis/graphlib/blob/7513e82/src/comparision/contain.ts#L13)
---
___

@@ -168,11 +169,11 @@ ### getSameEdges

| Name | Type |
| :----------- | :---- |
| Name | Type |
| :------ | :------ |
| `NodeIDType` | `any` |
| `EdgeType` | `any` |
| `EdgeType` | `any` |
#### Parameters
| Name | Type |
| :------- | :---------------------------------------------------------------------- |
| Name | Type |
| :------ | :------ |
| `aGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `EdgeType`, `any`\> |

@@ -187,5 +188,5 @@ | `bGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `EdgeType`, `any`\> |

[comparison.ts:56](https://github.com/antvis/graphlib/blob/630e2c1/src/comparison.ts#L56)
[comparision/contain.ts:62](https://github.com/antvis/graphlib/blob/7513e82/src/comparision/contain.ts#L62)
---
___

@@ -202,4 +203,4 @@ ### getSameNodes

| Name | Type |
| :----------- | :---- |
| Name | Type |
| :------ | :------ |
| `NodeIDType` | `any` |

@@ -210,3 +211,3 @@

| Name | Type |
| :-- | :-- |
| :------ | :------ |
| `aGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `Record`<`string`, `any`\>, `Record`<`string`, `any`\>, `string`\> |

@@ -221,6 +222,38 @@ | `bGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `Record`<`string`, `any`\>, `Record`<`string`, `any`\>, `string`\> |

[comparison.ts:43](https://github.com/antvis/graphlib/blob/630e2c1/src/comparison.ts#L43)
[comparision/contain.ts:49](https://github.com/antvis/graphlib/blob/7513e82/src/comparision/contain.ts#L49)
---
___
### isGraphComplement
▸ **isGraphComplement**<`NodeIDType`, `EdgeType`\>(`originGraph`, `targetGraph`): `boolean`
**`description`** Check if one graph is the complement of another graph.
**`description.zh-cn`** 检查一个图是否是另一个图的补图。
#### Type parameters
| Name | Type |
| :------ | :------ |
| `NodeIDType` | `any` |
| `EdgeType` | `any` |
#### Parameters
| Name | Type |
| :------ | :------ |
| `originGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `EdgeType`, `any`\> |
| `targetGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `EdgeType`, `any`\> |
#### Returns
`boolean`
#### Defined in
[comparision/complement.ts:9](https://github.com/antvis/graphlib/blob/7513e82/src/comparision/complement.ts#L9)
___
### isGraphContainsAnother

@@ -236,11 +269,11 @@

| Name | Type |
| :----------- | :---- |
| Name | Type |
| :------ | :------ |
| `NodeIDType` | `any` |
| `EdgeType` | `any` |
| `EdgeType` | `any` |
#### Parameters
| Name | Type |
| :------------ | :---------------------------------------------------------------------- |
| Name | Type |
| :------ | :------ |
| `originGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `EdgeType`, `any`\> |

@@ -255,5 +288,5 @@ | `targetGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `EdgeType`, `any`\> |

[comparison.ts:125](https://github.com/antvis/graphlib/blob/630e2c1/src/comparison.ts#L125)
[comparision/contain.ts:131](https://github.com/antvis/graphlib/blob/7513e82/src/comparision/contain.ts#L131)
---
___

@@ -270,11 +303,11 @@ ### isGraphOptionSame

| Name | Type |
| :----------- | :---- |
| Name | Type |
| :------ | :------ |
| `NodeIDType` | `any` |
| `EdgeType` | `any` |
| `EdgeType` | `any` |
#### Parameters
| Name | Type |
| :------- | :---------------------------------------------------------------------- |
| Name | Type |
| :------ | :------ |
| `aGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `EdgeType`, `any`\> |

@@ -289,5 +322,5 @@ | `bGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `EdgeType`, `any`\> |

[comparison.ts:69](https://github.com/antvis/graphlib/blob/630e2c1/src/comparison.ts#L69)
[comparision/contain.ts:75](https://github.com/antvis/graphlib/blob/7513e82/src/comparision/contain.ts#L75)
---
___

@@ -304,11 +337,11 @@ ### isGraphSame

| Name | Type |
| :----------- | :---- |
| Name | Type |
| :------ | :------ |
| `NodeIDType` | `any` |
| `EdgeType` | `any` |
| `EdgeType` | `any` |
#### Parameters
| Name | Type |
| :------- | :---------------------------------------------------------------------- |
| Name | Type |
| :------ | :------ |
| `aGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `EdgeType`, `any`\> |

@@ -323,2 +356,2 @@ | `bGraph` | [`Graph`](../classes/Graph.md)<`NodeIDType`, `any`, `EdgeType`, `any`\> |

[comparison.ts:108](https://github.com/antvis/graphlib/blob/630e2c1/src/comparison.ts#L108)
[comparision/contain.ts:114](https://github.com/antvis/graphlib/blob/7513e82/src/comparision/contain.ts#L114)

@@ -5,4 +5,36 @@ @antv/graphlib / [Exports](modules.md)

> a lib containing multible usages for graph structure, graph algorithm, and other graph ops. 一个包含方便的图结构,图算法,以及其他操作图的方法的图库,为 antv 上层提供相应的图基础能力
> a lib containing multible usages for graph structure, graph algorithm, and other graph ops.
>
> 一个包含方便的图结构,图算法,以及其他操作图的方法的图库,为 antv 上层提供相应的图基础能力
![build status](https://img.shields.io/github/workflow/status/antvis/graphlib/Build) ![coverage status](https://img.shields.io/codecov/c/github/antvis/graphlib)
## Content of Package
### Namespaces
- [algorithm](docs/modules/algorithm.md)
- [comparision](docs/modules/comparision.md)
### Classes
- [Graph](docs/classes/Graph.md)
### Functions
- [isGraph](docs/modules.md#isgraph)
## Change Log
#### 1.1.0
- 🎉 Now we have comparision module for graph comparing with nodes/edges/options even subgraph
- 💪 Add isGraph to check if a object is a "Graph", and add a self loop checking function
#### 1.0.1
- 🔨 Completes test and bring all to 100%
#### 1.0.0
- 🎉 Release new graphlib with graph and algorithm

@@ -13,3 +13,3 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

import PriorityQueue from '../PriorityQueue';
import PriorityQueue from './PriorityQueue';

@@ -16,0 +16,0 @@ var DEFAULT_WEIGHT_FUNC = function DEFAULT_WEIGHT_FUNC() {

import Graph from '../Graph';
import PriorityQueue from '../PriorityQueue';
import PriorityQueue from './PriorityQueue';

@@ -4,0 +4,0 @@ var prim = function prim(graph, weightFn) {

@@ -188,3 +188,3 @@ export interface GraphOption {

*/
setNode: (node: NodeIDType, value?: NodeType | undefined) => this;
setNode(node: NodeIDType, value?: NodeType): this;
/**

@@ -279,3 +279,3 @@ * @description Set nodes or add nodes in batch

*/
removeNode: (node: NodeIDType) => this;
removeNode(node: NodeIDType): this;
/**

@@ -303,3 +303,3 @@ * @description Set function that generate default label for edge, if param is non-function value then default label will always be this value;

*/
setEdge: (v_: NodeIDType, w_: NodeIDType, value?: any, name?: string | undefined) => this;
setEdge(v_: NodeIDType, w_: NodeIDType, value?: any, name?: string): this;
setEdgeObj: (edgeObj: DefaultEdgeType<NodeIDType, EdgeType>, value?: EdgeType | undefined) => this;

@@ -351,3 +351,3 @@ /**

*/
removeEdge: (v_: NodeIDType, w_: NodeIDType, name?: any) => this;
removeEdge(v_: NodeIDType, w_: NodeIDType, name?: any): this;
/**

@@ -446,7 +446,2 @@ * @description remove a specific edge by edge object

target: (edge: DefaultEdgeType<NodeIDType, EdgeType>) => NodeIDType;
/**
* @description Count the total edges with self loop
* @description.zh-CN 计算节点的自环边的数量
*/
countSelfLoops: () => number;
}

@@ -7,8 +7,4 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

@@ -18,6 +14,4 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
import { edgeArgsToId, isFunction } from '../util';
import { GraphEnum } from '../enum';
import { GraphEnum } from './enum';
import { decrementOrRemoveEntry, edgeArgsToObj, edgeObjToId, incrementOrInitEntry } from '../util';

@@ -31,621 +25,647 @@ import { read, write } from './toJSON';

var Graph = /*#__PURE__*/_createClass( // Graph option or basic props
var Graph = /*#__PURE__*/function () {
// Graph option or basic props
/**
* @description Label for this graph itself
* @description.zh-CN 图本身的标签(label)
* @default undefined
*/
/**
* @description Label for this graph itself
* @description.zh-CN 图本身的标签(label)
* @default undefined
*/
/**
* @description Number of nodes in the graph
* @description.zh-CN 节点的数量
* @default 0
*/
/**
* @description Number of nodes in the graph
* @description.zh-CN 节点的数量
* @default 0
*/
/**
* @description Number of edges in the graph
* @description.zh-CN 节点的数量
* @default 0
*/
/**
* @description Number of edges in the graph
* @description.zh-CN 节点的数量
* @default 0
*/
/**
* @description return node label with its id
* @description.zh-CN 返回节点的默认的标签
*/
/**
* @description return node label with its id
* @description.zh-CN 返回节点的默认的标签
*/
/**
* @description return edge label with its id
* @description.zh-CN 返回边的默认的标签
*/
function Graph() {
var _this = this;
/**
* @description return edge label with its id
* @description.zh-CN 返回边的默认的标签
*/
function Graph() {
var _this = this;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Graph);
_classCallCheck(this, Graph);
this.directed = true;
this.multigraph = false;
this.compound = false;
this.GRAPH_NODE = GraphEnum.GRAPH_NODE;
this.label = void 0;
this.nodeCountNum = 0;
this.edgeCountNum = 0;
this.directed = true;
this.multigraph = false;
this.compound = false;
this.GRAPH_NODE = GraphEnum.GRAPH_NODE;
this.label = void 0;
this.nodeCountNum = 0;
this.edgeCountNum = 0;
this.defaultNodeLabelFn = function () {
return undefined;
};
this.defaultNodeLabelFn = function () {
return undefined;
};
this.defaultEdgeLabelFn = function () {
return undefined;
};
this.defaultEdgeLabelFn = function () {
return undefined;
};
this.parentMap = void 0;
this.childrenMap = void 0;
this.nodesLabelMap = new Map();
this.inEdgesMap = new Map();
this.outEdgesMap = new Map();
this.predecessorsMap = new Map();
this.successorsMap = new Map();
this.edgesMap = new Map();
this.edgesLabelsMap = new Map();
this.parentMap = void 0;
this.childrenMap = void 0;
this.nodesLabelMap = new Map();
this.inEdgesMap = new Map();
this.outEdgesMap = new Map();
this.predecessorsMap = new Map();
this.successorsMap = new Map();
this.edgesMap = new Map();
this.edgesLabelsMap = new Map();
this.isDirected = function () {
return _this.directed;
};
this.isDirected = function () {
return _this.directed;
};
this.isMultigraph = function () {
return _this.multigraph;
};
this.isMultigraph = function () {
return _this.multigraph;
};
this.isCompound = function () {
return _this.compound;
};
this.isCompound = function () {
return _this.compound;
};
this.setGraph = function (label) {
_this.label = label;
return _this;
};
this.setGraph = function (label) {
_this.label = label;
return _this;
};
this.graph = function () {
return _this.label;
};
this.graph = function () {
return _this.label;
};
this.setDefaultNodeLabel = function (newDefault) {
if (isFunction(newDefault)) {
_this.defaultNodeLabelFn = newDefault;
} else {
_this.defaultNodeLabelFn = function () {
return newDefault;
};
}
this.setDefaultNodeLabel = function (newDefault) {
if (isFunction(newDefault)) {
_this.defaultNodeLabelFn = newDefault;
} else {
_this.defaultNodeLabelFn = function () {
return newDefault;
};
}
return _this;
};
return _this;
};
this.nodeCount = function () {
return _this.nodeCountNum;
};
this.nodeCount = function () {
return _this.nodeCountNum;
};
this.node = function (n) {
return _this.nodesLabelMap.get(n);
};
this.node = function (n) {
return _this.nodesLabelMap.get(n);
};
this.nodes = function () {
return Array.from(_this.nodesLabelMap.keys());
};
this.nodes = function () {
return Array.from(_this.nodesLabelMap.keys());
};
this.sources = function () {
return _this.nodes().filter(function (n) {
var _this$inEdgesMap$get;
this.sources = function () {
return _this.nodes().filter(function (n) {
var _this$inEdgesMap$get;
return !((_this$inEdgesMap$get = _this.inEdgesMap.get(n)) === null || _this$inEdgesMap$get === void 0 ? void 0 : _this$inEdgesMap$get.size);
});
};
return !((_this$inEdgesMap$get = _this.inEdgesMap.get(n)) === null || _this$inEdgesMap$get === void 0 ? void 0 : _this$inEdgesMap$get.size);
});
};
this.sinks = function () {
return _this.nodes().filter(function (n) {
var _this$outEdgesMap$get;
this.sinks = function () {
return _this.nodes().filter(function (n) {
var _this$outEdgesMap$get;
return !((_this$outEdgesMap$get = _this.outEdgesMap.get(n)) === null || _this$outEdgesMap$get === void 0 ? void 0 : _this$outEdgesMap$get.size);
});
};
return !((_this$outEdgesMap$get = _this.outEdgesMap.get(n)) === null || _this$outEdgesMap$get === void 0 ? void 0 : _this$outEdgesMap$get.size);
});
};
this.setNode = function (node, value) {
var nodesLabelMap = _this.nodesLabelMap,
defaultNodeLabelFn = _this.defaultNodeLabelFn,
isCompound = _this.isCompound,
parentMap = _this.parentMap,
childrenMap = _this.childrenMap,
inEdgesMap = _this.inEdgesMap,
outEdgesMap = _this.outEdgesMap,
predecessorsMap = _this.predecessorsMap,
successorsMap = _this.successorsMap; // 如果节点不在图中,则创建节点
this.setNodes = function (nodes, value) {
nodes.map(function (node) {
return _this.setNode(node, value);
});
return _this;
};
if (nodesLabelMap.has(node)) {
if (value !== undefined) {
nodesLabelMap.set(node, value);
this.hasNode = function (node) {
return _this.nodesLabelMap.has(node);
};
this.checkCompound = function () {
if (!_this.isCompound()) {
throw new Error('Cannot construct parent-children relations in a non-compound graph');
}
};
return _this;
}
this.parent = function (node) {
if (_this.isCompound()) {
var _this$parentMap;
nodesLabelMap.set(node, value || defaultNodeLabelFn(node)); // 如果是复合图,则创建节点的子节点
var parent = (_this$parentMap = _this.parentMap) === null || _this$parentMap === void 0 ? void 0 : _this$parentMap.get(node);
if (isCompound()) {
var _childrenMap$get;
parentMap === null || parentMap === void 0 ? void 0 : parentMap.set(node, _this.GRAPH_NODE);
childrenMap === null || childrenMap === void 0 ? void 0 : childrenMap.set(node, new Map());
if (!(childrenMap === null || childrenMap === void 0 ? void 0 : childrenMap.has(_this.GRAPH_NODE))) {
childrenMap === null || childrenMap === void 0 ? void 0 : childrenMap.set(_this.GRAPH_NODE, new Map());
if (parent !== _this.GRAPH_NODE) {
return parent;
}
}
};
childrenMap === null || childrenMap === void 0 ? void 0 : (_childrenMap$get = childrenMap.get(_this.GRAPH_NODE)) === null || _childrenMap$get === void 0 ? void 0 : _childrenMap$get.set(node, true);
}
this.removeFromParentsChildList = function (node) {
var targetParent = _this.parentMap.get(node);
[inEdgesMap, outEdgesMap, predecessorsMap, successorsMap].forEach(function (map) {
return map.set(node, new Map());
});
_this.nodeCountNum += 1;
return _this;
};
_this.childrenMap.get(targetParent).delete(node);
};
this.setNodes = function (nodes, value) {
nodes.map(function (node) {
return _this.setNode(node, value);
});
return _this;
};
this.setParent = function (node, parent) {
var _this$parentMap2, _this$childrenMap;
this.hasNode = function (node) {
return _this.nodesLabelMap.has(node);
};
_this.checkCompound();
this.checkCompound = function () {
if (!_this.isCompound()) {
throw new Error('Cannot construct parent-children relations in a non-compound graph');
}
};
var realParent = parent === undefined ? _this.GRAPH_NODE : parent;
this.parent = function (node) {
if (_this.isCompound()) {
var _this$parentMap;
var checkNode = _this.parent(realParent);
var parent = (_this$parentMap = _this.parentMap) === null || _this$parentMap === void 0 ? void 0 : _this$parentMap.get(node);
while (checkNode) {
if (node === checkNode) {
throw new Error('Setting ' + parent + ' as parent of ' + node + ' would create a cycle');
}
if (parent !== _this.GRAPH_NODE) {
return parent;
checkNode = _this.parent(checkNode);
}
}
};
this.removeFromParentsChildList = function (node) {
var targetParent = _this.parentMap.get(node);
_this.childrenMap.get(targetParent).delete(node);
};
this.setParent = function (node, parent) {
var _this$parentMap2, _this$childrenMap;
_this.checkCompound();
var realParent = parent === undefined ? _this.GRAPH_NODE : parent;
var checkNode = _this.parent(realParent);
while (checkNode) {
if (node === checkNode) {
throw new Error('Setting ' + parent + ' as parent of ' + node + ' would create a cycle');
if (parent) {
_this.setNode(parent);
}
checkNode = _this.parent(checkNode);
}
_this.setNode(node);
if (parent) {
_this.setNode(parent);
}
_this.removeFromParentsChildList(node);
_this.setNode(node);
(_this$parentMap2 = _this.parentMap) === null || _this$parentMap2 === void 0 ? void 0 : _this$parentMap2.set(node, realParent);
_this.removeFromParentsChildList(node);
var realParentChilren = _this.childrenMap.get(realParent);
(_this$parentMap2 = _this.parentMap) === null || _this$parentMap2 === void 0 ? void 0 : _this$parentMap2.set(node, realParent);
realParentChilren.set(node, true);
(_this$childrenMap = _this.childrenMap) === null || _this$childrenMap === void 0 ? void 0 : _this$childrenMap.set(realParent, realParentChilren);
return _this;
};
var realParentChilren = _this.childrenMap.get(realParent);
this.children = function (node) {
var targetNode = node === undefined ? _this.GRAPH_NODE : node;
realParentChilren.set(node, true);
(_this$childrenMap = _this.childrenMap) === null || _this$childrenMap === void 0 ? void 0 : _this$childrenMap.set(realParent, realParentChilren);
return _this;
};
if (_this.isCompound()) {
var _this$childrenMap2;
this.children = function (node) {
var targetNode = node === undefined ? _this.GRAPH_NODE : node;
var target = (_this$childrenMap2 = _this.childrenMap) === null || _this$childrenMap2 === void 0 ? void 0 : _this$childrenMap2.get(targetNode);
if (_this.isCompound()) {
var _this$childrenMap2;
if (target) {
return Array.from(target.keys());
}
var target = (_this$childrenMap2 = _this.childrenMap) === null || _this$childrenMap2 === void 0 ? void 0 : _this$childrenMap2.get(targetNode);
return undefined;
}
if (target) {
return Array.from(target.keys());
if (targetNode === _this.GRAPH_NODE) {
return _this.nodes();
}
return undefined;
}
if (node && _this.hasNode(node)) {
return [];
}
};
if (targetNode === _this.GRAPH_NODE) {
return _this.nodes();
}
this.predecessors = function (node) {
var preds = _this.predecessorsMap.get(node);
if (node && _this.hasNode(node)) {
return [];
}
};
return preds ? Array.from(preds.keys()) : undefined;
};
this.predecessors = function (node) {
var preds = _this.predecessorsMap.get(node);
this.successors = function (node) {
var succs = _this.successorsMap.get(node);
return preds ? Array.from(preds.keys()) : undefined;
};
return succs ? Array.from(succs.keys()) : undefined;
};
this.successors = function (node) {
var succs = _this.successorsMap.get(node);
this.neighbors = function (node) {
var _this$predecessors;
return succs ? Array.from(succs.keys()) : undefined;
};
if (!_this.hasNode(node)) {
return undefined;
}
this.neighbors = function (node) {
var _this$predecessors;
return Array.from(new Set((_this$predecessors = _this.predecessors(node)) === null || _this$predecessors === void 0 ? void 0 : _this$predecessors.concat(_this.successors(node))));
};
if (!_this.hasNode(node)) {
return undefined;
}
this.isLeaf = function (node) {
var _this$neighbors;
return Array.from(new Set((_this$predecessors = _this.predecessors(node)) === null || _this$predecessors === void 0 ? void 0 : _this$predecessors.concat(_this.successors(node))));
};
if (_this.isDirected()) {
var _this$successors;
this.isLeaf = function (node) {
var _this$neighbors;
if (_this.isDirected()) {
var _this$successors;
return !((_this$successors = _this.successors(node)) === null || _this$successors === void 0 ? void 0 : _this$successors.length);
}
return !((_this$neighbors = _this.neighbors(node)) === null || _this$neighbors === void 0 ? void 0 : _this$neighbors.length);
};
this.filterNodes = function (filter) {
var directed = _this.directed,
multigraph = _this.multigraph,
compound = _this.compound;
var copyGraph = new Graph({
directed: directed,
multigraph: multigraph,
compound: compound
});
copyGraph.setGraph(_this.graph());
_this.nodes().forEach(function (n) {
if (filter(n)) {
copyGraph.setNode(n, _this.node(n));
return !((_this$successors = _this.successors(node)) === null || _this$successors === void 0 ? void 0 : _this$successors.length);
}
});
_this.edges().forEach(function (edgeObj) {
if (copyGraph.hasNode(edgeObj.v) && copyGraph.hasNode(edgeObj.w)) {
copyGraph.setEdgeObj(edgeObj, _this.edge(edgeObj));
}
});
return !((_this$neighbors = _this.neighbors(node)) === null || _this$neighbors === void 0 ? void 0 : _this$neighbors.length);
};
if (compound) {
var findParent = function findParent(node) {
var parent = _this.parent(node);
this.filterNodes = function (filter) {
var directed = _this.directed,
multigraph = _this.multigraph,
compound = _this.compound;
var copyGraph = new Graph({
directed: directed,
multigraph: multigraph,
compound: compound
});
copyGraph.setGraph(_this.graph());
while (parent !== undefined && !copyGraph.hasNode(parent)) {
parent = _this.parent(parent);
_this.nodes().forEach(function (n) {
if (filter(n)) {
copyGraph.setNode(n, _this.node(n));
}
});
return parent;
};
copyGraph.nodes().forEach(function (node) {
copyGraph.setParent(node, findParent(node));
_this.edges().forEach(function (edgeObj) {
if (copyGraph.hasNode(edgeObj.v) && copyGraph.hasNode(edgeObj.w)) {
copyGraph.setEdgeObj(edgeObj, _this.edge(edgeObj));
}
});
}
return copyGraph;
};
if (compound) {
var findParent = function findParent(node) {
var parent = _this.parent(node);
this.removeNode = function (node) {
if (_this.hasNode(node)) {
var cleanEdge = function cleanEdge(edgeObj) {
_this.removeEdge(edgeObj.v, edgeObj.w, edgeObj.name);
};
while (parent !== undefined && !copyGraph.hasNode(parent)) {
parent = _this.parent(parent);
}
var inEdgesMap = _this.inEdgesMap,
outEdgesMap = _this.outEdgesMap,
predecessorsMap = _this.predecessorsMap,
successorsMap = _this.successorsMap,
nodesLabelMap = _this.nodesLabelMap;
return parent;
};
if (_this.isCompound()) {
var _this$parentMap3, _this$children, _this$childrenMap3;
_this.removeFromParentsChildList(node);
(_this$parentMap3 = _this.parentMap) === null || _this$parentMap3 === void 0 ? void 0 : _this$parentMap3.delete(node);
(_this$children = _this.children(node)) === null || _this$children === void 0 ? void 0 : _this$children.forEach(function (n) {
return _this.setParent(n);
copyGraph.nodes().forEach(function (node) {
copyGraph.setParent(node, findParent(node));
});
(_this$childrenMap3 = _this.childrenMap) === null || _this$childrenMap3 === void 0 ? void 0 : _this$childrenMap3.delete(node);
}
var inE = inEdgesMap.get(node);
var outE = outEdgesMap.get(node);
Array.from(inE.values()).forEach(function (edge) {
return cleanEdge(edge);
});
Array.from(outE.values()).forEach(function (edge) {
return cleanEdge(edge);
});
nodesLabelMap.delete(node);
inEdgesMap.delete(node);
outEdgesMap.delete(node);
predecessorsMap.delete(node);
successorsMap.delete(node);
_this.nodeCountNum -= 1;
}
return copyGraph;
};
return _this;
};
this.setDefaultEdgeLabel = function (newDefault) {
if (isFunction(newDefault)) {
_this.defaultEdgeLabelFn = newDefault;
} else {
_this.defaultEdgeLabelFn = function () {
return newDefault;
};
}
this.setDefaultEdgeLabel = function (newDefault) {
if (isFunction(newDefault)) {
_this.defaultEdgeLabelFn = newDefault;
} else {
_this.defaultEdgeLabelFn = function () {
return newDefault;
};
}
return _this;
};
return _this;
};
this.edgeCount = function () {
return _this.edgeCountNum;
};
this.edgeCount = function () {
return _this.edgeCountNum;
};
this.setEdgeObj = function (edgeObj, value) {
return _this.setEdge(edgeObj.v, edgeObj.w, value, edgeObj.name);
};
this.setEdge = function (v_, w_, value, name) {
var _this$inEdgesMap$get2, _this$outEdgesMap$get2;
this.setPath = function (edges, value) {
edges.reduce(function (v, w) {
_this.setEdge(v, w, value);
var edgeObj = edgeArgsToObj(_this.isDirected(), v_, w_, name);
var edgeId = edgeObjToId(_this.isDirected(), edgeObj);
var v = edgeObj.v,
w = edgeObj.w;
return w;
});
return _this;
};
if (_this.edgesLabelsMap.has(edgeId)) {
_this.edgesLabelsMap.set(edgeId, value);
this.edgeFromArgs = function (v, w, name) {
return _this.edge({
v: v,
w: w,
name: name
});
};
return _this;
}
this.edge = function (edgeObj) {
return _this.edgesLabelsMap.get(edgeObjToId(_this.isDirected(), edgeObj));
};
if (name !== undefined && !_this.isMultigraph()) {
throw new Error('Cannot set a named edge when isMultigraph = false');
}
this.hasEdge = function (v, w, name) {
return _this.edgesLabelsMap.has(edgeObjToId(_this.isDirected(), {
v: v,
w: w,
name: name
}));
};
_this.setNode(v);
this.removeEdgeObj = function (_ref) {
var v = _ref.v,
w = _ref.w,
name = _ref.name;
return _this.removeEdge(v, w, name);
};
_this.setNode(w);
this.edges = function () {
return Array.from(_this.edgesMap.values());
};
_this.edgesLabelsMap.set(edgeId, value || _this.defaultEdgeLabelFn(v, w, name));
this.inEdges = function (v, u) {
var inV = _this.inEdgesMap.get(v);
Object.freeze(edgeObj);
if (inV) {
return Array.from(inV.values()).filter(function (e) {
return !u || e.v === u;
});
}
_this.edgesMap.set(edgeId, edgeObj);
return undefined;
};
var preds = _this.predecessorsMap.get(w);
this.outEdges = function (w, u) {
var outW = _this.outEdgesMap.get(w);
var succs = _this.successorsMap.get(v);
if (outW) {
return Array.from(outW.values()).filter(function (e) {
return !u || e.w === u;
});
}
incrementOrInitEntry(preds, v);
incrementOrInitEntry(succs, w);
(_this$inEdgesMap$get2 = _this.inEdgesMap.get(w)) === null || _this$inEdgesMap$get2 === void 0 ? void 0 : _this$inEdgesMap$get2.set(edgeId, edgeObj);
(_this$outEdgesMap$get2 = _this.outEdgesMap.get(v)) === null || _this$outEdgesMap$get2 === void 0 ? void 0 : _this$outEdgesMap$get2.set(edgeId, edgeObj);
_this.edgeCountNum += 1;
return _this;
};
return undefined;
};
this.setEdgeObj = function (edgeObj, value) {
return _this.setEdge(edgeObj.v, edgeObj.w, value, edgeObj.name);
};
this.nodeEdges = function (v, w) {
var _this$inEdges;
this.setPath = function (edges, value) {
edges.reduce(function (v, w) {
_this.setEdge(v, w, value);
if (!_this.hasNode(v)) {
return undefined;
}
return w;
});
return _this;
};
return (_this$inEdges = _this.inEdges(v, w)) === null || _this$inEdges === void 0 ? void 0 : _this$inEdges.concat(_this.outEdges(v, w));
};
this.edgeFromArgs = function (v, w, name) {
return _this.edge({
v: v,
w: w,
name: name
});
};
this.toJSON = function () {
return write(_this);
};
this.edge = function (edgeObj) {
return _this.edgesLabelsMap.get(edgeObjToId(_this.isDirected(), edgeObj));
};
this.nodeInDegree = function (node) {
var inEdges = _this.inEdgesMap.get(node);
this.hasEdge = function (v, w, name) {
return _this.edgesLabelsMap.has(edgeObjToId(_this.isDirected(), {
v: v,
w: w,
name: name
}));
};
if (inEdges) {
return inEdges.size;
}
this.removeEdge = function (v_, w_, name) {
var edgeId = edgeArgsToId(_this.isDirected(), v_, w_, name);
return 0;
};
var edgeObj = _this.edgesMap.get(edgeId);
this.nodeOutDegree = function (node) {
var outEdges = _this.outEdgesMap.get(node);
if (edgeObj) {
var _edgeArgsToObj = edgeArgsToObj(_this.isDirected(), v_, w_, name),
v = _edgeArgsToObj.v,
w = _edgeArgsToObj.w;
if (outEdges) {
return outEdges.size;
}
_this.edgesLabelsMap.delete(edgeId);
return 0;
};
_this.edgesMap.delete(edgeId);
this.nodeDegree = function (node) {
return _this.nodeInDegree(node) + _this.nodeOutDegree(node);
};
var preds = _this.predecessorsMap.get(w);
this.source = function (edge) {
return edge.v;
};
var succs = _this.successorsMap.get(v);
this.target = function (edge) {
return edge.w;
};
decrementOrRemoveEntry(preds, v);
decrementOrRemoveEntry(succs, w);
var resultOptions = _objectSpread(_objectSpread({}, defaultOption), options);
_this.inEdgesMap.get(w).delete(edgeId);
this.compound = resultOptions.compound;
this.directed = resultOptions.directed;
this.multigraph = resultOptions.multigraph;
_this.outEdgesMap.get(v).delete(edgeId);
_this.edgeCountNum -= 1;
if (this.compound) {
this.parentMap = new Map();
this.childrenMap = new Map();
}
} // Map for graph
return _this;
};
/**
* @description Map for parent relationship
* @description.zh-CN 父子关系的映射
*/
this.removeEdgeObj = function (_ref) {
var v = _ref.v,
w = _ref.w,
name = _ref.name;
return _this.removeEdge(v, w, name);
};
this.edges = function () {
return Array.from(_this.edgesMap.values());
};
_createClass(Graph, [{
key: "setNode",
value:
/**
* @description Set Node label in graph if node not in graph then create it
* @description.zh-CN 设置节点的label,如果这个节点不在图中,则在图中创建这个节点
* @param node
* @param value
* @returns
*/
function setNode(node, value) {
var nodesLabelMap = this.nodesLabelMap,
defaultNodeLabelFn = this.defaultNodeLabelFn,
isCompound = this.isCompound,
parentMap = this.parentMap,
childrenMap = this.childrenMap,
inEdgesMap = this.inEdgesMap,
outEdgesMap = this.outEdgesMap,
predecessorsMap = this.predecessorsMap,
successorsMap = this.successorsMap; // 如果节点不在图中,则创建节点
this.inEdges = function (v, u) {
var inV = _this.inEdgesMap.get(v);
if (nodesLabelMap.has(node)) {
if (value !== undefined) {
nodesLabelMap.set(node, value);
}
if (inV) {
return Array.from(inV.values()).filter(function (e) {
return !u || e.v === u;
});
}
return this;
}
return undefined;
};
nodesLabelMap.set(node, value || defaultNodeLabelFn(node)); // 如果是复合图,则创建节点的子节点
this.outEdges = function (w, u) {
var outW = _this.outEdgesMap.get(w);
if (isCompound()) {
var _childrenMap$get;
if (outW) {
return Array.from(outW.values()).filter(function (e) {
return !u || e.w === u;
});
}
parentMap === null || parentMap === void 0 ? void 0 : parentMap.set(node, this.GRAPH_NODE);
childrenMap === null || childrenMap === void 0 ? void 0 : childrenMap.set(node, new Map());
return undefined;
};
if (!(childrenMap === null || childrenMap === void 0 ? void 0 : childrenMap.has(this.GRAPH_NODE))) {
childrenMap === null || childrenMap === void 0 ? void 0 : childrenMap.set(this.GRAPH_NODE, new Map());
}
this.nodeEdges = function (v, w) {
var _this$inEdges;
childrenMap === null || childrenMap === void 0 ? void 0 : (_childrenMap$get = childrenMap.get(this.GRAPH_NODE)) === null || _childrenMap$get === void 0 ? void 0 : _childrenMap$get.set(node, true);
}
if (!_this.hasNode(v)) {
return undefined;
[inEdgesMap, outEdgesMap, predecessorsMap, successorsMap].forEach(function (map) {
return map.set(node, new Map());
});
this.nodeCountNum += 1;
return this;
}
/**
* @description Set nodes or add nodes in batch
* @description.zh-CN 批量设置或者创建节点
* @param nodes
* @param value
* @returns
*/
return (_this$inEdges = _this.inEdges(v, w)) === null || _this$inEdges === void 0 ? void 0 : _this$inEdges.concat(_this.outEdges(v, w));
};
}, {
key: "removeNode",
value:
/**
* @description Remove node from graph
* @description.zh-CN 将节点从图中移除
* @param node
* @returns
*/
function removeNode(node) {
var _this2 = this;
this.toJSON = function () {
return write(_this);
};
if (this.hasNode(node)) {
var cleanEdge = function cleanEdge(edgeObj) {
_this2.removeEdge(edgeObj.v, edgeObj.w, edgeObj.name);
};
this.nodeInDegree = function (node) {
var inEdges = _this.inEdgesMap.get(node);
var inEdgesMap = this.inEdgesMap,
outEdgesMap = this.outEdgesMap,
predecessorsMap = this.predecessorsMap,
successorsMap = this.successorsMap,
nodesLabelMap = this.nodesLabelMap;
if (inEdges) {
return inEdges.size;
}
if (this.isCompound()) {
var _this$parentMap3, _this$children, _this$childrenMap3;
return 0;
};
this.removeFromParentsChildList(node);
(_this$parentMap3 = this.parentMap) === null || _this$parentMap3 === void 0 ? void 0 : _this$parentMap3.delete(node);
(_this$children = this.children(node)) === null || _this$children === void 0 ? void 0 : _this$children.forEach(function (n) {
return _this2.setParent(n);
});
(_this$childrenMap3 = this.childrenMap) === null || _this$childrenMap3 === void 0 ? void 0 : _this$childrenMap3.delete(node);
}
this.nodeOutDegree = function (node) {
var outEdges = _this.outEdgesMap.get(node);
var inE = inEdgesMap.get(node);
var outE = outEdgesMap.get(node);
Array.from(inE.values()).forEach(function (edge) {
return cleanEdge(edge);
});
Array.from(outE.values()).forEach(function (edge) {
return cleanEdge(edge);
});
nodesLabelMap.delete(node);
inEdgesMap.delete(node);
outEdgesMap.delete(node);
predecessorsMap.delete(node);
successorsMap.delete(node);
this.nodeCountNum -= 1;
}
if (outEdges) {
return outEdges.size;
return this;
}
/**
* @description Set function that generate default label for edge, if param is non-function value then default label will always be this value;
* @description.zh-CN 设置默认获取边Label的方法,如果传入不是函数的,那么默认label 的值只会是传入值
* @param newDefault
* @returns
*/
return 0;
};
}, {
key: "setEdge",
value:
/**
* @description set edge value, if nodes or edges not exsit then add to graph
* @description.zh-CN 设置边的属性,如果边或节点不存在,那么将他们加入这个图
* @param v
* @param w
* @param value
* @param name
* @returns
*/
function setEdge(v_, w_, value, name) {
var _this$inEdgesMap$get2, _this$outEdgesMap$get2;
this.nodeDegree = function (node) {
return _this.nodeInDegree(node) + _this.nodeOutDegree(node);
};
var edgeObj = edgeArgsToObj(this.isDirected(), v_, w_, name);
var edgeId = edgeObjToId(this.isDirected(), edgeObj);
var v = edgeObj.v,
w = edgeObj.w;
this.source = function (edge) {
return edge.v;
};
if (this.edgesLabelsMap.has(edgeId)) {
this.edgesLabelsMap.set(edgeId, value);
return this;
}
this.target = function (edge) {
return edge.w;
};
if (name !== undefined && !this.isMultigraph()) {
throw new Error('Cannot set a named edge when isMultigraph = false');
}
this.countSelfLoops = function () {
var count = 0;
this.setNode(v);
this.setNode(w);
this.edgesLabelsMap.set(edgeId, value || this.defaultEdgeLabelFn(v, w, name));
Object.freeze(edgeObj);
this.edgesMap.set(edgeId, edgeObj);
var preds = this.predecessorsMap.get(w);
var succs = this.successorsMap.get(v);
incrementOrInitEntry(preds, v);
incrementOrInitEntry(succs, w);
(_this$inEdgesMap$get2 = this.inEdgesMap.get(w)) === null || _this$inEdgesMap$get2 === void 0 ? void 0 : _this$inEdgesMap$get2.set(edgeId, edgeObj);
(_this$outEdgesMap$get2 = this.outEdgesMap.get(v)) === null || _this$outEdgesMap$get2 === void 0 ? void 0 : _this$outEdgesMap$get2.set(edgeId, edgeObj);
this.edgeCountNum += 1;
return this;
}
}, {
key: "removeEdge",
value:
/**
* @description remove a specific edge
* @description.zh-CN 删除一条边
* @param v
* @param w
* @param name
* @returns
*/
function removeEdge(v_, w_, name) {
var edgeId = edgeArgsToId(this.isDirected(), v_, w_, name);
var edgeObj = this.edgesMap.get(edgeId);
var _iterator = _createForOfIteratorHelper(_this.edges()),
_step;
if (edgeObj) {
var _edgeArgsToObj = edgeArgsToObj(this.isDirected(), v_, w_, name),
v = _edgeArgsToObj.v,
w = _edgeArgsToObj.w;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var edge = _step.value;
this.edgesLabelsMap.delete(edgeId);
this.edgesMap.delete(edgeId);
var preds = this.predecessorsMap.get(w);
var succs = this.successorsMap.get(v);
decrementOrRemoveEntry(preds, v);
decrementOrRemoveEntry(succs, w);
this.inEdgesMap.get(w).delete(edgeId);
this.outEdgesMap.get(v).delete(edgeId);
this.edgeCountNum -= 1;
}
if (edge.v === edge.w) {
count += 1;
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
return this;
}
/**
* @description remove a specific edge by edge object
* @description.zh-CN 删除一条边
*/
return count;
};
}]);
var resultOptions = _objectSpread(_objectSpread({}, defaultOption), options);
return Graph;
}();
this.compound = resultOptions.compound;
this.directed = resultOptions.directed;
this.multigraph = resultOptions.multigraph;
if (this.compound) {
this.parentMap = new Map();
this.childrenMap = new Map();
}
} // Map for graph
/**
* @description Map for parent relationship
* @description.zh-CN 父子关系的映射
*/
);
Graph.fromJSON = read;
export { Graph as default };
import Graph from './Graph';
import { isGraph } from './util';
import { GraphWithEvent } from './Graph/event';
import * as algorithm from './algorithm';
import * as comparision from './comparison';
export { Graph, algorithm, isGraph, comparision };
import * as comparision from './comparision';
import * as essence from './essence';
import * as generate from './generate';
export { Graph, GraphWithEvent, algorithm, comparision, essence, generate };
import Graph from './Graph';
import { isGraph } from './util';
import { GraphWithEvent } from './Graph/event';
import * as algorithm from './algorithm';
import * as comparision from './comparison';
export { Graph, algorithm, isGraph, comparision };
import * as comparision from './comparision';
import * as essence from './essence';
import * as generate from './generate';
export { Graph, GraphWithEvent, algorithm, comparision, essence, generate };

@@ -34,2 +34,1 @@ import { DefaultEdgeType } from './Graph';

export declare function isFunction(obj: any): boolean;
export declare function isGraph(obj: any): boolean;

@@ -1,3 +0,2 @@

import { GraphEnum } from './enum';
import Graph from './Graph';
import { GraphEnum } from './Graph/enum';
/**

@@ -84,5 +83,2 @@ * @description add one to key's value in map

return typeof obj === 'function';
}
export function isGraph(obj) {
return obj instanceof Graph;
}

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var PriorityQueue_1 = __importDefault(require("../PriorityQueue"));
var PriorityQueue_1 = __importDefault(require("./PriorityQueue"));
var DEFAULT_WEIGHT_FUNC = function () { return 1; };

@@ -9,0 +9,0 @@ /**

@@ -7,3 +7,3 @@ "use strict";

var Graph_1 = __importDefault(require("../Graph"));
var PriorityQueue_1 = __importDefault(require("../PriorityQueue"));
var PriorityQueue_1 = __importDefault(require("./PriorityQueue"));
var prim = function (graph, weightFn) {

@@ -10,0 +10,0 @@ var _a;

@@ -188,3 +188,3 @@ export interface GraphOption {

*/
setNode: (node: NodeIDType, value?: NodeType | undefined) => this;
setNode(node: NodeIDType, value?: NodeType): this;
/**

@@ -279,3 +279,3 @@ * @description Set nodes or add nodes in batch

*/
removeNode: (node: NodeIDType) => this;
removeNode(node: NodeIDType): this;
/**

@@ -303,3 +303,3 @@ * @description Set function that generate default label for edge, if param is non-function value then default label will always be this value;

*/
setEdge: (v_: NodeIDType, w_: NodeIDType, value?: any, name?: string | undefined) => this;
setEdge(v_: NodeIDType, w_: NodeIDType, value?: any, name?: string): this;
setEdgeObj: (edgeObj: DefaultEdgeType<NodeIDType, EdgeType>, value?: EdgeType | undefined) => this;

@@ -351,3 +351,3 @@ /**

*/
removeEdge: (v_: NodeIDType, w_: NodeIDType, name?: any) => this;
removeEdge(v_: NodeIDType, w_: NodeIDType, name?: any): this;
/**

@@ -446,7 +446,2 @@ * @description remove a specific edge by edge object

target: (edge: DefaultEdgeType<NodeIDType, EdgeType>) => NodeIDType;
/**
* @description Count the total edges with self loop
* @description.zh-CN 计算节点的自环边的数量
*/
countSelfLoops: () => number;
}

@@ -15,3 +15,3 @@ "use strict";

var util_1 = require("../util");
var enum_1 = require("../enum");
var enum_1 = require("./enum");
var util_2 = require("../util");

@@ -161,35 +161,2 @@ var toJSON_1 = require("./toJSON");

/**
* @description Set Node label in graph if node not in graph then create it
* @description.zh-CN 设置节点的label,如果这个节点不在图中,则在图中创建这个节点
* @param node
* @param value
* @returns
*/
this.setNode = function (node, value) {
var _a;
var _b = _this, nodesLabelMap = _b.nodesLabelMap, defaultNodeLabelFn = _b.defaultNodeLabelFn, isCompound = _b.isCompound, parentMap = _b.parentMap, childrenMap = _b.childrenMap, inEdgesMap = _b.inEdgesMap, outEdgesMap = _b.outEdgesMap, predecessorsMap = _b.predecessorsMap, successorsMap = _b.successorsMap;
// 如果节点不在图中,则创建节点
if (nodesLabelMap.has(node)) {
if (value !== undefined) {
nodesLabelMap.set(node, value);
}
return _this;
}
nodesLabelMap.set(node, value || defaultNodeLabelFn(node));
// 如果是复合图,则创建节点的子节点
if (isCompound()) {
parentMap === null || parentMap === void 0 ? void 0 : parentMap.set(node, _this.GRAPH_NODE);
childrenMap === null || childrenMap === void 0 ? void 0 : childrenMap.set(node, new Map());
if (!(childrenMap === null || childrenMap === void 0 ? void 0 : childrenMap.has(_this.GRAPH_NODE))) {
childrenMap === null || childrenMap === void 0 ? void 0 : childrenMap.set(_this.GRAPH_NODE, new Map());
}
(_a = childrenMap === null || childrenMap === void 0 ? void 0 : childrenMap.get(_this.GRAPH_NODE)) === null || _a === void 0 ? void 0 : _a.set(node, true);
}
[inEdgesMap, outEdgesMap, predecessorsMap, successorsMap].forEach(function (map) {
return map.set(node, new Map());
});
_this.nodeCountNum += 1;
return _this;
};
/**
* @description Set nodes or add nodes in batch

@@ -382,34 +349,2 @@ * @description.zh-CN 批量设置或者创建节点

/**
* @description Remove node from graph
* @description.zh-CN 将节点从图中移除
* @param node
* @returns
*/
this.removeNode = function (node) {
var _a, _b, _c;
if (_this.hasNode(node)) {
var cleanEdge_1 = function (edgeObj) {
_this.removeEdge(edgeObj.v, edgeObj.w, edgeObj.name);
};
var _d = _this, inEdgesMap = _d.inEdgesMap, outEdgesMap = _d.outEdgesMap, predecessorsMap = _d.predecessorsMap, successorsMap = _d.successorsMap, nodesLabelMap = _d.nodesLabelMap;
if (_this.isCompound()) {
_this.removeFromParentsChildList(node);
(_a = _this.parentMap) === null || _a === void 0 ? void 0 : _a.delete(node);
(_b = _this.children(node)) === null || _b === void 0 ? void 0 : _b.forEach(function (n) { return _this.setParent(n); });
(_c = _this.childrenMap) === null || _c === void 0 ? void 0 : _c.delete(node);
}
var inE = inEdgesMap.get(node);
var outE = outEdgesMap.get(node);
Array.from(inE.values()).forEach(function (edge) { return cleanEdge_1(edge); });
Array.from(outE.values()).forEach(function (edge) { return cleanEdge_1(edge); });
nodesLabelMap.delete(node);
inEdgesMap.delete(node);
outEdgesMap.delete(node);
predecessorsMap.delete(node);
successorsMap.delete(node);
_this.nodeCountNum -= 1;
}
return _this;
};
/**
* @description Set function that generate default label for edge, if param is non-function value then default label will always be this value;

@@ -435,37 +370,2 @@ * @description.zh-CN 设置默认获取边Label的方法,如果传入不是函数的,那么默认label 的值只会是传入值

this.edgeCount = function () { return _this.edgeCountNum; };
/**
* @description set edge value, if nodes or edges not exsit then add to graph
* @description.zh-CN 设置边的属性,如果边或节点不存在,那么将他们加入这个图
* @param v
* @param w
* @param value
* @param name
* @returns
*/
this.setEdge = function (v_, w_, value, name) {
var _a, _b;
var edgeObj = (0, util_2.edgeArgsToObj)(_this.isDirected(), v_, w_, name);
var edgeId = (0, util_2.edgeObjToId)(_this.isDirected(), edgeObj);
var v = edgeObj.v, w = edgeObj.w;
if (_this.edgesLabelsMap.has(edgeId)) {
_this.edgesLabelsMap.set(edgeId, value);
return _this;
}
if (name !== undefined && !_this.isMultigraph()) {
throw new Error('Cannot set a named edge when isMultigraph = false');
}
_this.setNode(v);
_this.setNode(w);
_this.edgesLabelsMap.set(edgeId, value || _this.defaultEdgeLabelFn(v, w, name));
Object.freeze(edgeObj);
_this.edgesMap.set(edgeId, edgeObj);
var preds = _this.predecessorsMap.get(w);
var succs = _this.successorsMap.get(v);
(0, util_2.incrementOrInitEntry)(preds, v);
(0, util_2.incrementOrInitEntry)(succs, w);
(_a = _this.inEdgesMap.get(w)) === null || _a === void 0 ? void 0 : _a.set(edgeId, edgeObj);
(_b = _this.outEdgesMap.get(v)) === null || _b === void 0 ? void 0 : _b.set(edgeId, edgeObj);
_this.edgeCountNum += 1;
return _this;
};
this.setEdgeObj = function (edgeObj, value) {

@@ -520,27 +420,2 @@ return _this.setEdge(edgeObj.v, edgeObj.w, value, edgeObj.name);

/**
* @description remove a specific edge
* @description.zh-CN 删除一条边
* @param v
* @param w
* @param name
* @returns
*/
this.removeEdge = function (v_, w_, name) {
var edgeId = (0, util_1.edgeArgsToId)(_this.isDirected(), v_, w_, name);
var edgeObj = _this.edgesMap.get(edgeId);
if (edgeObj) {
var _a = (0, util_2.edgeArgsToObj)(_this.isDirected(), v_, w_, name), v = _a.v, w = _a.w;
_this.edgesLabelsMap.delete(edgeId);
_this.edgesMap.delete(edgeId);
var preds = _this.predecessorsMap.get(w);
var succs = _this.successorsMap.get(v);
(0, util_2.decrementOrRemoveEntry)(preds, v);
(0, util_2.decrementOrRemoveEntry)(succs, w);
_this.inEdgesMap.get(w).delete(edgeId);
_this.outEdgesMap.get(v).delete(edgeId);
_this.edgeCountNum -= 1;
}
return _this;
};
/**
* @description remove a specific edge by edge object

@@ -641,16 +516,2 @@ * @description.zh-CN 删除一条边

this.target = function (edge) { return edge.w; };
/**
* @description Count the total edges with self loop
* @description.zh-CN 计算节点的自环边的数量
*/
this.countSelfLoops = function () {
var count = 0;
for (var _i = 0, _a = _this.edges(); _i < _a.length; _i++) {
var edge = _a[_i];
if (edge.v === edge.w) {
count += 1;
}
}
return count;
};
var resultOptions = __assign(__assign({}, defaultOption), options);

@@ -665,2 +526,128 @@ this.compound = resultOptions.compound;

}
/**
* @description Set Node label in graph if node not in graph then create it
* @description.zh-CN 设置节点的label,如果这个节点不在图中,则在图中创建这个节点
* @param node
* @param value
* @returns
*/
Graph.prototype.setNode = function (node, value) {
var _a;
var _b = this, nodesLabelMap = _b.nodesLabelMap, defaultNodeLabelFn = _b.defaultNodeLabelFn, isCompound = _b.isCompound, parentMap = _b.parentMap, childrenMap = _b.childrenMap, inEdgesMap = _b.inEdgesMap, outEdgesMap = _b.outEdgesMap, predecessorsMap = _b.predecessorsMap, successorsMap = _b.successorsMap;
// 如果节点不在图中,则创建节点
if (nodesLabelMap.has(node)) {
if (value !== undefined) {
nodesLabelMap.set(node, value);
}
return this;
}
nodesLabelMap.set(node, value || defaultNodeLabelFn(node));
// 如果是复合图,则创建节点的子节点
if (isCompound()) {
parentMap === null || parentMap === void 0 ? void 0 : parentMap.set(node, this.GRAPH_NODE);
childrenMap === null || childrenMap === void 0 ? void 0 : childrenMap.set(node, new Map());
if (!(childrenMap === null || childrenMap === void 0 ? void 0 : childrenMap.has(this.GRAPH_NODE))) {
childrenMap === null || childrenMap === void 0 ? void 0 : childrenMap.set(this.GRAPH_NODE, new Map());
}
(_a = childrenMap === null || childrenMap === void 0 ? void 0 : childrenMap.get(this.GRAPH_NODE)) === null || _a === void 0 ? void 0 : _a.set(node, true);
}
[inEdgesMap, outEdgesMap, predecessorsMap, successorsMap].forEach(function (map) {
return map.set(node, new Map());
});
this.nodeCountNum += 1;
return this;
};
/**
* @description Remove node from graph
* @description.zh-CN 将节点从图中移除
* @param node
* @returns
*/
Graph.prototype.removeNode = function (node) {
var _this = this;
var _a, _b, _c;
if (this.hasNode(node)) {
var cleanEdge_1 = function (edgeObj) {
_this.removeEdge(edgeObj.v, edgeObj.w, edgeObj.name);
};
var _d = this, inEdgesMap = _d.inEdgesMap, outEdgesMap = _d.outEdgesMap, predecessorsMap = _d.predecessorsMap, successorsMap = _d.successorsMap, nodesLabelMap = _d.nodesLabelMap;
if (this.isCompound()) {
this.removeFromParentsChildList(node);
(_a = this.parentMap) === null || _a === void 0 ? void 0 : _a.delete(node);
(_b = this.children(node)) === null || _b === void 0 ? void 0 : _b.forEach(function (n) { return _this.setParent(n); });
(_c = this.childrenMap) === null || _c === void 0 ? void 0 : _c.delete(node);
}
var inE = inEdgesMap.get(node);
var outE = outEdgesMap.get(node);
Array.from(inE.values()).forEach(function (edge) { return cleanEdge_1(edge); });
Array.from(outE.values()).forEach(function (edge) { return cleanEdge_1(edge); });
nodesLabelMap.delete(node);
inEdgesMap.delete(node);
outEdgesMap.delete(node);
predecessorsMap.delete(node);
successorsMap.delete(node);
this.nodeCountNum -= 1;
}
return this;
};
/**
* @description set edge value, if nodes or edges not exsit then add to graph
* @description.zh-CN 设置边的属性,如果边或节点不存在,那么将他们加入这个图
* @param v
* @param w
* @param value
* @param name
* @returns
*/
Graph.prototype.setEdge = function (v_, w_, value, name) {
var _a, _b;
var edgeObj = (0, util_2.edgeArgsToObj)(this.isDirected(), v_, w_, name);
var edgeId = (0, util_2.edgeObjToId)(this.isDirected(), edgeObj);
var v = edgeObj.v, w = edgeObj.w;
if (this.edgesLabelsMap.has(edgeId)) {
this.edgesLabelsMap.set(edgeId, value);
return this;
}
if (name !== undefined && !this.isMultigraph()) {
throw new Error('Cannot set a named edge when isMultigraph = false');
}
this.setNode(v);
this.setNode(w);
this.edgesLabelsMap.set(edgeId, value || this.defaultEdgeLabelFn(v, w, name));
Object.freeze(edgeObj);
this.edgesMap.set(edgeId, edgeObj);
var preds = this.predecessorsMap.get(w);
var succs = this.successorsMap.get(v);
(0, util_2.incrementOrInitEntry)(preds, v);
(0, util_2.incrementOrInitEntry)(succs, w);
(_a = this.inEdgesMap.get(w)) === null || _a === void 0 ? void 0 : _a.set(edgeId, edgeObj);
(_b = this.outEdgesMap.get(v)) === null || _b === void 0 ? void 0 : _b.set(edgeId, edgeObj);
this.edgeCountNum += 1;
return this;
};
/**
* @description remove a specific edge
* @description.zh-CN 删除一条边
* @param v
* @param w
* @param name
* @returns
*/
Graph.prototype.removeEdge = function (v_, w_, name) {
var edgeId = (0, util_1.edgeArgsToId)(this.isDirected(), v_, w_, name);
var edgeObj = this.edgesMap.get(edgeId);
if (edgeObj) {
var _a = (0, util_2.edgeArgsToObj)(this.isDirected(), v_, w_, name), v = _a.v, w = _a.w;
this.edgesLabelsMap.delete(edgeId);
this.edgesMap.delete(edgeId);
var preds = this.predecessorsMap.get(w);
var succs = this.successorsMap.get(v);
(0, util_2.decrementOrRemoveEntry)(preds, v);
(0, util_2.decrementOrRemoveEntry)(succs, w);
this.inEdgesMap.get(w).delete(edgeId);
this.outEdgesMap.get(v).delete(edgeId);
this.edgeCountNum -= 1;
}
return this;
};
Graph.fromJSON = toJSON_1.read;

@@ -667,0 +654,0 @@ return Graph;

import Graph from './Graph';
import { isGraph } from './util';
import { GraphWithEvent } from './Graph/event';
import * as algorithm from './algorithm';
import * as comparision from './comparison';
export { Graph, algorithm, isGraph, comparision };
import * as comparision from './comparision';
import * as essence from './essence';
import * as generate from './generate';
export { Graph, GraphWithEvent, algorithm, comparision, essence, generate };

@@ -25,10 +25,14 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.comparision = exports.isGraph = exports.algorithm = exports.Graph = void 0;
exports.generate = exports.essence = exports.comparision = exports.algorithm = exports.GraphWithEvent = exports.Graph = void 0;
var Graph_1 = __importDefault(require("./Graph"));
exports.Graph = Graph_1.default;
var util_1 = require("./util");
Object.defineProperty(exports, "isGraph", { enumerable: true, get: function () { return util_1.isGraph; } });
var event_1 = require("./Graph/event");
Object.defineProperty(exports, "GraphWithEvent", { enumerable: true, get: function () { return event_1.GraphWithEvent; } });
var algorithm = __importStar(require("./algorithm"));
exports.algorithm = algorithm;
var comparision = __importStar(require("./comparison"));
var comparision = __importStar(require("./comparision"));
exports.comparision = comparision;
var essence = __importStar(require("./essence"));
exports.essence = essence;
var generate = __importStar(require("./generate"));
exports.generate = generate;

@@ -34,2 +34,1 @@ import { DefaultEdgeType } from './Graph';

export declare function isFunction(obj: any): boolean;
export declare function isGraph(obj: any): boolean;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isGraph = exports.isFunction = exports.edgeObjToId = exports.edgeArgsToObj = exports.edgeArgsToId = exports.decrementOrRemoveEntry = exports.incrementOrInitEntry = void 0;
var enum_1 = require("./enum");
var Graph_1 = __importDefault(require("./Graph"));
exports.isFunction = exports.edgeObjToId = exports.edgeArgsToObj = exports.edgeArgsToId = exports.decrementOrRemoveEntry = exports.incrementOrInitEntry = void 0;
var enum_1 = require("./Graph/enum");
/**

@@ -87,5 +83,1 @@ * @description add one to key's value in map

exports.isFunction = isFunction;
function isGraph(obj) {
return obj instanceof Graph_1.default;
}
exports.isGraph = isGraph;
{
"name": "@antv/graphlib",
"version": "1.1.0",
"version": "1.2.0",
"scripts": {

@@ -58,3 +58,15 @@ "start": "dumi dev",

"yorkie": "^2.0.0"
},
"homepage": "https://github.com/antvis/graphlib",
"bugs": {
"url": "https://github.com/antvis/graphlib/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/antvis/graphlib.git"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
}
}

@@ -13,15 +13,19 @@ # Graphlib

- [algorithm](docs/modules/algorithm.md)
- [comparision](docs/modules/comparision.md)
- [algorithm](modules/algorithm.md)
- [comparision](modules/comparision.md)
- [essence](modules/essence.md)
- [generate](modules/generate.md)
### Classes
- [Graph](docs/classes/Graph.md)
- [Graph](classes/Graph.md)
- [GraphWithEvent](classes/GraphWithEvent.md)
## Change Log
### Functions
#### 1.2.0
- 🎉 `GraphWithEvent` now you can use graph with event listener
- 🎉 `essece` module for graph basic essence property check
- 🎉 `generate` module for graph generate new graph, now support graph's complement;
-
- [isGraph](docs/modules.md#isgraph)
## Change Log
#### 1.1.0

@@ -28,0 +32,0 @@

import Graph, { DefaultEdgeType } from '../Graph';
import PriorityQueue from '../PriorityQueue';
import PriorityQueue from './PriorityQueue';

@@ -4,0 +4,0 @@ const DEFAULT_WEIGHT_FUNC = () => 1;

import Graph, { DefaultEdgeType } from '../Graph';
import PriorityQueue from '../PriorityQueue';
import PriorityQueue from './PriorityQueue';

@@ -4,0 +4,0 @@ const prim = <NodeIdType, NodeType, EdgeType>(

import { edgeArgsToId, isFunction } from '../util';
import { GraphEnum } from '../enum';
import { GraphEnum } from './enum';
import { decrementOrRemoveEntry, edgeArgsToObj, edgeObjToId, incrementOrInitEntry } from '../util';

@@ -270,3 +270,3 @@ import { read, write } from './toJSON';

*/
setNode = (node: NodeIDType, value?: NodeType) => {
setNode(node: NodeIDType, value?: NodeType) {
const {

@@ -310,3 +310,3 @@ nodesLabelMap,

return this;
};
}

@@ -529,3 +529,3 @@ /**

*/
removeNode = (node: NodeIDType) => {
removeNode(node: NodeIDType) {
if (this.hasNode(node)) {

@@ -560,3 +560,3 @@ const cleanEdge = (edgeObj: DefaultEdgeType<NodeIDType, EdgeType>) => {

return this;
};
}

@@ -594,3 +594,3 @@ /**

*/
setEdge = (v_: NodeIDType, w_: NodeIDType, value?: any, name?: string) => {
setEdge(v_: NodeIDType, w_: NodeIDType, value?: any, name?: string) {
const edgeObj = edgeArgsToObj<NodeIDType>(this.isDirected(), v_, w_, name);

@@ -626,3 +626,3 @@ const edgeId = edgeObjToId(this.isDirected(), edgeObj);

return this;
};
}

@@ -690,3 +690,3 @@ setEdgeObj = (edgeObj: DefaultEdgeType<NodeIDType, EdgeType>, value?: EdgeType) => {

*/
removeEdge = (v_: NodeIDType, w_: NodeIDType, name?: any) => {
removeEdge(v_: NodeIDType, w_: NodeIDType, name?: any) {
const edgeId = edgeArgsToId(this.isDirected(), v_, w_, name);

@@ -709,3 +709,3 @@ const edgeObj = this.edgesMap.get(edgeId);

return this;
};
}

@@ -819,16 +819,2 @@ /**

target = (edge: DefaultEdgeType<NodeIDType, EdgeType>) => edge.w;
/**
* @description Count the total edges with self loop
* @description.zh-CN 计算节点的自环边的数量
*/
countSelfLoops = () => {
let count = 0;
for (const edge of this.edges()) {
if (edge.v === edge.w) {
count += 1;
}
}
return count;
};
}
import Graph from './Graph';
import { isGraph } from './util';
import { GraphWithEvent } from './Graph/event';
import * as algorithm from './algorithm';
import * as comparision from './comparison';
import * as comparision from './comparision';
import * as essence from './essence';
import * as generate from './generate';
export { Graph, algorithm, isGraph, comparision };
export { Graph, GraphWithEvent, algorithm, comparision, essence, generate };

@@ -1,3 +0,3 @@

import { GraphEnum } from './enum';
import Graph, { DefaultEdgeType } from './Graph';
import { GraphEnum } from './Graph/enum';
import { DefaultEdgeType } from './Graph';

@@ -94,5 +94,1 @@ /**

}
export function isGraph(obj: any) {
return obj instanceof Graph;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc