目标- c直方图或包数据结构的实现

时间:2021-05-16 14:54:36

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.

我想知道是否有人知道Objective-C中的直方图或包数据结构实现。

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.

本质上,直方图是列表的hashmap,其中列表包含与散列条目相关的值。一个很好的例子是超市商品的直方图,你把每一组商品都放在自己的袋子里。然后,您可以非常容易地根据项目的类型访问每组项目。

4 个解决方案

#1


5  

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.

NSCountedSet是一种多集(又称“包”),可以计数不同的对象,但不允许重复。但是,根据您的解释,我不认为这是您需要的,直方图也不需要,直方图根据一组(通常是数值)范围自动提取值。

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.

我相信你真正想要的是一个多映射,它是“一个或多个值的关键”关系。我维护的数据结构框架包括CHMultiDictionary,一个多映射实现。我不会说它是完美的或完整的,但是我希望它能对你的问题有所帮助。

#2


3  

It sounds to me like you simply want a dictionary of arrays. You can put NSArrays as elements of NSDictionarys, something like:

听起来你只是想要一个数组字典。可以将nsarray作为NSDictionarys的元素,比如:

NSMutableDictionary* dict = [NSMutableDictionary dictionary];
[dict setObject:[NSMutableArray arrayWithObjects:@"milk", @"eggs", @"cheese", nil] forKey:@"dairy"];
[dict setObject:[NSMutableArray arrayWithObjects:@"steak", @"sausages", @"mince", nil] forKey:@"meat"];

[[dict objectForKey:@"meat"] addObject:@"lamb"];

NSLog( @"Dictionary is %@", dict );

#3


1  

There's one in the GNU Objective-C Class library, but the docs appear to be pretty incomplete and the project's homepage must be currently having a problem -- still, if GPL software is acceptable for your project, you might want to download and check the sources.

在GNU Objective-C类库中有一个,但是文档看起来是相当不完整的,而且项目的主页现在一定有问题——但是,如果GPL软件对您的项目是可接受的,您可能想要下载并检查源代码。

#4


0  

CFIOMultimap apparently is an implementation of a multimap. However, as of the time of writing I couldn't get it to work. It returns nils all the time when I subscript.

可能是一个多地图的实现。然而,在写作的时候,我无法让它工作。当我下标的时候它总是返回nils。

Perhaps it can be fixed and adapted for your use.

也许它可以被修复并适应你的使用。

#1


5  

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.

NSCountedSet是一种多集(又称“包”),可以计数不同的对象,但不允许重复。但是,根据您的解释,我不认为这是您需要的,直方图也不需要,直方图根据一组(通常是数值)范围自动提取值。

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.

我相信你真正想要的是一个多映射,它是“一个或多个值的关键”关系。我维护的数据结构框架包括CHMultiDictionary,一个多映射实现。我不会说它是完美的或完整的,但是我希望它能对你的问题有所帮助。

#2


3  

It sounds to me like you simply want a dictionary of arrays. You can put NSArrays as elements of NSDictionarys, something like:

听起来你只是想要一个数组字典。可以将nsarray作为NSDictionarys的元素,比如:

NSMutableDictionary* dict = [NSMutableDictionary dictionary];
[dict setObject:[NSMutableArray arrayWithObjects:@"milk", @"eggs", @"cheese", nil] forKey:@"dairy"];
[dict setObject:[NSMutableArray arrayWithObjects:@"steak", @"sausages", @"mince", nil] forKey:@"meat"];

[[dict objectForKey:@"meat"] addObject:@"lamb"];

NSLog( @"Dictionary is %@", dict );

#3


1  

There's one in the GNU Objective-C Class library, but the docs appear to be pretty incomplete and the project's homepage must be currently having a problem -- still, if GPL software is acceptable for your project, you might want to download and check the sources.

在GNU Objective-C类库中有一个,但是文档看起来是相当不完整的,而且项目的主页现在一定有问题——但是,如果GPL软件对您的项目是可接受的,您可能想要下载并检查源代码。

#4


0  

CFIOMultimap apparently is an implementation of a multimap. However, as of the time of writing I couldn't get it to work. It returns nils all the time when I subscript.

可能是一个多地图的实现。然而,在写作的时候,我无法让它工作。当我下标的时候它总是返回nils。

Perhaps it can be fixed and adapted for your use.

也许它可以被修复并适应你的使用。