Skip to content

Commit 2cb8155

Browse files
committed
add Claude Code instruction
1 parent d94b0a5 commit 2cb8155

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

.claude/settings.local.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"enableAllProjectMcpServers": false
3+
}

CLAUDE.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
ZLinq is a zero-allocation LINQ library for .NET that provides high-performance alternatives to System.Linq through struct-based value types. The library offers LINQ to Span, LINQ to SIMD, and LINQ to Tree functionality across all .NET platforms including Unity and Godot.
8+
9+
## Key Architecture
10+
11+
### Core Design
12+
- **ValueEnumerable<TEnumerator, T>**: Main struct that wraps enumerators to enable method chaining without allocations
13+
- **IValueEnumerator<T>**: Interface defining `TryGetNext(out T current)` pattern instead of MoveNext/Current
14+
- **ref struct support**: In .NET 9+, ValueEnumerable is a ref struct enabling Span<T> integration
15+
- **Optimization methods**: `TryGetNonEnumeratedCount`, `TryGetSpan`, `TryCopyTo` for performance optimizations
16+
17+
### Project Structure
18+
- `src/ZLinq/`: Core library with all LINQ operators in `Linq/` folder and SIMD implementations in `Simd/`
19+
- `src/ZLinq.DropInGenerator/`: Source generator for automatic ZLinq method replacement
20+
- `src/ZLinq.FileSystem/`, `ZLinq.Json/`, `ZLinq.Godot/`: Tree traversal extensions
21+
- `src/ZLinq.Unity/`: Unity package with GameObject/Transform traversal
22+
- `src/FileGen/`: Code generation tools for creating operators
23+
- `sandbox/`: Test applications and benchmarks
24+
- `tests/`: Comprehensive test suite including System.Linq compatibility tests
25+
26+
## Development Commands
27+
28+
### Building
29+
```bash
30+
dotnet build
31+
```
32+
33+
### Testing
34+
```bash
35+
# Run ZLinq-specific tests
36+
dotnet test tests/ZLinq.Tests/
37+
38+
# Run System.Linq compatibility tests (extensive)
39+
dotnet test tests/System.Linq.Tests/
40+
41+
# Run all tests
42+
dotnet test
43+
```
44+
45+
### Benchmarking
46+
```bash
47+
cd sandbox/Benchmark
48+
dotnet run -c Release
49+
```
50+
51+
## Testing Guidelines
52+
53+
- Use xUnit v3 with Shouldly for assertions
54+
- Global usings include `Xunit`, `Shouldly`, `ZLinq`
55+
- Class field naming: do NOT use `_` prefix
56+
- Tests target multiple frameworks: net6.0, net8.0, net9.0, net48 (Windows), net10.0 (VS Preview)
57+
- System.Linq.Tests project validates 99% compatibility with System.Linq using original Microsoft tests
58+
59+
## Code Patterns
60+
61+
### Custom Operators
62+
- Implement `IValueEnumerator<T>` as struct (ref struct in .NET 9+)
63+
- Use `TryGetNext(out T current)` instead of MoveNext/Current pattern
64+
- Always dispose source enumerators in Dispose()
65+
- Optimization methods can return false if complex to implement
66+
67+
### SIMD Support
68+
- Available in .NET 8+ when `TryGetSpan` returns true
69+
- Covers Sum, Average, Min, Max, Contains, SequenceEqual for numeric types
70+
- Use `ZLinq.Simd` namespace for explicit SIMD operations
71+
72+
### Drop-in Replacement
73+
- Use `ZLinqDropInAttribute` assembly attribute to auto-replace LINQ methods
74+
- Configure with `DropInGenerateTypes` flags for target types
75+
- Support custom types with `ZLinqDropInExtensionAttribute`
76+
77+
## Important Constraints
78+
79+
- ValueEnumerable cannot be converted to IEnumerable<T> in .NET 9+ (ref struct limitation)
80+
- No yield return support in custom operators - everything must be manually implemented
81+
- Reference types in enumerator constructors share state across copies - initialize in TryGetNext instead
82+
- Method chains create different types - cannot reassign to same variable
83+
84+
## Unity Integration
85+
86+
- Install via NuGetForUnity + git URL for Unity package
87+
- Provides GameObject/Transform tree traversal with Ancestors/Children/Descendants
88+
- Supports NativeArray, NativeSlice through AsValueEnumerable()
89+
- Minimum Unity version: 2022.3.12f1 for DropInGenerator support
90+
91+
## Performance Focus
92+
93+
ZLinq prioritizes zero-allocation performance with comprehensive SIMD support and optimization hooks. The library proves compatibility by passing 9000+ System.Linq tests while delivering superior performance in most scenarios.

0 commit comments

Comments
 (0)