Finding Changed Membership with Symmetric Difference
Symmetric difference contains items present in exactly one of two sets. It detects membership changes in either direction.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Compare two snapshots
Before a release, enabled labels are alpha and beta. Afterward they are beta and gamma. Symmetric difference gives alpha and gamma. One was removed and one added. For direction use the two separate set differences.
Keep changes in value visible
If beta remains enabled with different settings, symmetric difference on labels does not detect the changed settings. Compare map entries for shared keys as a separate step. See record equality for classifying snapshots of one entity.[1]
Separate changed membership by direction
If yesterday's active IDs were \(\{3,5,9\}\) and today's are \(\{5,7,9\}\), the symmetric difference contains three and seven. It communicates that something changed but does not reveal which was an arrival. Today's set minus yesterday's gives seven as added. Reversing the operands gives three as removed. Compute the directional results first if people need to interpret the report. See ordinary set difference.
Check whether the change lives in fields or membership
If ID five stays in both sets but its name changes, symmetric difference over IDs cannot report the edit. Compare the records for keys in the intersection to detect that case. Use the same ID policy across both snapshots. A reused identifier can look like a changed record when it actually refers to a replacement. Test an addition, removal and edit together. See stable identifiers.