Objective-C实现直方图或行李数据结构 [英] Objective-C implementation of a histogram or bag datastructure

查看:212
本文介绍了Objective-C实现直方图或行李数据结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

而不是实现我自己,我想知道是否有人知道在Objective-C中可以使用的直方图或行李数据结构实现。

Instead of implementing my own I was wondering if anyone knows of a histogram or bag datastructure implementation in Objective-C that I can use.

基本上一个直方图是列表中的hashmap,其中列表包含与其哈希条目相关的值。一个很好的例子是超市物品的直方图,您可以将自己的包装中的每一组乳制品,肉类和罐头食品。您可以根据自己的类型轻松访问每组项目。

Essentially a histogram is a hashmap of lists where the lists contain values that relate to their hash entry. A good example is a histogram of supermarket items where you place each group of items dairy, meat, canned goods in their own bag. You can then very easily access each group of items according to their type.

推荐答案

NSCountedSet 是一个 multiset (又名bag),它计数不同的对象,但不允许重复。但是,根据您的解释,我不认为这是您需要的, histogram ,它会根据一组(通常为数字)范围自动调用值。

NSCountedSet is a multiset (aka "bag") that counts distinct objects, but doesn't allow duplicates. However, based on your explanation, I don't think that's what you need, and neither is a histogram, which automatically buckets values based on a set of (usually numerical) ranges.

我相信你真正想要的是一个 multimap ,这是一个或多个值关系的关键。我维护的数据结构框架包括 CHMultiDictionary ,一个multimap实现。我不会以任何方式表示完美或完整,但希望对您的问题有帮助。

I believe what you really want is a multimap, which is a "key to one-or-more values" relation. The data structures framework I maintain includes CHMultiDictionary, a multimap implementation. I won't claim by any means that it's perfect or complete, but I hope it may be helpful for your problem.

这篇关于Objective-C实现直方图或行李数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆