pd-code-de-r1 0.0.1__py3-none-any.whl

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,5 @@
1
+ from .main import de_r1
2
+
3
+ __all__ = [
4
+ "de_r1"
5
+ ]
pd_code_de_r1/main.py ADDED
@@ -0,0 +1,86 @@
1
+ import pd_code_sanity
2
+
3
+ # 向邻接表添加单向边
4
+ def __add_arc(nxt: dict, a: int, b: int) -> None:
5
+ if nxt.get(a) is None:
6
+ nxt[a] = []
7
+ if b not in nxt[a]:
8
+ nxt[a].append(b)
9
+
10
+ # 向邻接表添加双向边
11
+ def __addedge(nxt: dict, a: int, b: int) -> None:
12
+ __add_arc(nxt, a, b)
13
+ __add_arc(nxt, b, a)
14
+
15
+ # 构造邻接表
16
+ def __get_nxt(pd_code: list) -> dict:
17
+ nxt = {}
18
+ for line in pd_code:
19
+ a, b, c, d = line # a -> c, b -> d
20
+ __addedge(nxt, a, c)
21
+ __addedge(nxt, b, d)
22
+ return nxt
23
+
24
+ # 搜索找环
25
+ def __dfs(nxt: dict, vis: list, pos: int) -> None:
26
+ assert pos not in vis
27
+ vis.append(pos)
28
+
29
+ while True:
30
+ top_pos = vis[-1]
31
+ avai_nxt_pos = [v for v in nxt[top_pos] if v not in vis]
32
+ if len(avai_nxt_pos) == 0: # 无路可走
33
+ break
34
+ vis.append(avai_nxt_pos[0])
35
+
36
+ def __get_value_set(pd_code: list) -> set:
37
+ value_set = set()
38
+ for x in pd_code:
39
+ for v in x:
40
+ if v not in value_set:
41
+ value_set.add(v)
42
+ return value_set
43
+
44
+ # 删除 pd_code 中的所有 r1 拧
45
+ def de_r1(pd_code: list[list]) -> list[list]:
46
+
47
+ # 检验 pd_code 合法性
48
+ if not pd_code_sanity.sanity(pd_code):
49
+ raise TypeError()
50
+
51
+ while any(len(set(x)) <= 3 for x in pd_code):
52
+ for i in range(len(pd_code)):
53
+ x = pd_code[i]
54
+ if len(set(x)) <= 3:
55
+ pd_code = pd_code[:i] + pd_code[i+1:] # 删除当前节点
56
+ single = []
57
+ for v in x:
58
+ if x.count(v) == 1:
59
+ single.append(v)
60
+
61
+ if len(single) == 2:
62
+ pd_code = [[(single[1] if x==single[0] else x) for x in line] for line in pd_code]
63
+ break
64
+
65
+ # 获取编码集合
66
+ value_set = __get_value_set(pd_code)
67
+
68
+ # 重新编码
69
+ if pd_code != []:
70
+ nxt = __get_nxt(pd_code)
71
+ vis = list() # 得到 dfs 序
72
+
73
+ for value in value_set:
74
+ if value not in vis:
75
+ __dfs(nxt, vis, value)
76
+
77
+ # 给所有数据重新编码
78
+ new_id = {}
79
+ for i in range(len(vis)):
80
+ new_id[vis[i]] = i + 1
81
+ pd_code = [[new_id[v] for v in x] for x in pd_code]
82
+
83
+ return pd_code
84
+
85
+ if __name__ == "__main__":
86
+ print(de_r1([[1, 4, 2, 5], [5, 2, 6, 3], [3, 6, 4, 7], [7, 1, 8, 8]]))
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.4
2
+ Name: pd-code-de-r1
3
+ Version: 0.0.1
4
+ Summary: erase r1-move from link pd_code.
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Author: GGN_2015
8
+ Author-email: neko@jlulug.org
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
+ Requires-Dist: pd_code_sanity
18
+ Description-Content-Type: text/markdown
19
+
20
+ # pd_code_de_r1
21
+ erase r1-move in link pd_code.
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ pip install pd-code-de-r1
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```python
32
+ import pd_code_de_r1
33
+
34
+ link_pd_code = [[1, 4, 2, 5], [5, 2, 6, 3], [3, 6, 4, 7], [7, 1, 8, 8]]
35
+ print(pd_code_de_r1.de_r1(link_pd_code))
36
+ ```
37
+
@@ -0,0 +1,6 @@
1
+ pd_code_de_r1/__init__.py,sha256=TtYyZ9YQK0-it69pRvZbNSlhtS5hDnIEaqO6lh3a_vA,56
2
+ pd_code_de_r1/main.py,sha256=K-BHBf4QdXLVE4KbbkdwUgfpvMPXQWMSr_r1C7WuFXI,2488
3
+ pd_code_de_r1-0.0.1.dist-info/licenses/LICENSE,sha256=gCKLErgKpA7XoLYEwL_UJkJQE_jTw7V4dD4dSns9fjI,1100
4
+ pd_code_de_r1-0.0.1.dist-info/METADATA,sha256=kw-utk9JlmY4yAAXpIP6asZtrvFaIkAkrGB28TZI_dU,889
5
+ pd_code_de_r1-0.0.1.dist-info/WHEEL,sha256=kJCRJT_g0adfAJzTx2GUMmS80rTJIVHRCfG0DQgLq3o,88
6
+ pd_code_de_r1-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.3.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -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.