pd-code-components 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TopologicalKnotIndexer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pd-code-components
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: get all components from a link pd code.
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Author: GGN_2015
|
|
8
|
+
Author-email: premierbob@qq.com
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# pd_code_components
|
|
20
|
+
计算 pd_code 中的每一个连通分量对应的编号集合
|
|
21
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
|
|
2
|
+
# 向一个指定的图中新增节点
|
|
3
|
+
def add_edge(nxt:dict, node_a:str|int, node_b:str|int):
|
|
4
|
+
|
|
5
|
+
# 确保节点存在
|
|
6
|
+
if nxt.get(node_a) is None:
|
|
7
|
+
nxt[node_a] = []
|
|
8
|
+
if nxt.get(node_b) is None:
|
|
9
|
+
nxt[node_b] = []
|
|
10
|
+
|
|
11
|
+
# 将节点加入到列表中
|
|
12
|
+
if node_b not in nxt[node_a]:
|
|
13
|
+
nxt[node_a].append(node_b)
|
|
14
|
+
if node_a not in nxt[node_b]:
|
|
15
|
+
nxt[node_b].append(node_a)
|
|
16
|
+
|
|
17
|
+
# 使用深度优先搜索确定所有连通分量
|
|
18
|
+
def dfs(nxt:dict, vis:list, arr:list, node_name:str|int):
|
|
19
|
+
if node_name in vis:
|
|
20
|
+
return
|
|
21
|
+
vis.append(node_name)
|
|
22
|
+
arr.append(node_name)
|
|
23
|
+
for nxt_node in nxt[node_name]:
|
|
24
|
+
dfs(nxt, vis, arr, nxt_node)
|
|
25
|
+
|
|
26
|
+
# 从 pd_code 中计算每一个连通分支对应的数值集合
|
|
27
|
+
def get_components_from_pd_code(pd_code:list[list[int|str]]) -> list[list[int|str]]:
|
|
28
|
+
if not isinstance(pd_code, list):
|
|
29
|
+
raise TypeError()
|
|
30
|
+
for item in pd_code:
|
|
31
|
+
if len(item) != 4:
|
|
32
|
+
raise AssertionError()
|
|
33
|
+
for sub_item in item:
|
|
34
|
+
if (not isinstance(sub_item, str)) and (not isinstance(sub_item, int)):
|
|
35
|
+
raise TypeError()
|
|
36
|
+
|
|
37
|
+
# nxt 记录每个节点的后继节点(一般来说有两个)
|
|
38
|
+
nxt = {}
|
|
39
|
+
|
|
40
|
+
# 建图
|
|
41
|
+
for crossing in pd_code:
|
|
42
|
+
add_edge(nxt, crossing[0], crossing[2])
|
|
43
|
+
add_edge(nxt, crossing[1], crossing[3])
|
|
44
|
+
|
|
45
|
+
vis = []
|
|
46
|
+
components = []
|
|
47
|
+
for node_name in nxt:
|
|
48
|
+
if node_name not in vis:
|
|
49
|
+
arr = []
|
|
50
|
+
dfs(nxt, vis, arr, node_name)
|
|
51
|
+
components.append(sorted(arr))
|
|
52
|
+
|
|
53
|
+
return sorted(components)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "pd-code-components"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "get all components from a link pd code."
|
|
5
|
+
authors = [
|
|
6
|
+
{name = "GGN_2015",email = "premierbob@qq.com"}
|
|
7
|
+
]
|
|
8
|
+
license = {text = "MIT"}
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
dependencies = [
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
[build-system]
|
|
16
|
+
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
17
|
+
build-backend = "poetry.core.masonry.api"
|