Optimization of Index

This commit is contained in:
Viktor Klang 2010-09-08 17:49:19 +02:00 committed by Viktor Klang
parent f0079cb6c8
commit eff7aeaf5c

View file

@ -157,6 +157,7 @@ class Index[K <: AnyRef,V <: AnyRef : Manifest] {
private val Naught = Array[V]() //Nil for Arrays
private val container = new ConcurrentHashMap[K, JSet[V]]
private val emptySet = new ConcurrentSkipListSet[V]
def put(key: K, value: V) {
@ -213,9 +214,10 @@ class Index[K <: AnyRef,V <: AnyRef : Manifest] {
val set = container get key
if (set ne null) {
set.synchronized {
set remove value
if (set.isEmpty)
container remove key
if (set.remove(value)) {
if (set.isEmpty)
container.remove(key,emptySet)
}
}
}
}