Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[79_6] Performance tuning on vertex_occurrences in link.cpp #2089

Draft
wants to merge 5 commits into
base: branch-1.2
Choose a base branch
from

Conversation

da-liii
Copy link
Contributor

@da-liii da-liii commented Sep 12, 2024

What

Use hashset instead list for faster insertion and removal.

How to test your changes?

Use Goldfish.tmu as the test doc: https://github.com/LiiiLabs/goldfish/blob/main/Goldfish.tmu

@@ -57,15 +63,22 @@ unregister_pointer (string id, observer which) {

void
register_vertex (tree v, soft_link ln) {
list<soft_link>& l= vertex_occurrences (v);
l = list<soft_link> (ln, l);
if (vertex_occurrences->contains (v)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么这里要判断v是否是vertex_occurrences的键?如果hashmap不包含对应的键,会原位构造对应的参数,然后返回引用。如果hashset没有默认初始化函数,可以在初始化vertex_occurrences的时候传个初始对象进去

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用原来的写法,编辑器直接卡死了。所以用了这种朴素的写法。

@Oyyko
Copy link
Contributor

Oyyko commented Sep 12, 2024

这块代码看起来没有问题。有经过测试,其他调用这块的代码,可以正常运行吗?

hashmap<tree, list<soft_link>> vertex_occurrences;
hashmap<string, int> type_count (0);
static int
hash (soft_link l) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个函数哪里用到了?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hashset<soft_link> 需要提供一个 hash函数

@da-liii
Copy link
Contributor Author

da-liii commented Sep 13, 2024

有经过测试,其他调用这块的代码,可以正常运行吗?

通过打开文档测试的,我尝试加一下集成测试

@da-liii da-liii marked this pull request as draft September 13, 2024 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants