pd-code-reverse-component 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.
File without changes
@@ -0,0 +1,62 @@
1
+ import pd_code_sanity
2
+ import pd_code_pre_nxt
3
+ import json
4
+
5
+ # 沿着 nxt 边走出一个 loop
6
+ def get_loop(nxt:dict, begin_val) -> list:
7
+ loop = [begin_val]
8
+ while True:
9
+ loop.append(nxt[loop[-1]])
10
+ if loop[-1] == loop[0]: # 如果第一个元素已经重复出现
11
+ loop.pop()
12
+ break
13
+ return loop
14
+
15
+ # 翻转 val 所在的连通分支的所有编号
16
+ def reverse_component(pd_code:list[list], val):
17
+
18
+ # 先备份
19
+ pd_code = json.loads(json.dumps(pd_code))
20
+
21
+ # 必须是合法 pd_code
22
+ if not pd_code_sanity.sanity(pd_code):
23
+ raise TypeError()
24
+
25
+ # 没有出现过这个值,因此不能翻转
26
+ if val not in set([
27
+ term
28
+ for crossing in pd_code
29
+ for term in crossing
30
+ ]):
31
+ return pd_code
32
+
33
+ # 计算前驱后继
34
+ pre, nxt = pd_code_pre_nxt.get_pre_nxt(pd_code)
35
+
36
+ # 先找到当前循环的最小元素
37
+ min_val = min(get_loop(nxt, val))
38
+ loop = get_loop(nxt, min_val) # 这样可以得到递增序列
39
+ rev_loop = loop[::-1] # 翻转的 list
40
+
41
+ # 把出现过的值映射成大小相反的值
42
+ num_map = {
43
+ loop[i]: rev_loop[i]
44
+ for i in range(len(loop))
45
+ }
46
+
47
+ # 编写针对一个对象的映射函数
48
+ def map_one_data(term):
49
+ if num_map.get(term) is None:
50
+ return term
51
+ else:
52
+ return num_map[term]
53
+
54
+ # 重新编码
55
+ return [
56
+ [map_one_data(term) for term in crossing]
57
+ for crossing in pd_code
58
+ ]
59
+
60
+ if __name__ == "__main__":
61
+ pd_code = [[8,11,9,12],[12,9,13,10],[10,13,11,14],[7,14,8,1],[4,1,5,2],[2,5,3,6],[6,3,7,4]]
62
+ print(reverse_component(pd_code, 1))
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.4
2
+ Name: pd-code-reverse-component
3
+ Version: 0.0.1
4
+ Summary: reverse all arc number in one certain component for a 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_pre_nxt
18
+ Requires-Dist: pd_code_sanity
19
+ Description-Content-Type: text/markdown
20
+
21
+ # pd_code_reverse_component
22
+ reverse all arc number in one certain component for a link pd_code.
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ pip install pd-code-reverse-component
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ```python
33
+ import pd_code_reverse_component
34
+
35
+ pd_code = [[8,11,9,12],[12,9,13,10],[10,13,11,14],[7,14,8,1],[4,1,5,2],[2,5,3,6],[6,3,7,4]]
36
+ print(reverse_component(pd_code, 1)) # reverse the component with arc 1
37
+ ```
38
+
@@ -0,0 +1,6 @@
1
+ pd_code_reverse_component/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ pd_code_reverse_component/main.py,sha256=gBkNd_y8yVOzHjCehLCDCrIHBLP_AxLfuJ1qnbqbSPc,1740
3
+ pd_code_reverse_component-0.0.1.dist-info/licenses/LICENSE,sha256=gCKLErgKpA7XoLYEwL_UJkJQE_jTw7V4dD4dSns9fjI,1100
4
+ pd_code_reverse_component-0.0.1.dist-info/METADATA,sha256=QFMlUuz1AM3H9ZQSXJ6_vuaaXK2ry6KBORMZLwfPczI,1091
5
+ pd_code_reverse_component-0.0.1.dist-info/WHEEL,sha256=kJCRJT_g0adfAJzTx2GUMmS80rTJIVHRCfG0DQgLq3o,88
6
+ pd_code_reverse_component-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.