.Net Collection for atomizing T?

拜拜、爱过 提交于 2019-12-08 02:43:39

问题


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 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 cannot be used as it only has Contains, there ?is no way? to get to the actual member instance.

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.

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()

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

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


回答1:


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



来源:https://stackoverflow.com/questions/28761807/net-collection-for-atomizing-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!