Skip to content

Commit 5b9cf67

Browse files
authored
zig update - v0.14.0 (#24)
1 parent ae9f05c commit 5b9cf67

12 files changed

+83
-70
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
### How to build
3636

3737
**Require:**
38-
- [Zig v0.13 or higher](https://ziglang.org/download), self-hosting (stage3) compiler.
38+
- [Zig v0.14 or higher](https://ziglang.org/download), self-hosting (stage3) compiler.
3939

4040
### Test all
4141

build.zig

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,35 @@ pub fn build(b: *std.Build) void {
88

99
// Sort algorithms
1010
if (std.mem.eql(u8, op, "sort/quicksort"))
11-
build_algorithm(b, .{
11+
buildAlgorithm(b, .{
1212
.optimize = optimize,
1313
.target = target,
1414
.name = "quickSort.zig",
1515
.category = "sort",
1616
});
1717
if (std.mem.eql(u8, op, "sort/bubblesort"))
18-
build_algorithm(b, .{
18+
buildAlgorithm(b, .{
1919
.optimize = optimize,
2020
.target = target,
2121
.name = "bubbleSort.zig",
2222
.category = "sort",
2323
});
2424
if (std.mem.eql(u8, op, "sort/radixsort"))
25-
build_algorithm(b, .{
25+
buildAlgorithm(b, .{
2626
.optimize = optimize,
2727
.target = target,
2828
.name = "radixSort.zig",
2929
.category = "sort",
3030
});
3131
if (std.mem.eql(u8, op, "sort/mergesort"))
32-
build_algorithm(b, .{
32+
buildAlgorithm(b, .{
3333
.optimize = optimize,
3434
.target = target,
3535
.name = "mergeSort.zig",
3636
.category = "sort",
3737
});
3838
if (std.mem.eql(u8, op, "sort/insertsort"))
39-
build_algorithm(b, .{
39+
buildAlgorithm(b, .{
4040
.optimize = optimize,
4141
.target = target,
4242
.name = "insertionSort.zig",
@@ -45,14 +45,14 @@ pub fn build(b: *std.Build) void {
4545

4646
// Search algorithms
4747
if (std.mem.eql(u8, op, "search/bSearchTree"))
48-
build_algorithm(b, .{
48+
buildAlgorithm(b, .{
4949
.optimize = optimize,
5050
.target = target,
5151
.name = "binarySearchTree.zig",
5252
.category = "search",
5353
});
5454
if (std.mem.eql(u8, op, "search/rb"))
55-
build_algorithm(b, .{
55+
buildAlgorithm(b, .{
5656
.optimize = optimize,
5757
.target = target,
5858
.name = "redBlackTrees.zig",
@@ -61,28 +61,28 @@ pub fn build(b: *std.Build) void {
6161

6262
// Data Structures algorithms
6363
if (std.mem.eql(u8, op, "ds/linkedlist"))
64-
build_algorithm(b, .{
64+
buildAlgorithm(b, .{
6565
.optimize = optimize,
6666
.target = target,
6767
.name = "linkedList.zig",
6868
.category = "dataStructures",
6969
});
7070
if (std.mem.eql(u8, op, "ds/doublylinkedlist"))
71-
build_algorithm(b, .{
71+
buildAlgorithm(b, .{
7272
.optimize = optimize,
7373
.target = target,
7474
.name = "doublyLinkedList.zig",
7575
.category = "dataStructures",
7676
});
7777
if (std.mem.eql(u8, op, "ds/lrucache"))
78-
build_algorithm(b, .{
78+
buildAlgorithm(b, .{
7979
.optimize = optimize,
8080
.target = target,
8181
.name = "lruCache.zig",
8282
.category = "dataStructures",
8383
});
8484
if (std.mem.eql(u8, op, "ds/stack"))
85-
build_algorithm(b, .{
85+
buildAlgorithm(b, .{
8686
.optimize = optimize,
8787
.target = target,
8888
.name = "stack.zig",
@@ -91,79 +91,79 @@ pub fn build(b: *std.Build) void {
9191

9292
// Dynamic Programming algorithms
9393
if (std.mem.eql(u8, op, "dp/coinChange"))
94-
build_algorithm(b, .{
94+
buildAlgorithm(b, .{
9595
.optimize = optimize,
9696
.target = target,
9797
.name = "coinChange.zig",
98-
.category = "dynamicProgramming"
98+
.category = "dynamicProgramming",
9999
});
100100
if (std.mem.eql(u8, op, "dp/knapsack"))
101-
build_algorithm(b, .{
101+
buildAlgorithm(b, .{
102102
.optimize = optimize,
103103
.target = target,
104104
.name = "knapsack.zig",
105-
.category = "dynamicProgramming"
105+
.category = "dynamicProgramming",
106106
});
107107
if (std.mem.eql(u8, op, "dp/longestIncreasingSubsequence"))
108-
build_algorithm(b, .{
108+
buildAlgorithm(b, .{
109109
.optimize = optimize,
110110
.target = target,
111111
.name = "longestIncreasingSubsequence.zig",
112-
.category = "dynamicProgramming"
112+
.category = "dynamicProgramming",
113113
});
114114
if (std.mem.eql(u8, op, "dp/editDistance"))
115-
build_algorithm(b, .{
115+
buildAlgorithm(b, .{
116116
.optimize = optimize,
117117
.target = target,
118118
.name = "editDistance.zig",
119-
.category = "dynamicProgramming"
119+
.category = "dynamicProgramming",
120120
});
121121

122122
// Math algorithms
123123
if (std.mem.eql(u8, op, "math/ceil"))
124-
build_algorithm(b, .{
124+
buildAlgorithm(b, .{
125125
.optimize = optimize,
126126
.target = target,
127127
.name = "ceil.zig",
128128
.category = "math",
129129
});
130130
if (std.mem.eql(u8, op, "math/crt"))
131-
build_algorithm(b, .{
131+
buildAlgorithm(b, .{
132132
.optimize = optimize,
133133
.target = target,
134134
.name = "chineseRemainderTheorem.zig",
135135
.category = "math",
136136
});
137137
if (std.mem.eql(u8, op, "math/fibonacci"))
138-
build_algorithm(b, .{
138+
buildAlgorithm(b, .{
139139
.optimize = optimize,
140140
.target = target,
141141
.name = "fibonacciRecursion.zig",
142142
.category = "math",
143143
});
144144
if (std.mem.eql(u8, op, "math/primes"))
145-
build_algorithm(b, .{
145+
buildAlgorithm(b, .{
146146
.optimize = optimize,
147147
.target = target,
148148
.name = "primes.zig",
149149
.category = "math",
150150
});
151151
if (std.mem.eql(u8, op, "math/euclidianGCDivisor"))
152-
build_algorithm(b, .{
152+
buildAlgorithm(b, .{
153153
.optimize = optimize,
154154
.target = target,
155155
.name = "euclidianGreatestCommonDivisor.zig",
156156
.category = "math",
157157
});
158158
if (std.mem.eql(u8, op, "math/gcd"))
159-
build_algorithm(b, .{
159+
buildAlgorithm(b, .{
160160
.optimize = optimize,
161161
.target = target,
162162
.name = "gcd.zig",
163163
.category = "math",
164164
});
165165
if (std.mem.eql(u8, op, "math/factorial"))
166-
build_algorithm(b, .{
166+
buildAlgorithm(b, .{
167167
.optimize = optimize,
168168
.target = target,
169169
.name = "factorial.zig",
@@ -172,7 +172,7 @@ pub fn build(b: *std.Build) void {
172172

173173
// Concurrent
174174
if (std.mem.eql(u8, op, "threads/threadpool"))
175-
build_algorithm(b, .{
175+
buildAlgorithm(b, .{
176176
.optimize = optimize,
177177
.target = target,
178178
.name = "ThreadPool.zig",
@@ -181,29 +181,29 @@ pub fn build(b: *std.Build) void {
181181

182182
// Web
183183
if (std.mem.eql(u8, op, "web/httpClient"))
184-
build_algorithm(b, .{
184+
buildAlgorithm(b, .{
185185
.optimize = optimize,
186186
.target = target,
187187
.name = "client.zig",
188188
.category = "web/http",
189189
});
190190
if (std.mem.eql(u8, op, "web/httpServer"))
191-
build_algorithm(b, .{
191+
buildAlgorithm(b, .{
192192
.optimize = optimize,
193193
.target = target,
194194
.name = "server.zig",
195195
.category = "web/http",
196196
});
197197
if (std.mem.eql(u8, op, "web/tls1_3"))
198-
build_algorithm(b, .{
198+
buildAlgorithm(b, .{
199199
.optimize = optimize,
200200
.target = target,
201201
.name = "X25519+Kyber768Draft00.zig",
202202
.category = "web/tls",
203203
});
204204
}
205205

206-
fn build_algorithm(b: *std.Build, info: BInfo) void {
206+
fn buildAlgorithm(b: *std.Build, info: BInfo) void {
207207
const src = std.mem.concat(b.allocator, u8, &.{
208208
info.category,
209209
"/",
@@ -217,7 +217,7 @@ fn build_algorithm(b: *std.Build, info: BInfo) void {
217217
.target = info.target,
218218
.optimize = info.optimize,
219219
.root_source_file = b.path(src),
220-
.test_runner = runner,
220+
.test_runner = .{ .path = runner, .mode = .simple },
221221
});
222222

223223
const descr = b.fmt("Test the {s} algorithm", .{info.name});

build.zig.zon

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,29 @@
66
//
77
// It is redundant to include "zig" in this name because it is already
88
// within the Zig package namespace.
9-
.name = "Algorithms-Zig",
9+
.name = .Algorithms,
1010

1111
// This is a [Semantic Version](https://semver.org/).
1212
// In a future version of Zig it will be used for package deduplication.
1313
.version = "0.3.0",
1414

15-
// This field is optional.
16-
// This is currently advisory only; Zig does not yet do anything
17-
// with this value.
18-
.minimum_zig_version = "0.13.0",
15+
// Together with name, this represents a globally unique package
16+
// identifier. This field is generated by the Zig toolchain when the
17+
// package is first created, and then *never changes*. This allows
18+
// unambiguous detection of one package being an updated version of
19+
// another.
20+
//
21+
// When forking a Zig project, this id should be regenerated (delete the
22+
// field and run `zig build`) if the upstream project is still maintained.
23+
// Otherwise, the fork is *hostile*, attempting to take control over the
24+
// original project's identity. Thus it is recommended to leave the comment
25+
// on the following line intact, so that it shows up in code reviews that
26+
// modify the field.
27+
.fingerprint = 0xe67bc23f91330780, // Changing this has security and trust implications.
28+
29+
// Tracks the earliest Zig version that the package considers to be a
30+
// supported use case.
31+
.minimum_zig_version = "0.14.0",
1932

2033
// This field is optional.
2134
// Each dependency must either provide a `url` and `hash`, or a `path`.
@@ -25,8 +38,8 @@
2538
.dependencies = .{
2639
// Custom test-runner: see tests output
2740
.runner = .{
28-
.url = "git+https://gist.github.com/karlseguin/c6bea5b35e4e8d26af6f81c22cb5d76b/#f303e77231e14b405e4e800072e7deacac4a4881",
29-
.hash = "12208ab39744c8c0909d53b8c9889aff0690930d20e98e4f650f9690310e9a860b14",
41+
.url = "git+https://gist.github.com/karlseguin/c6bea5b35e4e8d26af6f81c22cb5d76b/#1f317ebc9cd09bc50fd5591d09c34255e15d1d85",
42+
.hash = "N-V-__8AANwlAADW-4Yu_sYSZkL_6wcz13gOf9pkOLCjct-F",
3043
},
3144
},
3245
.paths = .{

concurrency/threads/ThreadPool.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ pub const ThreadPool = struct {
421421
// Acquire barrier to ensure operations before the shutdown() are seen after the wait().
422422
// Shutdown is rare so it's better to have an Acquire barrier here instead of on CAS failure + load which are common.
423423
if (state == SHUTDOWN) {
424-
@fence(.acquire);
424+
_ = self.state.load(.acquire);
425425
return;
426426
}
427427

dataStructures/doublyLinkedList.zig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn DoublyLinkedList(comptime T: type) type {
3030
// Runs in O(1)
3131
// Arguments:
3232
// key: T - the key to be inserted to the list
33-
pub fn push_back(self: *Self, key: T) !void {
33+
pub fn pushBack(self: *Self, key: T) !void {
3434
const nn = try self.allocator.create(node);
3535
nn.* = node{ .info = key, .next = null, .prev = self.tail };
3636

@@ -49,7 +49,7 @@ pub fn DoublyLinkedList(comptime T: type) type {
4949
// Runs in O(1)
5050
// Arguments:
5151
// key: T - the key to be inserted to the list
52-
pub fn push_front(self: *Self, key: T) !void {
52+
pub fn pushFront(self: *Self, key: T) !void {
5353
const nn = try self.allocator.create(node);
5454
nn.* = node{ .info = key, .next = self.root, .prev = null };
5555

@@ -66,7 +66,7 @@ pub fn DoublyLinkedList(comptime T: type) type {
6666

6767
// Function that removes the front of the list
6868
// Runs in O(1)
69-
pub fn pop_front(self: *Self) void {
69+
pub fn popFront(self: *Self) void {
7070
if (self.root == null) {
7171
return;
7272
}
@@ -80,7 +80,7 @@ pub fn DoublyLinkedList(comptime T: type) type {
8080

8181
// Function that removes the back of the list
8282
// Runs in O(1)
83-
pub fn pop_back(self: *Self) void {
83+
pub fn popBack(self: *Self) void {
8484
if (self.root == null) {
8585
return;
8686
}
@@ -193,9 +193,9 @@ test "Testing Doubly Linked List" {
193193
var list = DoublyLinkedList(i32){ .allocator = &allocator };
194194
defer list.destroy();
195195

196-
try list.push_front(10);
197-
try list.push_front(20);
198-
try list.push_front(30);
196+
try list.pushFront(10);
197+
try list.pushFront(20);
198+
try list.pushFront(30);
199199

200200
try testing.expect(list.search(10) == true);
201201
try testing.expect(list.search(30) == true);
@@ -207,7 +207,7 @@ test "Testing Doubly Linked List" {
207207
defer list2.destroy();
208208

209209
inline for (0..4) |el| {
210-
try list2.push_back(el);
210+
try list2.pushBack(el);
211211
}
212212

213213
inline for (0..4) |el| {
@@ -216,10 +216,10 @@ test "Testing Doubly Linked List" {
216216

217217
try testing.expect(list2.size == 4);
218218

219-
list2.pop_front();
219+
list2.popFront();
220220
try testing.expect(list2.search(0) == false);
221221

222-
list2.pop_back();
222+
list2.popBack();
223223

224224
try testing.expect(list2.size == 2);
225225
try testing.expect(list2.search(3) == false);

dynamicProgramming/coinChange.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const testing = std.testing;
66
// Arguments:
77
// arr: the array that contains the coins
88
// N: the total amount of money that you have
9-
pub fn min_cost(arr: []const u32, comptime N: i32) i32 {
9+
pub fn minCost(arr: []const u32, comptime N: i32) i32 {
1010
const max_of: i32 = N + 1;
1111

1212
var dp: [N + 1]i32 = undefined;
@@ -28,11 +28,11 @@ pub fn min_cost(arr: []const u32, comptime N: i32) i32 {
2828

2929
test "Testing min_cost algorithm" {
3030
const v = [3]u32{ 1, 2, 5 };
31-
try testing.expect(min_cost(&v, 11) == 3);
31+
try testing.expect(minCost(&v, 11) == 3);
3232

3333
const v2 = [1]u32{2};
34-
try testing.expect(min_cost(&v2, 3) == -1);
34+
try testing.expect(minCost(&v2, 3) == -1);
3535

3636
const v3 = [1]u32{1};
37-
try testing.expect(min_cost(&v3, 0) == 0);
37+
try testing.expect(minCost(&v3, 0) == 0);
3838
}

0 commit comments

Comments
 (0)