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

mapx: 支持 Len 方法 #238

Closed
flycash opened this issue Jan 8, 2024 · 0 comments · Fixed by #239
Closed

mapx: 支持 Len 方法 #238

flycash opened this issue Jan 8, 2024 · 0 comments · Fixed by #239

Comments

@flycash
Copy link
Contributor

flycash commented Jan 8, 2024

仅限中文

使用场景

在一些时候,我们需要判定整个 Map 里面究竟放了多少个元素,那么就希望可以暴露一个 Len 的方法。

这个 Len 返回的是键值对的数量。也就是说,如果一个 key 对应了多个元素,类似于 MultipleMap,那么还是认为这些元素和key 只是一个键值对而已。

行业分析

如果你知道有框架提供了类似功能,可以在这里描述,并且给出文档或者例子

可行方案

如果你有设计思路或者解决方案,请在这里提供。你可以提供多个方案,并且给出自己的选择

type mapi[K any, V any] interface {
	Put(key K, val V) error
	Get(key K) (V, bool)
	// Delete 删除
	// 第一个返回值是被删除的 key 对应的值
	// 第二个返回值是代表是否真的删除了
	Delete(k K) (V, bool)
	// Keys 返回所有的键
	// 注意,当你调用多次拿到的结果不一定相等
	// 取决于具体实现
	Keys() []K
	// Values 返回所有的值
	// 注意,当你调用多次拿到的结果不一定相等
	// 取决于具体实现
	Values() []V
       // 返回键值对数量
        Len() int64
}

这里我认为返回 int64 是万无一失的。当然,即便直接返回 int 大多数时候也没问题。

其它

任何你觉得有利于解决问题的补充说明

你使用的是 ekit 哪个版本?

你设置的的 Go 环境?

上传 go env 的结果

@longyue0521 longyue0521 linked a pull request Jan 9, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant