净征集雾化T' [英] .Net Collection for atomizing T?

查看:193
本文介绍了净征集雾化T'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找是否有pre-现有的.NET散列集型实施适合雾化一般类型T.我们有大量相同的对象,成为被需要序列化源雾化以节省内存。

I am looking if there is a pre-existing .Net 'Hash-Set type' implementation suitable to atomizing a general type T. We have a large number of identical objects coming in for serialized sources that need to be atomized to conserve memory.

A 词典< T,T>与值==键作品完美,但在这些集合中的对象可以运行到各地数以百万的应用程序,所以它看起来非常浪费存储2引用的每一个对象。

A Dictionary<T,T> with the value == key works perfectly, however the objects in these collections can run into the millions across the app, and so it seem very wasteful to store 2 references to every object.

的HashSet 不能使用,因为它只是已经包含有?没有办法?到达实际构件实例

HashSet cannot be used as it only has Contains, there ?is no way? to get to the actual member instance.

很显然,我会推出自己的,但要检查是否有什么pre存在。在C5的扫描没有看到任何东西跳出来,但随后他们的250+页文档,确实让我知道如果我错过了一些东西。

Obviously I could roll my own but wanted to check if there was anything pre-existing. A scan at C5 didn't see anything jumping out, but then their 250+ page documentation does make me wonder if I've missed something.

修改的基波的想法是,我需要能够后退的唯一对象的即HashSet的具有包含(T OBJ),但没有得到(T obj)以<强> /修改

EDIT The fundemental idea is I need to be able to GET THE UNIQUE OBJECT BACK ie HashSet has Contains(T obj) but not Get(T obj) /EDIT

收集在最坏的情况只需要实现:

The collection at worst only needs to implement:

T GetOrAdd(T candidate)
void Clear()

和采取arbitary的IComparer 而GetOrAdd的〜O(1),并会的理想的是原子,即不浪费时间哈希两次。

And take an arbitary IComparer And GetOrAdd is ~O(1) and would ideally be atomic, i.e. doesn't waste time Hashing twice.

修改上源的基本散列失败现有实施任何建议/铲装机械将AP preciated。 - 在单HashSet的来源已经指出了这一点,因此这部分回答 /修改

EDIT Failing an existing implementation any recommendations on sources for the basic Hashing / Bucketing mechanics would be appreciated. - The Mono HashSet source has been pointed out for this and thus this section is answered /EDIT

推荐答案

您可以乘坐的HashSet℃的来源$ C ​​$ C; T&GT; 从的基准源并编写自己的GetOrAdd方法。

You can take a source code of a HashSet<T> from Reference Source and write your own GetOrAdd method.

这篇关于净征集雾化T'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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