Notes › Tech Notes › Text Set Operations Measured: Duplicates and Order

Text Set Operations Measured: Duplicates and Order

Three duplicate rows on side A against one row on side B: the page returns one intersection row by default and three with result dedupe off, matching neither set nor multiset semantics. Output order follows A, dedupe runs before comparison, only newlines split rows, and a cleared page still copies the old result.

Pinning the scene: three occurrences against one, the default mode yields one row

This article measures the duplicate-value and output-order ledgers of the text set operations page. Side A feeds three m rows, side B one m row; under the default mode the intersection is 1 row, the difference 0 rows, the union 1 row. Reverse the inputs and the intersection and union still give one row each; three rows on both sides still give one intersection row. The default mode folds rows into one before comparison — plain set semantics.

Turning result dedupe off: neither a set nor a multiset

Switch to the r series: A rows "r, r, r" against B row "r". Dedupe off, the intersection prints 3 rows (innerHTML 258 code units), the union 4 rows (344 code units); three rows per side give 3 intersection rows and 6 union rows (516 code units). A true multiset intersection would take min(3,1), one row, yet the measurement gives three: the off-mode intersection returns every A-side raw row whose key hit, and the union simply takes m+n. The comparison table:

Input (A vs B)Result dedupeIntersection rowsUnion rows
three m rows vs one m rowOn11
one m row vs three m rowsOn11
three m rows vs three m rowsOn11
three r rows vs one r rowOff34
three r rows vs three r rowsOff36
Dedupe ON folds first; dedupe OFF keeps every A rowA: three m rowsB: one m rowON: parseSet folds firstcnt-a = 1Default mode, set semanticsIntersection 1 / union 1 / diff 0A: three r rowsB: one r rowOFF: raw rows keptevery hit row goes outOFF: neither set nor multisetIntersection 3, union 4 (union 6)A multiset would take min(3,1)=1 row; measured 3 rows are every hit row on side A

Figure 1. Row counts for identical inputs under the on and off modes.

Output order always follows side A's input order

A inputs three rows 丙、乙、甲, B receives the reverse 甲、乙、丙; the intersection still prints the same three rows in A's order (innerHTML 258 code units), and the union does too — B's order contributes nothing. Shrink B to one row 丙 and the difference returns 乙 then 甲, two rows in A's order. All three operations follow A: the source walks only listA for intersection and difference, and the union walks listA first, listB second.

Dedupe happens before the comparison

A gives two rows: Ga with one trailing space, then ga; B gives GA. Dedupe on: cnt-a=1, the intersection prints one row, Ga — two rows entered, one displayed, a gap of one, so dedupe completes inside parseSet before comparison. Dedupe off: cnt-a=2, the intersection prints Ga and ga (174 code units), the union prints Ga, ga and GA (261 code units). Both raw forms match GA at once, proving the compared key is the trimmed, lowercased shape while the exit prints raw.

Splitting scope: the newline and nothing else

The source splits on newlines only, once, and the page offers no separator option. A single row aa,bb;cc followed by a tab and dd stays unbroken: commas, semicolons and tabs never cut a row, cnt-a=1, still one segment of 11 code units. A rows k1, k2,k3;k4 and k5 count three elements; against B's whole row k2,k3;k4 the intersection hits one row. CRLF ledger: with a carriage return plus newline between A's two rows against B rows a and b, trim on gives a two-row intersection, trim off leaves only b. The carriage return is row content here, not a separator.

Line-count conservation: five ledgers all close

  • Blank line inside: A rows a1, an empty row, b1 give default cnt-a=2; turning the ignore-blank-lines switch off makes it 3, the union prints 4 rows whose second is empty, and the copy comes out as a1, blank, b1, zzz.
  • Trailing newline: A rows a1 and b1 plus a final newline — the empty tail segment is swallowed, cnt-a=2.
  • All whitespace: a row of three spaces, a row starting with one tab, an empty segment — default cnt-a=0; with both switches off the union prints 4 rows and the whitespace and tab rows return verbatim.
  • Equal sets: solo1 against solo1 gives one row; both sides p1, q1, r2 means three rows in, three out, intersection 3, difference 0, union 3.
  • Disjoint sets: c1, c2 against c3, c4 gives intersection 0, difference 2, union 4, and 4=2+2, so conservation holds.

Empty input and the 87 code units that never clear

With both sides empty, the unconditional first calc() has already overwritten the 15-code-unit placeholder markup with the 10-code-unit notice that the result is an empty set ∅; statistics read 0/0/0 and the bar stays visible. A row w9 against empty B sends the intersection to the ∅ wording; the union prints one row. Residue ledger: A rows w1 and w2 against B row w1 give a one-row intersection, innerHTML 87 code units. Clearing A drops cnt-r to 0 and hides the card, yet result-list still holds those same 87 code units, so copy carries last round's w1 out verbatim with no toast; clearing both sides still yields w1. The no-results toast is reachable only if the page never produced a non-empty result.

Display and copy match character by character, and there is no third exit

Samples A and B are both two rows; the first packs x in angle brackets, an ampersand, and y in double quotes (shape: <x> & "y"), the second is n2. The intersection has two rows; display-side innerHTML is 201 code units, the first line in entity-escaped form. The copied string is the raw two rows, 14 code units total: first line 11 code units, lines joined by newlines, no trailing newline, matching the displayed text character by character after entity decoding. The escape function leaves single quotes untouched. The words download, Blob, navigator.clipboard and export each appear 0 times in the script block, so there is no export exit.

Scale ledger: 200 rows and 1000 rows, both without truncation

200 rows against 200 rows with 100 overlapping: the intersection prints 100 rows in 0.84 ms, the union 300 rows in 0.44 ms (innerHTML 27492 code units), the difference 100 rows in 0.58 ms. With 1000 rows per side and 500 overlapping: the intersection prints 500 rows in 1.19 ms (45892 code units), the union 1500 rows in 1.67 ms (138393 code units, copy string 8999 code units), and dedupe-off union reaches 2000 rows in 1.8 ms (184893 code units). Decoded row counts equal cnt-r, so no silent cap truncates. These timings measure calc() inside a DOM stub, exclude browser layout, and must not be extrapolated to real devices; the one-side-empty case was not measured separately, so 1000 rows on both sides is the heaviest tier.

Three code-unit ledgers at the 1000-row tier (axis = innerHTML units)Intersection 50045892 units, 1.19 msUnion 1500138393 units1.67 msOFF union 2000184893 units, 1.8 msCopy string 8999 units here; parsed rows = cnt-r, no truncationTimings: calc() in a DOM stub, browser layout excluded

Figure 2. Exit code units and timings with 1000 rows on each side.

Four places where the site blurb disagrees

Taking measurements as the record: the blurb lists dedupe as always-on, yet with the switch off the intersection still prints three rows; the keyword "text comparison" overpromises, since rows are never aligned side by side; "real-time results" contradicts the residue state where a cleared page still copies the old answer; and the union wording "merge and dedupe" clashes with the off-mode three-plus-three giving six. To reproduce, open Text Set Operations and run the m and r pairs through it; if your habit is to sort before comparing, use Text Sort and Dedupe; row-level keep, delete and slice work lives in Text Line Operations.

Quick answers

Q: With result dedupe off, is the intersection computed as a multiset?

A: No. The off-mode intersection prints side A's hit rows as they are; only dedupe-before-comparison is set semantics.

Q: Can it split rows on commas or semicolons?

A: No. The split only follows newlines, so such a row stays one segment of 11 code units, commas and tabs intact.

Q: After clearing the inputs, does copy hand me an empty string?

A: No. Copy still carries last round's result away; the no-results toast appears only before the first non-empty result.

📎 Related articles

HTML Beautify Deletes the Blank Line Inside pre 2026-11-28 Two EXIF Segments in One Photo, but the Web Viewer Only Reads the First One's 12 Tags 2026-11-28 Why 1 GB at 100 Mbps Shows 1 min 29 sec: The Divide by 8 and the 90 Percent Discount on This Page 2026-11-27 Standard Deviation Calculator, Two Conventions Measured: Sample 5.12696 vs Population 4.795832 at 1.069045 Times 2026-11-27 Same 90/80 as 30/70, 3/7 or 0.3/0.7 Gives 83, but the Contribution Column Sums to 0.9999 2026-11-27