PSVec

dev.constructive.eo.data.PSVec
See thePSVec companion trait
object PSVec

Constructors for PSVec — the primary entry points are empty, singleton, and unsafeWrap (zero-copy from an Array[Any]). The three Slice / Single / Empty subclasses are internal to the dev.constructive.eo.data package and stable across release lines only at the aggregate PSVec supertype level.

Attributes

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

Members list

Grouped members

Instances

cats.Foldable — index-based foldLeft, Eval-deferred foldRight (stack-safe), O(1) size.

cats.Foldable — index-based foldLeft, Eval-deferred foldRight (stack-safe), O(1) size.

Attributes

Source
PSVec.scala
object pSVecFoldable extends Foldable[PSVec]

cats.Foldable — index-based foldLeft, Eval-deferred foldRight (stack-safe), O(1) size.

cats.Foldable — index-based foldLeft, Eval-deferred foldRight (stack-safe), O(1) size.

Attributes

Source
PSVec.scala
Supertypes
trait Foldable[PSVec]
trait FoldableNFunctions[PSVec]
trait UnorderedFoldable[PSVec]
trait Serializable
class Object
trait Matchable
class Any
Show all
Self type

cats.Functor — index-based map into one fresh backing array (0/1-element results normalise through unsafeWrap to Empty / Single).

cats.Functor — index-based map into one fresh backing array (0/1-element results normalise through unsafeWrap to Empty / Single).

Attributes

Source
PSVec.scala
object pSVecFunctor extends Functor[PSVec]

cats.Functor — index-based map into one fresh backing array (0/1-element results normalise through unsafeWrap to Empty / Single).

cats.Functor — index-based map into one fresh backing array (0/1-element results normalise through unsafeWrap to Empty / Single).

Attributes

Source
PSVec.scala
Supertypes
trait Functor[PSVec]
trait Invariant[PSVec]
trait Serializable
class Object
trait Matchable
class Any
Show all
Self type

cats.Traverse — the instance Traversal's .modifyA routes through when the carrier is MultiFocus[PSVec]. Effects run left-to-right in index order; results land in one pre-sized backing array (a TraverseBuf) threaded through G.map2.

cats.Traverse — the instance Traversal's .modifyA routes through when the carrier is MultiFocus[PSVec]. Effects run left-to-right in index order; results land in one pre-sized backing array (a TraverseBuf) threaded through G.map2.

That array must not be blindly shared: G may resume a continuation more than once — a multi-shot effect (List, Vector, Chain, LazyList, fs2 Stream, …) once per branch, a product effect (Tuple2K, cats' parallel-composition law) once per component, a re-runnable effect (IO, State, Kleisli, …) once per run. Two rules keep every resumption apart:

  • The buffer is allocated INSIDE the first element's continuation, not in a G.pure seed, so every branch of f(fa(0)) and every run of the returned G starts its own buffer (no shared seed — which is also what makes two concurrent runs of one IO safe).
  • Later continuations CLAIM their slot (TraverseBuf.put): the first writer at i writes in place, every further writer at i copies the prefix [0, i) — frozen, since slots are only ever written at the claim frontier — into a buffer of its own.

Single-shot effects (Option, Either, Id, Eval, IO, Validated, …) thus pay what a shared array costs (one array plus one small buffer object, no per-element structure), and multi-shot effects pay one prefix copy per extra branch, bounded by the size of the result they build anyway. The claim is a plain field, not a CAS (a CAS measured ~2× slower here): it assumes no single run of G resumes continuations on one intermediate value from two threads at once, which nothing that re-evaluates its inputs (IO, fs2, Kleisli) does.

Attributes

Source
PSVec.scala
object pSVecTraverse extends Traverse[PSVec]

cats.Traverse — the instance Traversal's .modifyA routes through when the carrier is MultiFocus[PSVec]. Effects run left-to-right in index order; results land in one pre-sized backing array (a TraverseBuf) threaded through G.map2.

cats.Traverse — the instance Traversal's .modifyA routes through when the carrier is MultiFocus[PSVec]. Effects run left-to-right in index order; results land in one pre-sized backing array (a TraverseBuf) threaded through G.map2.

That array must not be blindly shared: G may resume a continuation more than once — a multi-shot effect (List, Vector, Chain, LazyList, fs2 Stream, …) once per branch, a product effect (Tuple2K, cats' parallel-composition law) once per component, a re-runnable effect (IO, State, Kleisli, …) once per run. Two rules keep every resumption apart:

  • The buffer is allocated INSIDE the first element's continuation, not in a G.pure seed, so every branch of f(fa(0)) and every run of the returned G starts its own buffer (no shared seed — which is also what makes two concurrent runs of one IO safe).
  • Later continuations CLAIM their slot (TraverseBuf.put): the first writer at i writes in place, every further writer at i copies the prefix [0, i) — frozen, since slots are only ever written at the claim frontier — into a buffer of its own.

Single-shot effects (Option, Either, Id, Eval, IO, Validated, …) thus pay what a shared array costs (one array plus one small buffer object, no per-element structure), and multi-shot effects pay one prefix copy per extra branch, bounded by the size of the result they build anyway. The claim is a plain field, not a CAS (a CAS measured ~2× slower here): it assumes no single run of G resumes continuations on one intermediate value from two threads at once, which nothing that re-evaluates its inputs (IO, fs2, Kleisli) does.

Attributes

Source
PSVec.scala
Supertypes
trait Traverse[PSVec]
trait UnorderedTraverse[PSVec]
trait Foldable[PSVec]
trait FoldableNFunctions[PSVec]
trait UnorderedFoldable[PSVec]
trait Functor[PSVec]
trait Invariant[PSVec]
trait Serializable
class Object
trait Matchable
class Any
Show all
Self type

Type members

Classlikes

case object Empty extends PSVec[Nothing]

Zero-element shared singleton; Prism / Affine miss branches allocate nothing.

Zero-element shared singleton; Prism / Affine miss branches allocate nothing.

Attributes

Source
PSVec.scala
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait PSVec[Nothing]
trait IterableOnce[Nothing]
class Object
trait Matchable
class Any
Show all
Self type
Empty.type
final class Single[+B](val b: B) extends PSVec[B]

Single-element vector — stores the element inline, no backing array.

Single-element vector — stores the element inline, no backing array.

Attributes

Source
PSVec.scala
Supertypes
trait PSVec[B]
trait IterableOnce[B]
class Object
trait Matchable
class Any
final class Slice[+B] extends PSVec[B]

Array-backed view with offset + length. slice is a pointer update over the shared backing array — the zero-copy reassembly path mfAssocPSVec depends on.

Array-backed view with offset + length. slice is a pointer update over the shared backing array — the zero-copy reassembly path mfAssocPSVec depends on.

Attributes

Source
PSVec.scala
Supertypes
trait PSVec[B]
trait IterableOnce[B]
class Object
trait Matchable
class Any

Value members

Concrete methods

def empty[B]: PSVec[B]

Zero-length shared vector.

Zero-length shared vector.

Attributes

Source
PSVec.scala
def from[B](xs: IterableOnce[B]): PSVec[B]

Build a PSVec from any collection. A PSVec passes through untouched; ArraySeq.ofRef's backing array is aliased zero-copy (safe: ArraySeq is immutable and no PSVec operation mutates a wrapped array); every other shape collects through the stdlib Iterator.toArray (exact-fill when knownSize is known, ArrayBuilder otherwise), specialised at 0 / 1 by unsafeWrap.

Build a PSVec from any collection. A PSVec passes through untouched; ArraySeq.ofRef's backing array is aliased zero-copy (safe: ArraySeq is immutable and no PSVec operation mutates a wrapped array); every other shape collects through the stdlib Iterator.toArray (exact-fill when knownSize is known, ArrayBuilder otherwise), specialised at 0 / 1 by unsafeWrap.

Attributes

Source
PSVec.scala
def from[B](arr: Array[B]): PSVec[B]

Build a PSVec from an Array — one defensive copy (Array.copyAs: an intrinsic arraycopy for reference arrays, a boxing fill for primitive ones). The array is caller-owned and mutable, so it can NOT be aliased the way immutable ArraySeq.ofRef's backing is. Also spares the Predef.genericWrapArray allocation the IterableOnce overload would force on an Array argument.

Build a PSVec from an Array — one defensive copy (Array.copyAs: an intrinsic arraycopy for reference arrays, a boxing fill for primitive ones). The array is caller-owned and mutable, so it can NOT be aliased the way immutable ArraySeq.ofRef's backing is. Also spares the Predef.genericWrapArray allocation the IterableOnce overload would force on an Array argument.

Attributes

Source
PSVec.scala
def from[T[_] : Foldable, A](ta: T[A]): PSVec[A]

from for any Foldable container, in fold order. An IterableOnce-backed container — PSVec itself included — routes through the structural overload (sound whenever the instance folds in iteration order, as every cats instance does); anything else collects through its own foldLeft.

from for any Foldable container, in fold order. An IterableOnce-backed container — PSVec itself included — routes through the structural overload (sound whenever the instance folds in iteration order, as every cats instance does); anything else collects through its own foldLeft.

Attributes

Source
PSVec.scala
def of[B](b0: B, b1: B): PSVec[B]

Two-element vector — builds the backing array directly, no List / Iterable intermediate. The common arity for binary-tree children (recursion-scheme coalgebras, Node(l, r)), where PSVec.of(l, r) replaces the wasteful from(List(l, r)).

Two-element vector — builds the backing array directly, no List / Iterable intermediate. The common arity for binary-tree children (recursion-scheme coalgebras, Node(l, r)), where PSVec.of(l, r) replaces the wasteful from(List(l, r)).

Attributes

Source
PSVec.scala
def singleton[B](b: B): PSVec[B]

Single-element vector, stored inline (no backing array).

Single-element vector, stored inline (no backing array).

Attributes

Source
PSVec.scala
def unsafeWrap[B](arr: Array[Any]): PSVec[B]

Wrap an Array[Any] verbatim as a PSVec. Shares ownership with the caller. Returns the most specialised variant for the array's length so callers need not special-case empty / singleton themselves.

Wrap an Array[Any] verbatim as a PSVec. Shares ownership with the caller. Returns the most specialised variant for the array's length so callers need not special-case empty / singleton themselves.

Attributes

Source
PSVec.scala