A Go-based repository for implementing and testing various data structures and algorithms with an organized, serialized structure.
Each algorithm or data structure is contained in its own directory as a package within the main github.com/celj/dsa
module:
XXXX-algorithm-name/
├── algorithm_name.go # Implementation
├── algorithm_name_test.go # Tests and benchmarks
└── README.md # Algorithm-specific documentation
Example:
0001-linear-search/
├── linear_search.go # Linear search implementation
├── linear_search_test.go # Comprehensive tests and benchmarks
└── README.md # Algorithm documentation
make new n=binary-search
This will create a new directory 0002-binary-search
with all the necessary files. The directory number is automatically incremented based on existing directories.
Test all algorithms:
make test
Test specific algorithms by name:
make test n=linear-search,binary-search
Test specific algorithms by index:
make test n=1,2,15,20
Mix names and indices:
make test n=linear-search,2,bubble-sort,12
Run all algorithms:
make run
Run specific algorithms by name:
make run n=linear-search,binary-search
Run specific algorithms by index:
make run n=1,2,15,20
Run benchmarks for all algorithms:
make bench
Run benchmarks for specific algorithms by name:
make bench n=linear-search,binary-search
Run benchmarks for specific algorithms by index:
make bench n=1,2,15,20
View available commands:
make help
The n
parameter supports multiple selection formats:
- By algorithm names:
n=linear-search,binary-search
- By directory indices:
n=1,2,15,20
(where 1 = 0001-, 2 = 0002-, etc.) - Mixed format:
n=linear-search,2,bubble-sort,15
- Single selection:
n=linear-search
orn=1
- Full directory name:
n=0001-linear-search
- Automatic Serialization: Directories are automatically numbered (0001, 0002, etc.)
- Complete Package Structure: Each algorithm gets its own Go package within the main module
- Flexible Selection: Use algorithm names, indices, or mix both for multi-selection
- Comma-separated Multi-selection: Run multiple algorithms in a single command
- Comprehensive Testing: Includes unit tests, benchmarks, go vet, and formatting checks
- Template Generation: Automatically generates boilerplate code with TODO markers
- Colorized Output: Test runner provides clear, colorized feedback
- Dynamic Execution: Run command creates temporary main.go files with proper imports
-
Create a new algorithm:
make new n=binary-search
-
Navigate to the directory and implement:
cd 0002-binary-search # Edit binary_search.go to implement your algorithm # Update tests in binary_search_test.go
-
Test your implementation:
make test n=binary-search
-
Run your algorithm:
make run n=binary-search
-
Run multiple algorithms:
make run n=1,2,5 make test n=linear-search,binary-search,bubble-sort make bench n=1,3,quick-sort,15
A complete implementation of linear search with:
- Multiple data type support (int, string, float64, generic)
- Comprehensive test suite with edge cases
- Performance benchmarks for different array sizes
- Detailed complexity analysis and documentation
Usage:
make run n=linear-search
# or
make run n=1
# Output: map[array:[64 34 25 12 22 11 90] found:true index:4 target:22]
make test n=linear-search
# or
make test n=1
# Runs comprehensive tests and benchmarks
When you create a new algorithm, you'll get:
- algorithm_name.go: Your implementation goes here
- algorithm_name_test.go: Unit tests and benchmarks
- README.md: Documentation template
The test runner performs:
- Unit tests (
go test -v
) - Benchmarks (
go test -bench=. -benchmem
) - Code analysis (
go vet
) - Format checking (
gofmt
)
- Each directory is a Go package within the
github.com/celj/dsa
module - The
make run
command creates a temporary main.go file with proper import aliasing - Import paths use the directory name:
github.com/celj/dsa/XXXX-algorithm-name
- Package names use underscores:
algorithm_name
- Selection supports both full directory names, algorithm names, and numeric indices
- Temporary files are automatically cleaned up after execution
The repository uses three main scripts:
scripts/new.sh
- Creates new algorithm directoriesscripts/test.sh
- Runs tests and benchmarks with multi-selection supportscripts/run.sh
- Executes algorithms with multi-selection supportscripts/bench.sh
- Runs benchmarks with multi-selection support
- Create a new algorithm with
make new n=your-algorithm
- Implement the algorithm in the generated files
- Add comprehensive tests and benchmarks
- Update the algorithm's README.md with complexity analysis
- Run
make test
to ensure everything passes
Based on the linear-search implementation:
Code Structure:
- Provide multiple functions for different data types
- Include a generic implementation when possible
- Use clear, descriptive function names
- Return consistent result formats
Testing:
- Test all edge cases (empty arrays, single elements, not found)
- Include benchmarks for different input sizes
- Use table-driven tests for comprehensive coverage
- Test both success and failure scenarios
Documentation:
- Include algorithm description and complexity analysis
- Provide usage examples with code snippets
- Document when to use vs. alternatives
- Include performance characteristics