ocaml: phase 5.1 huffman.ml baseline (Huffman tree WPL = 224)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
Classic CLRS Huffman code example. ADT:
type tree = Leaf of int * char | Node of int * tree * tree
Build by repeatedly merging two lightest trees (sorted-list pq):
let rec build_tree lst = match lst with
| [t] -> t
| a :: b :: rest ->
let merged = Node (weight a + weight b, a, b) in
build_tree (insert merged rest)
weighted path length (= total Huffman bits):
leaves {(5,a) (9,b) (12,c) (13,d) (16,e) (45,f)} -> 224
Tests sum-typed ADT with mixed arities, `function` keyword
pattern matching, recursive sorted insert, depth-counting recursion.
150 baseline programs total.
This commit is contained in:
@@ -407,6 +407,15 @@ _Newest first._
|
||||
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
|
||||
'a tree`) with insert + in-order traversal. Tests parametric ADT,
|
||||
recursive match, List.append, List.fold_left.
|
||||
- 2026-05-10 Phase 5.1 — huffman.ml baseline (Huffman tree weighted
|
||||
path length on letters {(5,a) (9,b) (12,c) (13,d) (16,e) (45,f)}
|
||||
= 224). Builds optimal prefix code by repeatedly merging the two
|
||||
lightest trees: insert merged node back into a sorted-by-weight
|
||||
list. Verifies the standard Huffman result of 224 bits for this
|
||||
classic CLRS example. Tests sum-typed ADT with two arities
|
||||
(Leaf of int * char | Node of int * tree * tree), `function`
|
||||
keyword pattern matching, recursive sorted insert, depth-counting
|
||||
recursion. 150 baseline programs total.
|
||||
- 2026-05-10 Phase 5.1 — parser: accept `if/match/let/fun/...` as
|
||||
the rhs of `<-` and `:=`. parse-binop-rhs now special-cases prec-1
|
||||
ops (`<-`, `:=`) to call parse-expr-no-seq for their right operand
|
||||
|
||||
Reference in New Issue
Block a user