Skip to content

Conversation

@copyleftdev
Copy link
Contributor

Overview

This PR adds a comprehensive Tiger Style algorithm collection to showcase expert-level implementations following TigerBeetle's Tiger Style principles.

What's Included

9 Production-Quality Implementations (102 tests):

  1. time_simulation.zig (7 tests) - Deterministic time simulation framework
  2. merge_sort_tiger.zig (14 tests) - Zero-recursion merge sort
  3. knapsack_tiger.zig (12 tests) - 0/1 Knapsack with heavy assertions
  4. ring_buffer.zig (15 tests) - Bounded FIFO queue with fail-fast
  5. raft_consensus.zig (12 tests) - Raft distributed consensus
  6. two_phase_commit.zig (9 tests) - Two-phase commit protocol
  7. vsr_consensus.zig (11 tests) - Viewstamped Replication (TigerBeetle's actual consensus)
  8. robin_hood_hash.zig (12 tests) - Cache-efficient hash table with Robin Hood hashing
  9. skip_list.zig (10 tests) - Probabilistic ordered map (foundation for LSM trees)

Tiger Style Principles

All implementations follow rigorous Tiger Style discipline:

  • No recursion - Explicit iteration with bounded loops
  • Heavy assertions - Minimum 2 per function, often 5-10+
  • Explicit types - u32/u64/i32 everywhere (never usize)
  • Bounded operations - Every loop has provable upper bounds
  • Fail-fast - Invalid inputs error immediately
  • Zero technical debt - Production-ready from day one

Testing

All 102 tests pass:

zig test tiger_style/time_simulation.zig       #  7 tests ✓
zig test tiger_style/merge_sort_tiger.zig      # 14 tests ✓
zig test tiger_style/knapsack_tiger.zig        # 12 tests ✓
zig test tiger_style/ring_buffer.zig           # 15 tests ✓
zig test tiger_style/raft_consensus.zig        # 12 tests ✓
zig test tiger_style/two_phase_commit.zig      #  9 tests ✓
zig test tiger_style/vsr_consensus.zig         # 11 tests ✓
zig test tiger_style/robin_hood_hash.zig       # 12 tests ✓
zig test tiger_style/skip_list.zig             # 10 tests ✓

Why This Matters

This showcases:

  • Advanced algorithms (consensus, distributed systems, data structures)
  • Production-quality code (inspired by TigerBeetle database)
  • Rigorous engineering discipline
  • Educational value for learning robust system design

Files Changed

  • Added tiger_style/ directory with 9 implementations + README
  • Updated DIRECTORY.md to include Tiger Style section

Total: 4,351 lines of production-quality code

- Time simulation framework (deterministic testing)
- Zero-recursion merge sort
- Heavy-assertion knapsack DP
- Bounded ring buffer (fail-fast FIFO)
- Raft consensus algorithm
- Two-phase commit protocol
- VSR consensus (TigerBeetle's actual consensus)
- Robin Hood hash table (cache-efficient)
- Skip list (probabilistic ordered map)

All implementations follow TigerBeetle's Tiger Style principles:
- No recursion, explicit iteration with bounded loops
- Heavy assertions (2+ per function)
- Explicit u32/u64 types (never usize)
- Fail-fast on invalid inputs
- Zero technical debt

Total: 102 tests, all passing
@kassane
Copy link
Member

kassane commented Nov 10, 2025

Hi @copyleftdev,
Add all new algorithms in runall.zig to run tests.

- Add 9 Tiger Style algorithms to runall.zig test runner
- Add Tiger Style build configurations to build.zig
- Includes: time_simulation, merge_sort_tiger, knapsack_tiger, ring_buffer,
  raft_consensus, two_phase_commit, vsr_consensus, robin_hood_hash, skip_list
@copyleftdev
Copy link
Contributor Author

@kassane updated

@kassane kassane merged commit 7623d42 into TheAlgorithms:main Nov 13, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants