1// A complete article demonstrating Typst features together2
3#set document(4 title: "Content-Addressable Storage for Version Control",5 author: "sublimated docs",6)7#set page(paper: "a4", margin: (x: 2.5cm, y: 3cm), numbering: "1")8#set text(size: 11pt)9#set par(justify: true, leading: 0.65em)10#set heading(numbering: "1.1")11
12// Custom note block13#let note(body) = block(14 width: 100%,15 fill: rgb("#f0f7ff"),16 stroke: rgb("#3b82f6") + 0.5pt,17 inset: 12pt,18 radius: 4pt,19)[#text(weight: "bold", size: 9pt, fill: rgb("#3b82f6"))[NOTE ] #body]20
21// Title22#align(center)[23 #text(size: 20pt, weight: "bold")[Content-Addressable Storage\ for Version Control]24 #v(0.5em)25 #text(size: 12pt, fill: luma(100))[A practical overview]26 #v(1em)27]28
29= Introduction <intro>30
31Content-addressable storage (CAS) identifies data by its content hash rather than by location. This approach is fundamental to version control systems like Git, where every object — blob, tree, commit — is addressed by its SHA-1 hash.32
33#note[This article demonstrates Typst features. Push it to sublimated to see it rendered as a multi-page document.]34
35= How CAS works36
37== Hash functions38
39A hash function $H$ maps arbitrary data $D$ to a fixed-size digest:40
41$ H: {0, 1}^* -> {0, 1}^n $42
43For CAS to work, the hash must be:44
45- *deterministic* — same input always produces same output46- *collision-resistant* — hard to find $x != y$ where $H(x) = H(y)$47- *fast* — hashing should not be a bottleneck48
49== Common algorithms50
51#figure(52 table(53 columns: (1fr, auto, auto, auto),54 fill: (x, y) => if y == 0 { luma(235) },55 [*Algorithm*], [*Digest size*], [*Speed*], [*Status*],56 [SHA-1], [160 bits], [~500 MB/s], [Deprecated],57 [SHA-256], [256 bits], [~300 MB/s], [Standard],58 [BLAKE3], [256 bits], [~3 GB/s], [Modern],59 ),60 caption: [Hash algorithm comparison],61) <hash-table>62
63As shown in @hash-table, BLAKE3 offers significantly better throughput while maintaining security properties equivalent to SHA-256.64
65== Content identifiers66
67A self-describing content identifier (CID) includes the algorithm:68
69```70blake3-a1b2c3d4e5f6...71sha256-9f86d081884c...72```73
74This makes the system future-proof — new algorithms can be added without breaking existing references.75
76= Applications77
78== Deduplication79
80When two files have identical content, they produce the same hash and are stored once:81
82$ "store"(f_1) = "store"(f_2) "iff" H(f_1) = H(f_2) $83
84#let savings(n, d) = calc.round((1 - (n - d) / n) * 100, digits: 1)85
86#figure(87 table(88 columns: 4,89 fill: (x, y) => if y == 0 { luma(235) },90 [*Dataset*], [*Total files*], [*Unique*], [*Space saved*],91 [Source code], [12,450], [8,230], [#savings(12450, 8230)%],92 [Documents], [3,200], [2,890], [#savings(3200, 2890)%],93 [Media], [850], [845], [#savings(850, 845)%],94 ),95 caption: [Deduplication effectiveness by content type],96)97
98== Immutable history99
100Every version of every file is preserved. A commit is a tree of hashes:101
102```103commit abc123104├── tree def456105│ ├── blob 1a2b3c README.md106│ ├── blob 4d5e6f src/main.rs107│ └── tree 7g8h9i docs/108│ ├── blob aabbcc guide.md109│ └── blob ddeeff api.md110└── parent commit 789xyz111```112
113Changing any file changes every hash up to the root — integrity is guaranteed.114
115= Performance116
117The cost of CAS operations scales with content size, not history depth:118
119$ T_"lookup" = O(1) quad "hash table lookup" $120$ T_"store" = O(|D|) quad "hash computation" $121$ T_"verify" = O(|D|) quad "rehash and compare" $122
123For a repository with $n$ objects and average size $s$:124
125$ "Total space" <= n dot s quad "(with dedup: significantly less)" $126
127= Conclusion128
129Content-addressable storage provides a foundation for systems that need integrity, deduplication, and immutable history. Combined with a hierarchical commit model, it enables version control at any granularity — from individual files to entire organizations.130
131See @intro for the overview, and @hash-table for algorithm benchmarks. v1 of v5
commit 524811b
message create article.typ via macOS
author anton
date Apr 18, 2026
size 3.9 KB