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

setx: Set 接口设计和基于 map 的实现 #146

Closed
flycash opened this issue Feb 3, 2023 · 1 comment · Fixed by #155
Closed

setx: Set 接口设计和基于 map 的实现 #146

flycash opened this issue Feb 3, 2023 · 1 comment · Fixed by #155
Labels
Milestone

Comments

@flycash
Copy link
Contributor

flycash commented Feb 3, 2023

仅限中文

使用场景

正常来说,Set 算是一个很常用的数据结构。不过令人惊奇的是 Go 并没有直接提供 Set 的数据结构,所以大多数时候我们都是依赖于使用 map 来间接达成 Set 效果。

当然这并不是什么问题,只是代码 review 的时候有点烦。

所以现在要求你设计一个 Set 接口,并且基于 map 提供一个实现。

要求:

  • 设计基准测试,将基于 map 的实现和直接使用 map 的性能进行比较

要求接口具备方法:

  • 增加元素
  • 删除元素
  • 判断一个元素是否存在
  • 返回所有的元素

按照我一贯的做法,接口的方法都要返回 error,但是我不确定这种习惯在 set 里面是否合适。之前在 Map 的设计与实现里面返回了 error 就有点累赘。

@flycash flycash added the 中等 label Feb 3, 2023
@flycash flycash added this to the v0.0.7 milestone Feb 3, 2023
@flycash
Copy link
Contributor Author

flycash commented Feb 3, 2023

实现本身不难,就是接口设计要小心

@flycash flycash mentioned this issue Feb 3, 2023
@flycash flycash linked a pull request Feb 12, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant