de.sciss.lucre.impl.IdentMapImpl.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lucre-core_3 Show documentation
Show all versions of lucre-core_3 Show documentation
Extension of Scala-STM, adding optional durability layer, and providing API for confluent and reactive event layers
The newest version!
/*
* IdentMapImpl.scala
* (Lucre 4)
*
* Copyright (c) 2009-2024 Hanns Holger Rutz. All rights reserved.
*
* This software is published under the GNU Affero General Public License v3+
*
*
* For further information, please contact Hanns Holger Rutz at
* [email protected]
*/
package de.sciss.lucre
package impl
import scala.concurrent.stm.TMap
object IdentMapImpl {
def apply[T <: Txn[T], A](intView: T => Ident[T] => Int): IdentMap[T, A] =
new InMemoryInt[T, A](intView)
private final class InMemoryInt[T <: Txn[T], A](intView: T => Ident[T] => Int)
extends IdentMap[T, A] {
private[this] val peer = TMap.empty[Int, A]
def get(id: Ident[T])(implicit tx: T): Option[A] = peer.get(intView(tx)(id))(tx.peer)
def getOrElse(id: Ident[T], default: => A)(implicit tx: T): A = get(id).getOrElse(default)
def put(id: Ident[T], value: A)(implicit tx: T): Unit =
peer.put(intView(tx)(id), value)(tx.peer)
def contains(id: Ident[T])(implicit tx: T): Boolean = peer.contains(intView(tx)(id))(tx.peer)
def remove(id: Ident[T])(implicit tx: T): Unit =
peer.remove(intView(tx)(id))(tx.peer)
override def toString = s"IdentifierMap@${hashCode.toHexString}"
// def write(out: DataOutput): Unit = ()
def dispose()(implicit tx: T): Unit = ()
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy