ocaml: phase 5.1 stable_unique.ml baseline (Hashtbl dedupe preserving order, 8+38 = 46)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 30s

Walk input with Hashtbl.mem + Hashtbl.add seen x () (unit-payload
turns the table into a set); on first occurrence cons to the result
list; reverse at the end:

  let stable_unique xs =
    let seen = Hashtbl.create 8 in
    let result = ref [] in
    List.iter (fun x ->
      if not (Hashtbl.mem seen x) then begin
        Hashtbl.add seen x ();
        result := x :: !result
      end
    ) xs;
    List.rev !result

For [3;1;4;1;5;9;2;6;5;3;5;8;9]:
  result = [3;1;4;5;9;2;6;8]   (input order, dupes dropped)
  length = 8, sum = 38         total = 46

Tests Hashtbl as a set abstraction (unit-payload), the rev-build
idiom, and 'not (Hashtbl.mem seen x)' membership negation.

82 baseline programs total.
This commit is contained in:
2026-05-09 16:56:46 +00:00
parent 554ef48c63
commit 1bde4e834f
3 changed files with 24 additions and 0 deletions

View File

@@ -407,6 +407,14 @@ _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-09 Phase 5.1 — stable_unique.ml baseline (Hashtbl-tracked
dedupe preserving order, length+sum = 8+38 = 46). Walks input
with `Hashtbl.mem` + `Hashtbl.add seen x ()` (unit-payload to use
the table as a set); on first occurrence cons to the result list,
reverse at the end. For [3;1;4;1;5;9;2;6;5;3;5;8;9] yields
[3;1;4;5;9;2;6;8] — 8 elements summing to 38. Tests Hashtbl as
a set abstraction (ignoring values), and the rev-build idiom. 82
baseline programs total.
- 2026-05-09 Phase 5.1 — run_decode.ml baseline (RLE decode, sum of
expansion = 21). Inverse of run_length.ml: takes a list of
`(value, count)` tuples, expands each pair via inner `rep` helper,