From 9d3014ad3cbf2bdafc8b1548079950ddea5f07a9 Mon Sep 17 00:00:00 2001 From: tabcat Date: Sun, 23 Jun 2024 18:12:45 -0400 Subject: [PATCH] rename pairwiseTraversal params and variables also made changes to jsdoc wording --- src/util.ts | 66 ++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/util.ts b/src/util.ts index fdd3491..cab4bd3 100644 --- a/src/util.ts +++ b/src/util.ts @@ -73,68 +73,68 @@ export const iteratorIsDone = (result: IteratorResult): boolean => result.value === undefined && result.done === true; /** - * Yields pairwise traversal of two ordered sets. + * Yields pairwise traversal of two ordered arrays. * - * @param source - Source ordered set - * @param target - Target ordered set + * @param iterableA - First ordered array + * @param iterableB - Second ordered array * @param comparator - Used to compare two set elements, same as Array.sort parameter */ export function* pairwiseTraversal( - source: Iterable, - target: Iterable, + iterableA: Iterable, + iterableB: Iterable, comparator: (a: A, b: B) => number, ): Generator<[...PairwiseElement, ...PairwiseDone]> { - const iteratorS = source[Symbol.iterator](); - const iteratorT = target[Symbol.iterator](); + const iteratorA = iterableA[Symbol.iterator](); + const iteratorB = iterableB[Symbol.iterator](); - // initialize s and t - let s = iteratorS.next(); - let t = iteratorT.next(); + // initialize a and b values + let a = iteratorA.next(); + let b = iteratorB.next(); - let sourceDone = iteratorIsDone(s); - let targetDone = iteratorIsDone(t); + let aIsDone = iteratorIsDone(a); + let bIsDone = iteratorIsDone(b); - while (!sourceDone && !targetDone) { - const order = comparator(s.value, t.value); + while (!aIsDone && !bIsDone) { + const order = comparator(a.value, b.value); - const result = [null, null, sourceDone, targetDone] as [ + const result = [null, null, aIsDone, bIsDone] as [ ...PairwiseElement, ...PairwiseDone, ]; if (order <= 0) { - result[0] = s.value; - s = iteratorS.next(); + result[0] = a.value; + a = iteratorA.next(); } if (order >= 0) { - result[1] = t.value; - t = iteratorT.next(); + result[1] = b.value; + b = iteratorB.next(); } yield result; - if (s.done === true) { - sourceDone = iteratorIsDone(s); + if (a.done === true) { + aIsDone = iteratorIsDone(a); } - if (t.done === true) { - targetDone = iteratorIsDone(t); + if (b.done === true) { + bIsDone = iteratorIsDone(b); } } - while (!sourceDone) { - yield [s.value, null, sourceDone, targetDone]; - s = iteratorS.next(); - if (s.done === true) { - sourceDone = iteratorIsDone(s); + while (!aIsDone) { + yield [a.value, null, aIsDone, bIsDone]; + a = iteratorA.next(); + if (a.done === true) { + aIsDone = iteratorIsDone(a); } } - while (!targetDone) { - yield [null, t.value, sourceDone, targetDone]; - t = iteratorT.next(); - if (t.done === true) { - targetDone = iteratorIsDone(t); + while (!bIsDone) { + yield [null, b.value, aIsDone, bIsDone]; + b = iteratorB.next(); + if (b.done === true) { + bIsDone = iteratorIsDone(b); } } }