Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
- uses: actions/checkout@v4

- name: Setup Zig
uses: mlugg/setup-zig@v1
uses: mlugg/setup-zig@v2
with:
version: 0.14.0
version: 0.15.2

- name: Run tests
run: zig build test
Expand Down
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.name = .zig_utils,
.version = "0.5.0",
.fingerprint = 0x6dc482caf73c4a75,
.minimum_zig_version = "0.14.0",
.minimum_zig_version = "0.15.2",

.dependencies = .{
.zspec = .{
.url = "https://github.com/apotema/zspec/archive/refs/heads/main.tar.gz",
.hash = "zspec-0.3.0-jaKLbbqZAgAB-MBfy6M3HKB3jSTQ-TsNW9OxpLhLlav5",
.hash = "zspec-0.6.0-jaKLbU5DAwAYa0jR0cnFGuIbSrxD6ojh-oyXj9ooyb3V",
},
},

Expand Down
81 changes: 77 additions & 4 deletions claude.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ Standalone math utilities library for Zig. Part of the labelle-toolkit.

```
src/
root.zig - Main module exports
vector.zig - Position and PositionI types
quad_tree.zig - QuadTree spatial partitioning (generic, Position-based)
sweep_and_prune.zig - Sweep and Prune collision detection
root.zig - Main module exports
vector.zig - Position and PositionI types
quad_tree.zig - QuadTree spatial partitioning
sweep_and_prune.zig - Sweep and Prune collision detection
sparse_set.zig - SparseSet O(1) key-value mapping
z_index_buckets.zig - ZIndexBuckets sorted storage by u8 key
zon_coercion.zig - Comptime ZON to struct conversion
hook_dispatcher.zig - Zero-overhead comptime event dispatcher
floyd_warshall.zig - Floyd-Warshall all-pairs shortest path
floyd_warshall_optimized.zig - SIMD/parallel Floyd-Warshall
a_star.zig - A* single-source pathfinding
heuristics.zig - Distance heuristics for A*
tests/
root.zig - Test entry point
vector_test.zig - Position/PositionI tests
Expand All @@ -23,6 +31,12 @@ tests/
- `PositionI` (i32) - Integer position for pixel-perfect work
- `QuadTree(T)` - Generic spatial index with Position-based queries
- `SweepAndPrune(T)` - Generic broad-phase collision detection
- `SparseSet(T)` - O(1) key-value mapping with cache-friendly iteration
- `ZIndexBuckets(T)` - Bucket-sorted storage by u8 key (256 buckets)
- `HookDispatcher` - Zero-overhead comptime event dispatcher
- `FloydWarshall` - All-pairs shortest path O(V鲁)
- `FloydWarshallOptimized` - SIMD/parallel Floyd-Warshall (5-16x faster)
- `AStar` - A* single-source pathfinding with heuristics
- `Rectangle` - AABB for bounds and collision
- `EntityPoint(T)` - Point with generic ID for QuadTree
- `AABB` - Axis-aligned bounding box for SweepAndPrune
Expand Down Expand Up @@ -59,6 +73,65 @@ zig build test
- Generic ID type support
- Position-based AABB queries

### SparseSet
- O(1) insert, remove, lookup (worst-case, not amortized)
- Cache-friendly dense array iteration
- Generic value type support
- Fixed memory based on max key range
- Ideal for entity -> component mappings

**Benchmark results (vs HashMap):**
| Operation | SparseSet | HashMap |
|-----------|-----------|---------|
| contains | 0.76 ns | 4.61 ns |

**Trade-off:** ~40KB memory for 10k max keys vs variable for HashMap

### ZIndexBuckets
- 256 buckets (one per u8 z-index level)
- O(1) insert, O(bucket_size) remove
- O(256 + n) ordered iteration
- Generic over item type T
- Optional custom equality via `eql` method

### ZON Coercion
- Comptime conversion of anonymous structs to typed structs
- Handles nested structs, optionals, slices, arrays
- Tagged union coercion from enum literals or structs
- Struct merging with override semantics
- Functions: `coerceValue`, `buildStruct`, `tupleToSlice`, `mergeStructs`

### HookDispatcher
- Zero-overhead comptime event dispatch
- Handlers resolved entirely at compile time
- No runtime overhead for missing handlers
- `MergeHooks` for composing multiple handler structs
- `EmptyDispatcher` for default no-op dispatching

### Graph Algorithms

**Floyd-Warshall** (all-pairs shortest path):
- O(V鲁) time, O(V虏) space
- Best for dense graphs, frequent all-pairs queries
- Entity ID mapping support
- Optimized variant with SIMD (5-8x faster) and parallel (up to 16x)

**A\*** (single-source shortest path):
- Heuristic-guided best-first search
- Built-in heuristics: Euclidean, Manhattan, Chebyshev, Octile, Zero
- Custom heuristic function support
- Entity ID mapping for ECS integration
- Best for sparse graphs, real-time queries

**Heuristics**:
| Movement Type | Recommended |
|---------------|-------------|
| Any-angle | Euclidean |
| 4-directional | Manhattan |
| 8-dir equal cost | Chebyshev |
| 8-dir realistic | Octile |
| Unknown | Zero (Dijkstra) |

## Related

- labelle-pathfinding - Uses QuadTree for spatial queries
Expand Down
Loading