pd-code-pre-nxt 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,44 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pd-code-pre-nxt
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: get `pre` and `next` node for every number in 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
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# pd_code_pre_nxt
|
|
20
|
+
get `pre` and `next` node for every number in pd_code.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install pd-code-pre-nxt
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
import pd_code_pre_nxt
|
|
32
|
+
|
|
33
|
+
# link pd_code
|
|
34
|
+
pd_code = [[1, 5, 2, 4], [3, 1, 4, 6], [5, 3, 6, 2]]
|
|
35
|
+
|
|
36
|
+
# output number set (ascending order)
|
|
37
|
+
print(pd_code_pre_nxt.get_num_set(pd_code))
|
|
38
|
+
|
|
39
|
+
# get pre, nxt dict for pd_code
|
|
40
|
+
pre, nxt = pd_code_pre_nxt.get_pre_nxt(pd_code)
|
|
41
|
+
print(pre)
|
|
42
|
+
print(nxt)
|
|
43
|
+
```
|
|
44
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# pd_code_pre_nxt
|
|
2
|
+
get `pre` and `next` node for every number in pd_code.
|
|
3
|
+
|
|
4
|
+
## Install
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pip install pd-code-pre-nxt
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
import pd_code_pre_nxt
|
|
14
|
+
|
|
15
|
+
# link pd_code
|
|
16
|
+
pd_code = [[1, 5, 2, 4], [3, 1, 4, 6], [5, 3, 6, 2]]
|
|
17
|
+
|
|
18
|
+
# output number set (ascending order)
|
|
19
|
+
print(pd_code_pre_nxt.get_num_set(pd_code))
|
|
20
|
+
|
|
21
|
+
# get pre, nxt dict for pd_code
|
|
22
|
+
pre, nxt = pd_code_pre_nxt.get_pre_nxt(pd_code)
|
|
23
|
+
print(pre)
|
|
24
|
+
print(nxt)
|
|
25
|
+
```
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import pd_code_sanity
|
|
2
|
+
|
|
3
|
+
# 提取原始数值
|
|
4
|
+
# 如果里面有下划线,则去掉下划线转 int
|
|
5
|
+
def get_raw_val(val_in_crs:int|str) -> int:
|
|
6
|
+
if isinstance(val_in_crs, str):
|
|
7
|
+
return int(val_in_crs.split("_")[-1])
|
|
8
|
+
return int(val_in_crs)
|
|
9
|
+
|
|
10
|
+
def add_edge(pre:dict, nxt:dict, val1, val2):
|
|
11
|
+
raw_val1 = get_raw_val(val1)
|
|
12
|
+
raw_val2 = get_raw_val(val2)
|
|
13
|
+
|
|
14
|
+
# 记录前后关系
|
|
15
|
+
pre_val = -1
|
|
16
|
+
nxt_val = -1
|
|
17
|
+
|
|
18
|
+
# 确定前后关系
|
|
19
|
+
if abs(raw_val1 - raw_val2) == 1:
|
|
20
|
+
if raw_val1 < raw_val2:
|
|
21
|
+
pre_val = val1
|
|
22
|
+
nxt_val = val2
|
|
23
|
+
else:
|
|
24
|
+
pre_val = val2
|
|
25
|
+
nxt_val = val1
|
|
26
|
+
else:
|
|
27
|
+
if raw_val1 < raw_val2:
|
|
28
|
+
pre_val = val2
|
|
29
|
+
nxt_val = val1
|
|
30
|
+
else:
|
|
31
|
+
pre_val = val1
|
|
32
|
+
nxt_val = val2
|
|
33
|
+
|
|
34
|
+
# 设置 dict 值
|
|
35
|
+
pre[nxt_val] = pre_val
|
|
36
|
+
nxt[pre_val] = nxt_val
|
|
37
|
+
|
|
38
|
+
# 获得 pd_code 中的数值集合
|
|
39
|
+
# 按照字典序从小到大排序
|
|
40
|
+
def get_num_set(pd_code:list[list]):
|
|
41
|
+
val_set = set()
|
|
42
|
+
for crossing in pd_code:
|
|
43
|
+
for term in crossing:
|
|
44
|
+
if term not in val_set:
|
|
45
|
+
val_set.add(term)
|
|
46
|
+
return sorted(list(val_set), key=lambda x:get_raw_val(x))
|
|
47
|
+
|
|
48
|
+
# 计算 pre 和 nxt
|
|
49
|
+
# 没有 r1 crossing 就不会出现混乱
|
|
50
|
+
def get_pre_nxt(pd_code:list[list]) -> tuple[dict, dict]:
|
|
51
|
+
|
|
52
|
+
# 检查类型是否正确
|
|
53
|
+
if not pd_code_sanity.sanity(pd_code):
|
|
54
|
+
raise TypeError()
|
|
55
|
+
|
|
56
|
+
pre = dict()
|
|
57
|
+
nxt = dict()
|
|
58
|
+
for crossing in pd_code:
|
|
59
|
+
if len(set(crossing)) > 2: # 至少有三个不同的数
|
|
60
|
+
add_edge(pre, nxt, crossing[0], crossing[2])
|
|
61
|
+
add_edge(pre, nxt, crossing[1], crossing[3])
|
|
62
|
+
else:
|
|
63
|
+
two_values = list(set(crossing)) # 只有两个不同的数
|
|
64
|
+
if len(two_values) != 2:
|
|
65
|
+
raise AssertionError()
|
|
66
|
+
for i in range(2):
|
|
67
|
+
pre[two_values[i]] = two_values[1-i] # 互为前驱后继
|
|
68
|
+
nxt[two_values[i]] = two_values[1-i]
|
|
69
|
+
|
|
70
|
+
# 获取数值合集
|
|
71
|
+
num_set = get_num_set(pd_code)
|
|
72
|
+
for num in num_set:
|
|
73
|
+
if pre.get(num) is None:
|
|
74
|
+
pre[num] = nxt[num]
|
|
75
|
+
if nxt.get(num) is None:
|
|
76
|
+
nxt[num] = pre[num]
|
|
77
|
+
return pre, nxt
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "pd-code-pre-nxt"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "get `pre` and `next` node for every number in 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
|
+
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
[build-system]
|
|
17
|
+
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
18
|
+
build-backend = "poetry.core.masonry.api"
|