MCPcopy Create free account
hub / github.com/TanStack/db / diffHalfOpen

Function diffHalfOpen

packages/db-ivm/src/utils.ts:156–173  ·  view source on GitHub ↗
(a: HRange, b: HRange)

Source from the content-addressed store, hash-verified

154 * @returns The difference between the two ranges
155 */
156export function diffHalfOpen(a: HRange, b: HRange) {
157 const [a1, a2] = a
158 const [b1, b2] = b
159
160 // A \ B can be up to two segments (left and right of the overlap)
161 const onlyInA: Array<number> = [
162 ...range(a1, Math.min(a2, b1)), // left side of A outside B
163 ...range(Math.max(a1, b2), a2), // right side of A outside B
164 ]
165
166 // B \ A similarly
167 const onlyInB: Array<number> = [
168 ...range(b1, Math.min(b2, a1)),
169 ...range(Math.max(b1, a2), b2),
170 ]
171
172 return { onlyInA, onlyInB }
173}
174
175function range(start: number, end: number): Array<number> {
176 const out: Array<number> = []

Callers 1

moveMethod · 0.85

Calls 1

rangeFunction · 0.85

Tested by

no test coverage detected