pd-code-reverse-component 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.
- pd_code_reverse_component-0.0.1/LICENSE +21 -0
- pd_code_reverse_component-0.0.1/PKG-INFO +38 -0
- pd_code_reverse_component-0.0.1/README.md +17 -0
- pd_code_reverse_component-0.0.1/pd_code_reverse_component/__init__.py +0 -0
- pd_code_reverse_component-0.0.1/pd_code_reverse_component/main.py +62 -0
- pd_code_reverse_component-0.0.1/pyproject.toml +19 -0
|
@@ -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,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,17 @@
|
|
|
1
|
+
# pd_code_reverse_component
|
|
2
|
+
reverse all arc number in one certain component for a link pd_code.
|
|
3
|
+
|
|
4
|
+
## Install
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pip install pd-code-reverse-component
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
import pd_code_reverse_component
|
|
14
|
+
|
|
15
|
+
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]]
|
|
16
|
+
print(reverse_component(pd_code, 1)) # reverse the component with arc 1
|
|
17
|
+
```
|
|
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,19 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "pd-code-reverse-component"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "reverse all arc number in one certain component for a link pd_code."
|
|
5
|
+
authors = [
|
|
6
|
+
{name = "GGN_2015",email = "neko@jlulug.org"}
|
|
7
|
+
]
|
|
8
|
+
license = {text = "MIT"}
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"pd_code_sanity",
|
|
13
|
+
"pd_code_pre_nxt"
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
[build-system]
|
|
18
|
+
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
19
|
+
build-backend = "poetry.core.masonry.api"
|