Case Folding for Collection Keys

Normalize lookup keys when a domain defines a case-insensitive identity. Apply the same rule to both storage and retrieval.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace two apparent duplicates
  2. Check domain limits
  3. Preserve display text while resolving lookup keys
  4. Keep comparison policy tied to the domain

Trace two apparent duplicates

A tag index can use the comparison key north for both North and NORTH. Inserting the second spelling then updates or rejects it under the chosen collision rule. Canonicalizing labels treats the human-readable spelling separately from the key.

Check domain limits

An external identifier with case-sensitive parts should retain the specified casing. Make separate fields for display and lookup when both matter. Record identity and snapshot equality explain where duplicate detection belongs.[1]

Preserve display text while resolving lookup keys

Suppose an application compares user-entered categories without case distinctions. A stored label can keep the submitted spelling while its dictionary key uses case folding. In Python, the folded forms of "Straße" and "STRASSE" agree. The resulting collision needs an explicit policy if the records previously had different identities. Test both spellings at insertion and lookup. See case-folded comparisons.

Keep comparison policy tied to the domain

Case folding is designed for caseless text comparisons. A protocol identifier with strict byte equality follows different rules. Even when case folding is wanted, canonically equivalent combining sequences can require normalization as part of the key policy. Store one consistently transformed key, and compare changes to the policy against real existing collisions. Test a composed and decomposed spelling alongside a case-only pair. See normalization and equality.

References

  1. Python Software Foundation, Python Standard Library: Built-in Types ↩