Skip to content

Conversation

imhun
Copy link
Contributor

@imhun imhun commented Apr 8, 2024

如题,支持多端口逗号分隔,连续端口-连接,比如:
22,80,443,1234-5678
image

image

return err
}

func ContainsInPorts(ports []uint16, port uint16) bool {
Copy link
Owner

Choose a reason for hiding this comment

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

转换成map匹配,效率会不会更高一些

Copy link
Contributor Author

Choose a reason for hiding this comment

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

需要支持连续端口,比如123-456这种,用map不好实现
另外跟原来的单端口规则比,比较次数是一样的,新的配置下多个端口只要一条规则

Copy link
Owner

@bjdgyc bjdgyc Apr 8, 2024

Choose a reason for hiding this comment

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

所有端口展开,存到map内,用空间换时间的方式。map查询是O(1),for循环是O(n)。
你看看哪种方式比较好

Copy link
Contributor Author

Choose a reason for hiding this comment

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

可以考虑

@bjdgyc bjdgyc merged commit 6e0c0ef into bjdgyc:main Apr 11, 2024
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.

2 participants