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
10 changes: 2 additions & 8 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@ jobs:
fetch-depth: 0
- uses: mlugg/setup-zig@v1

- name: Testing (Linux & MacOS)
if: (startsWith(matrix.runs-on, 'ubuntu')) || (startsWith(matrix.runs-on, 'macos'))
run: sh runall.sh

- name: Testing (Windows)
if: startsWith(matrix.runs-on, 'windows')
run: ./runall.cmd

- name: Testing
run: zig run runall.zig

lint:
runs-on: ubuntu-latest
Expand Down
73 changes: 47 additions & 26 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,66 @@ Every project is managed by the `build.zig` file.
├── README.md
├── build.zig
├── concurrency
   └── threads
   └── ThreadPool.zig
└── threads
└── ThreadPool.zig
├── dataStructures
│   ├── linkedList.zig
│   └── lruCache.zig
│ ├── doublyLinkedList.zig
│ ├── linkedList.zig
│ ├── lruCache.zig
│ ├── stack.zig
│ └── trie.zig
├── dynamicProgramming
│ ├── coinChange.zig
│ ├── editDistance.zig
│ ├── knapsack.zig
│ └── longestIncreasingSubsequence.zig
├── machine_learning
│ └── k_means_clustering.zig
├── math
   ├── ceil.zig
   ├── chineseRemainderTheorem.zig
   ├── euclidianGreatestCommonDivisor.zig
   ├── factorial.zig
   ├── fibonacciRecursion.zig
   ├── gcd.zig
   └── primes.zig
├── ceil.zig
├── chineseRemainderTheorem.zig
├── euclidianGreatestCommonDivisor.zig
├── factorial.zig
├── fibonacciRecursion.zig
├── gcd.zig
└── primes.zig
├── runall.sh
├── search
   ├── binarySearchTree.zig
   └── redBlackTrees.zig
├── binarySearchTree.zig
└── redBlackTrees.zig
├── sort
│   ├── bubbleSort.zig
│   ├── insertionSort.zig
│   ├── mergeSort.zig
│   ├── quickSort.zig
│   └── radixSort.zig
│ ├── bubbleSort.zig
│ ├── insertionSort.zig
│ ├── mergeSort.zig
│ ├── quickSort.zig
│ └── radixSort.zig
└── web
├── http
│ ├── client.zig
│ └── server.zig
└── tls
└── X25519+Kyber768Draft00.zig
```

To add a new algorithm you only need to categorize and pass the exact location of the new file.

e.g.:
```zig
// build.zig
// new algorithm
if (std.mem.eql(u8, op, "category/algorithm-name"))
build_algorithm(b, mode, target, "algorithm-src.zig", "foldername");
// build.zig
// new algorithm
if (std.mem.eql(u8, op, "category/algorithm-name"))
buildAlgorithm(b, .{
.optimize = optimize,
.target = target,
.name = "algorithm-src.zig",
.category = "category",
});
```
to test add:

```bash
# runall.sh
$ZIG_TEST -Dalgorithm="category/algorithm-name" $StackTrace
```zig
# runall.zig
try runTest(allocator, "category/algorithm-name");
```

**Note:** Do not change or modify the files (`build.zig` & `runall.sh`) without first suggesting it to the maintainers (open/issue proposal).
**Note:** Do not change or modify the files (`build.zig` & `runall.zig`) without first suggesting it to the maintainers (open/issue proposal).
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ pub fn build(b: *std.Build) void {
.category = "web/tls",
});
// Machine Learning
if (std.mem.eql(u8, op, "machine_learning/k_means_clustering.zig"))
if (std.mem.eql(u8, op, "machine_learning/k_means_clustering"))
buildAlgorithm(b, .{
.optimize = optimize,
.target = target,
Expand Down
55 changes: 0 additions & 55 deletions runall.cmd

This file was deleted.

54 changes: 0 additions & 54 deletions runall.sh

This file was deleted.

71 changes: 71 additions & 0 deletions runall.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const std = @import("std");

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();

// Math algorithms
try runTest(allocator, "math/ceil");
try runTest(allocator, "math/crt");
try runTest(allocator, "math/primes");
try runTest(allocator, "math/fibonacci");
try runTest(allocator, "math/factorial");
try runTest(allocator, "math/euclidianGCDivisor");
try runTest(allocator, "math/gcd");

// Data Structures
try runTest(allocator, "ds/trie");
try runTest(allocator, "ds/linkedlist");
try runTest(allocator, "ds/doublylinkedlist");
try runTest(allocator, "ds/lrucache");
try runTest(allocator, "ds/stack");

// Dynamic Programming
try runTest(allocator, "dp/coinChange");
try runTest(allocator, "dp/knapsack");
try runTest(allocator, "dp/longestIncreasingSubsequence");
try runTest(allocator, "dp/editDistance");

// Sort
try runTest(allocator, "sort/quicksort");
try runTest(allocator, "sort/bubblesort");
try runTest(allocator, "sort/radixsort");
try runTest(allocator, "sort/mergesort");
try runTest(allocator, "sort/insertsort");

// Search
try runTest(allocator, "search/bSearchTree");
try runTest(allocator, "search/rb");

// Threads
try runTest(allocator, "threads/threadpool");

// Web
try runTest(allocator, "web/httpClient");
try runTest(allocator, "web/httpServer");
try runTest(allocator, "web/tls1_3");

// Machine Learning
try runTest(allocator, "machine_learning/k_means_clustering");
}

fn runTest(allocator: std.mem.Allocator, comptime algorithm: []const u8) !void {
var child = std.process.Child.init(&[_][]const u8{
"zig",
"build",
"test",
"-Dalgorithm=" ++ algorithm,
} ++ args, allocator);

child.stderr = std.io.getStdErr();
child.stdout = std.io.getStdOut();

_ = try child.spawnAndWait();
}

const args = [_][]const u8{
"--summary",
"all",
"-freference-trace",
};