pd-code-reverse-component 0.1.0__tar.gz → 0.1.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,65 @@
1
+ Metadata-Version: 2.4
2
+ Name: pd-code-reverse-component
3
+ Version: 0.1.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 (>=0.1.0)
18
+ Requires-Dist: pd-code-sanity (>=0.1.0)
19
+ Description-Content-Type: text/markdown
20
+
21
+ # pd-code-reverse-component
22
+
23
+ Reverse the orientation encoding of one selected PD-code component.
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ pip install pd-code-reverse-component
29
+ ```
30
+
31
+ ## Usage example
32
+
33
+ ```python
34
+ from pd_code_reverse_component import reverse_component
35
+
36
+ pd = [[2, 3, 1, 4], [4, 1, 3, 2]]
37
+ reversed_pd = reverse_component(pd, 1)
38
+ print(reversed_pd)
39
+ ```
40
+
41
+ ## Algorithm
42
+
43
+ The selected label identifies its component cycle through predecessor/successor maps. The cycle is placed in canonical order and mapped to its reverse order. Every occurrence of a component label is replaced through that bijection; labels belonging to other components remain unchanged. The operation returns a deep copy and leaves the input untouched.
44
+
45
+ ## Input conventions
46
+
47
+ A PD code is represented as a list of four-entry crossings. Arc labels normally occur exactly twice. Public functions validate inputs and return new values rather than mutating caller-owned data unless their API explicitly says otherwise.
48
+
49
+ ## External software
50
+
51
+ No external software is required.
52
+
53
+ ## Development
54
+
55
+ Run examples and package checks before release. Python packages require Python 3.10 or newer. Build PyPI artifacts with:
56
+
57
+ ```bash
58
+ poetry check
59
+ poetry build
60
+ ```
61
+
62
+ ## License
63
+
64
+ MIT. See `LICENSE`.
65
+
@@ -0,0 +1,44 @@
1
+ # pd-code-reverse-component
2
+
3
+ Reverse the orientation encoding of one selected PD-code component.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install pd-code-reverse-component
9
+ ```
10
+
11
+ ## Usage example
12
+
13
+ ```python
14
+ from pd_code_reverse_component import reverse_component
15
+
16
+ pd = [[2, 3, 1, 4], [4, 1, 3, 2]]
17
+ reversed_pd = reverse_component(pd, 1)
18
+ print(reversed_pd)
19
+ ```
20
+
21
+ ## Algorithm
22
+
23
+ The selected label identifies its component cycle through predecessor/successor maps. The cycle is placed in canonical order and mapped to its reverse order. Every occurrence of a component label is replaced through that bijection; labels belonging to other components remain unchanged. The operation returns a deep copy and leaves the input untouched.
24
+
25
+ ## Input conventions
26
+
27
+ A PD code is represented as a list of four-entry crossings. Arc labels normally occur exactly twice. Public functions validate inputs and return new values rather than mutating caller-owned data unless their API explicitly says otherwise.
28
+
29
+ ## External software
30
+
31
+ No external software is required.
32
+
33
+ ## Development
34
+
35
+ Run examples and package checks before release. Python packages require Python 3.10 or newer. Build PyPI artifacts with:
36
+
37
+ ```bash
38
+ poetry check
39
+ poetry build
40
+ ```
41
+
42
+ ## License
43
+
44
+ MIT. See `LICENSE`.
@@ -1,62 +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))
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))
@@ -1,19 +1,19 @@
1
- [project]
2
- name = "pd-code-reverse-component"
3
- version = "0.1.0"
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 = [
1
+ [project]
2
+ name = "pd-code-reverse-component"
3
+ version = "0.1.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
12
  "pd-code-sanity>=0.1.0",
13
13
  "pd-code-pre-nxt>=0.1.0"
14
- ]
15
-
16
-
17
- [build-system]
18
- requires = ["poetry-core>=2.0.0,<3.0.0"]
19
- build-backend = "poetry.core.masonry.api"
14
+ ]
15
+
16
+
17
+ [build-system]
18
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
19
+ build-backend = "poetry.core.masonry.api"
@@ -1,44 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: pd-code-reverse-component
3
- Version: 0.1.0
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 (>=0.1.0)
18
- Requires-Dist: pd-code-sanity (>=0.1.0)
19
- Description-Content-Type: text/markdown
20
-
21
- # pd-code-reverse-component
22
-
23
- Reverse the orientation of one component of a PD code.
24
-
25
- ## Installation
26
-
27
- ```bash
28
- pip install pd-code-reverse-component
29
- ```
30
-
31
- ## Quick start
32
-
33
- `from pd_code_reverse_component import reverse_component`.
34
-
35
- PD codes are lists of four-entry crossings. Each arc label must occur exactly twice. Functions validate their inputs and do not mutate caller-owned PD-code lists unless explicitly documented.
36
-
37
- ## Development
38
-
39
- Use Python 3.10 or newer for Python packages. Build distributions with `poetry build`. Run the package's tests or examples before publishing. C++ projects require a modern standards-compliant compiler.
40
-
41
- ## License
42
-
43
- MIT. See `LICENSE`.
44
-
@@ -1,23 +0,0 @@
1
- # pd-code-reverse-component
2
-
3
- Reverse the orientation of one component of a PD code.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- pip install pd-code-reverse-component
9
- ```
10
-
11
- ## Quick start
12
-
13
- `from pd_code_reverse_component import reverse_component`.
14
-
15
- PD codes are lists of four-entry crossings. Each arc label must occur exactly twice. Functions validate their inputs and do not mutate caller-owned PD-code lists unless explicitly documented.
16
-
17
- ## Development
18
-
19
- Use Python 3.10 or newer for Python packages. Build distributions with `poetry build`. Run the package's tests or examples before publishing. C++ projects require a modern standards-compliant compiler.
20
-
21
- ## License
22
-
23
- MIT. See `LICENSE`.