HashConsed

scalus.serialization.flat.HashConsed
object HashConsed

Objects are hash-consed during restoring from file. Note, that identityHashCode can be different on the different VM-s, so it is not safe to reky on it. value-based hash-code now is not determenistics on recuresive data structures with self-references. So, we use identityHashCode on VN which store file and restore internal references on other VN.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
HashConsed.type

Members list

Type members

Classlikes

class CachedTaggedRef[A <: AnyRef](val tag: Tag, val ref: HashConsedRef[A]) extends HashConsedRef[A]

Attributes

Supertypes
trait HashConsedRef[A]
class Object
trait Matchable
class Any
case class ConstRef[A <: AnyRef](value: A) extends HashConsedRef[A]

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
trait HashConsedRef[A]
class Object
trait Matchable
class Any
Show all
object ConstRef

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
ConstRef.type
class ForwardRef[A <: AnyRef](val ihc: Int, val tag: Tag) extends HashConsedRef[A]

Attributes

Companion
object
Supertypes
trait HashConsedRef[A]
class Object
trait Matchable
class Any
object ForwardRef

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
ForwardRef.type
class ForwardRefAcceptor(val ihc: Int, val tag: Tag, var setRefActions: List[(HashConsedRef[_]) => Unit])

Attributes

Supertypes
class Object
trait Matchable
class Any
class ForwardValueAcceptor(var setValueActions: List[AnyRef => Unit])

Attributes

Supertypes
class Object
trait Matchable
class Any
class KeyAssignment(val tag: Tag, val key: Int)

Key assigned to an object during encoding. The tag is remembered to detect an attempt to encode the same object under two different tag namespaces, which would leave the second namespace without an encoded body.

Key assigned to an object during encoding. The tag is remembered to detect an attempt to encode the same object under two different tag namespaces, which would leave the second namespace without an encoded body.

Attributes

Supertypes
class Object
trait Matchable
class Any
class MutRef[A <: AnyRef](var value: A | Null) extends HashConsedRef[A]

Attributes

Companion
object
Supertypes
trait HashConsedRef[A]
class Object
trait Matchable
class Any
object MutRef

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
MutRef.type
case class State(forwardRefAcceptors: Map[(Int, Int), ForwardRefAcceptor], refs: Map[(Int, Int), CachedTaggedRef[_]], forwardValueAcceptors: Map[(Int, Int), ForwardValueAcceptor])

Value parameters

forwardRefAcceptors

- set of forward references, which are not yet resolved from hashConded

forwardValueAcceptors

- set of callbacks, which should be called after the value is readed.

refs

- set of references

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object State

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
State.type

Types

opaque type Tag

Value members

Concrete methods

def allocKey(state: State, a: AnyRef, tag: Tag): Int

Allocate the wire key for a on the encoder side.

Allocate the wire key for a on the encoder side.

The key written to the stream is an opaque identifier: the decoder only uses it to match references, so the encoder is free to choose any value. a.hashCode is only the starting point; if the slot is occupied by a structurally different object (a 32-bit hash collision, routine for recursive types whose hash passes through TypeProxy.identityHashCode), we probe successive keys until we find a free slot or an equal object. Without this, a collision would silently encode the second object as a reference to the first.

Deterministic given the traversal order, so the bitSize and encode passes (each starting from an empty State) assign identical keys.

Attributes

def finishCallbacks(s: State, debug: Boolean = ...): Unit
def lookup(s: State, ihc: Int, tag: Tag): Option[Either[ForwardRefAcceptor, HashConsedRef[_]]]
def lookupValue(s: State, ihc: Int, tag: Tag): Option[HashConsedRef[_]]
def putForwadValueAcceptor[A <: AnyRef](state: State, ihc: Int, tag: Tag, acceptor: A => Unit): Unit
def setRef[A <: AnyRef](state: State, ihc: Int, tag: Tag, ra: HashConsedRef[A]): Unit
def tag(value: Int): Tag