没有“有效负载”的字典; .Net 中的价值
有时,我需要检查一组值中是否有重复的 ID,通常我会使用字典来执行此操作 - 仅使用键并将值保留为空。
请注意,这是严格且高度优化的代码,因此请不要抱怨“过早优化”!假设 CPU 和 RAM 被挤压到极限的场景,我想收集关于更优化解决方案的意见;大概像 Lookup 类这样的东西会避免不必要的 RAM 分配,因此会稍微快一些。 BCL 中是否存在第三方此类或我忽略的某些类?
我知道谷歌已经发布了快速和紧凑字典类的代码 - 也许其中有一些东西可以移植到 C#/.Net?
谢谢。
Occassionally I need to check for duplicate IDs in a set of values and generally I use a Dictionary for this - using just the keys and leaving values empty.
Note that this is tight and highly optimized code so please no cries of 'premature optimization'! Assuming scenarios where CPU and RAM are being squeezed to the limit I was wanting to gather opinions on more optimal solutions; presumably something like a Lookup class would avoid unnecessary RAM allocations and would thus be slightly faster. Are there such classes either third party or perhaps some class I've overlooked in the BCL?
I understand google have released code for both fast and compact dictionary classes - perhaps there's something in there that could be ported to C#/.Net?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 .NET 3.5 中的 HashSet 类。
Use the HashSet class in .NET 3.5.