搜索速度快、体积小的数据结构搜索
我正在寻找数据结构来存储唯一索引(整数)列表。对我来说最重要的功能是:
- 快速检查值是否存在于值集中 - 就像散列表中一样
- 内存大小小并且序列化后 - 像数组
它当然应该支持添加、删除元素,但此操作的性能并不重要。
框架中是否有以这种方式工作的结构?或者我应该创建它?
使用示例: 我为用户开设了课程,在这个课程中,有一些(~20)各种数据的列表。 (访问权、特权、文件等)。我需要将用户数据存储在缓存中,以便在回发期间快速访问 - 每次查询数据库非常慢。整数是 db 中的索引,
I'm searching for data structure to store list of unique indices (integers). The most important features for me are:
- fast checking if value exists in set of values - like in hashtable
- small size in memory and after serialization - like array
It should of course support adding, removing elements, but performance of this actions aren't significiant.
Is there any structure in framework that works in this way? Or I should create it?
Example of use:
I have class for user and in this class few (~20) lists of various data. (accesses, privilages, documents etc). I need to store user data in cache for fast access during postbacks - querying DB each time is very slow. Integers are indices in db,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您正在寻找 HashSethttp://msdn.microsoft.com/en-us/library/bb359438.aspx
它的实现是为了提供 O(1) 查找(或者文档是这么说的,但我怀疑它实际上是摊销的 O(1),因为它是用 Hashtables 实现的......)并支持许多集合操作。
我不确定它的序列化形式,但我会进一步调查它。如果你确实希望它序列化为数组,你总是可以这样做
,然后反序列化只需从序列化数组创建一个 HashSet 即可。
I think you're looking for HashSet<T> http://msdn.microsoft.com/en-us/library/bb359438.aspx
It's implemented so that it provides O(1) lookups (or so the documentation says, however I suspect its really an amortized O(1) since its implemented with Hashtables...) and supports many set operations.
I am not sure of its serialized form, but I will investigate it further. If you really want it to serialize to an array you could always do
and then to deserialize just create a HashSet from the serialized array.