org.sigilaris.core.codec

Members list

Type members

Classlikes

trait OrderedCodec[A] extends ByteCodec[A], Ordering[A]

OrderedCodec extends ByteCodec with an ordering preservation law.

OrderedCodec extends ByteCodec with an ordering preservation law.

Law: compare(x, y) ≡ encode(x).compare(encode(y))

This ensures that the encoded byte representation preserves the ordering relationship of the original values. This property is critical for blockchain applications where prefix-free encoding and key ordering matter.

The law states: For all x, y of type A, sign(compare(x, y)) == sign(encode(x).compare(encode(y)))

Where sign(n) is:

  • negative if n < 0
  • zero if n == 0
  • positive if n > 0

Attributes

Example
 val codec = OrderedCodec[Long]
 val x     = -100L
 val y     = 200L
 // The law guarantees:
 // x.compare(y) < 0  ⟹  encode(x).compare(encode(y)) < 0
Companion
object
Source
OrderedCodec.scala
Supertypes
trait Ordering[A]
trait PartialOrdering[A]
trait Equiv[A]
trait Serializable
trait Comparator[A]
trait ByteCodec[A]
trait ByteEncoder[A]
trait ByteDecoder[A]
class Object
trait Matchable
class Any
Show all
object OrderedCodec

Attributes

Companion
trait
Source
OrderedCodec.scala
Supertypes
class Object
trait Matchable
class Any
Self type