Skip to content

Commit

Permalink
Add build check with py_compile
Browse files Browse the repository at this point in the history
  • Loading branch information
krahets committed Oct 22, 2023
1 parent 1b99789 commit b7c110e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions codes/python/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import glob
import py_compile as pyc

src_paths = sorted(glob.glob("codes/python/**/*.py"))
num_src = len(src_paths)
num_src_error = 0

for src_path in src_paths:
try:
pyc.compile(src_path, doraise=True)
except pyc.PyCompileError as e:
num_src_error += 1
print(e)

print(f"===== Build Summary =====")
print(f"Total: {num_src}")
print(f"Error: {num_src - num_src_error}")
2 changes: 1 addition & 1 deletion docs/chapter_array_and_linkedlist/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
另一方面,必要使用链表的情况主要是二叉树和图。栈和队列往往会使用编程语言提供的 `stack` 和 `queue` ,而非链表。

!!! question "初始化列表 `res = [0] * self.size()` 操作,会导致 `res` 的每个元素引用相同的地址吗?"

不会。但二维数组会有这个问题,例如初始化二维列表 `res = [[0] * self.size()]` ,则多次引用了同一个列表 `[0]` 。

!!! question "在删除节点中,需要断开该节点与其后继节点之间的引用指向吗?"
Expand Down
2 changes: 1 addition & 1 deletion docs/chapter_graph/graph_operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
- 为了方便添加与删除顶点,以及简化代码,我们使用列表(动态数组)来代替链表。
- 使用哈希表来存储邻接表,`key` 为顶点实例,`value` 为该顶点的邻接顶点列表(链表)。

另外,我们在邻接表中使用 `Vertex` 类来表示顶点。这是因为如果与邻接矩阵一样用列表索引来区分不同顶点。那么假设想要删除索引为 $i$ 的顶点,则需要遍历整个邻接表,将所有大于 $i$ 的索引全部减 $1$ ,效率很低。而如果每个顶点都是唯一的 `Vertex` 实例,删除某一顶点之后就无须改动其他顶点了。
另外,我们在邻接表中使用 `Vertex` 类来表示顶点,这样做的原因是:如果与邻接矩阵一样,用列表索引来区分不同顶点,那么假设要删除索引为 $i$ 的顶点,则需遍历整个邻接表,将所有大于 $i$ 的索引全部减 $1$ ,效率很低。而如果每个顶点都是唯一的 `Vertex` 实例,删除某一顶点之后就无须改动其他顶点了。

```src
[file]{graph_adjacency_list}-[class]{graph_adj_list}-[func]{}
Expand Down

0 comments on commit b7c110e

Please sign in to comment.