% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/50-ordered_sequence-ops.R
\name{merge.ordered_sequence}
\alias{merge.ordered_sequence}
\title{Merge Two Ordered Sequences}
\usage{
\method{merge}{ordered_sequence}(x, y, ...)
}
\arguments{
\item{x}{An \code{ordered_sequence}.}

\item{y}{An \code{ordered_sequence}.}

\item{...}{Unused.}
}
\value{
A new \code{ordered_sequence} of size \code{length(x) + length(y)}.
}
\description{
Returns a new \code{ordered_sequence} containing every entry from both inputs,
preserving key order. On duplicate keys, \code{x}'s entries precede \code{y}'s
(left-biased FIFO).
}
\details{
The merge runs in O(m + n) via a zipper-style traversal, with a fast path
to O(log(min(m, n))) when the key ranges are disjoint (all of \code{x}'s keys
\code{<=} all of \code{y}'s keys, or vice versa with a strict \code{<} to keep
left-biased FIFO intact on equal boundary keys).

Both sequences must share the same key type and the same monoid set;
mismatches error rather than being silently harmonized. Merging an
empty sequence with a non-empty sequence returns the non-empty one
unchanged.

Both inputs are left unmodified.
}
\examples{
a <- ordered_sequence("a1", "a2", "a3", keys = c(1, 3, 5))
b <- ordered_sequence("b1", "b2", "b3", keys = c(2, 3, 6))
m <- merge(a, b)
as.list(m)
# At the tied key 3, "a2" precedes "b2".
}
