高性能并发 MultiMap Java/Scala [英] High-performance Concurrent MultiMap Java/Scala
问题描述
我正在寻找一种高性能、并发的 MultiMap.我到处搜索,但我根本找不到使用与 ConcurrentHashMap 相同方法的解决方案(仅锁定哈希数组的一部分).
I am looking for a high-performance, concurrent, MultiMap. I have searched everywhere but I simply cannot find a solution that uses the same approach as ConcurrentHashMap (Only locking a segment of the hash array).
多图将经常被读取、添加和删除.
The multimap will be both read, added to and removed from often.
多映射键是一个字符串,它的值是任意的.
The multimap key will be a String and it's value will be arbitrary.
我需要 O(1) 来找到给定键的所有值,O(N) 可以删除,但 O(logN) 是首选.
I need O(1) to find all values for a given key, O(N) is OK for removal, but O(logN) would be preferred.
删除给定键的最后一个值会从键中删除值的容器,以免泄漏内存,这一点至关重要.
It is crucial that removal of the last value for a given key will remove the container of values from the key, as to not leak memory.
这是我构建的解决方案,可在 ApacheV2 下使用:索引(多图)
HERE'S THE SOLUTION I BUILT, available under ApacheV2: Index (multimap)
推荐答案
为什么不将 ConcurrentHashMap[T,ConcurrentLinkedQueue[U]] 用一些类似 Scala 的好方法(例如隐式转换为 Iterable 或任何您需要的方法,和更新方法)?
Why not wrap ConcurrentHashMap[T,ConcurrentLinkedQueue[U]] with some nice Scala-like methods (e.g. implicit conversion to Iterable or whatever it is that you need, and an update method)?
这篇关于高性能并发 MultiMap Java/Scala的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!