Skip to content

Commit 45ea3b1

Browse files
authored
Updates for building/testing on Zig 0.16.0 (#29)
* fixes for Zig 0.16.0 * Regen docs * Update README.md with correct doc gen command * remove src/main.zig from build.zig.zon
1 parent 7556316 commit 45ea3b1

10 files changed

Lines changed: 79 additions & 29 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ zig build test
220220

221221
```sh
222222
# With Zig installed:
223-
zigup build docs && cp -a zig-out/docs/. docs/
223+
zig build docs && cp -a zig-out/docs/. docs/
224224

225225
# Alternatively, using Zigup:
226226
zigup run <zig-version> build docs && cp -a zig-out/docs/. docs/

build.zig.zon

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
.{
22
.name = .ziglangSet,
3-
.version = "0.0.1",
3+
.version = "0.1.0",
44
.fingerprint = 0x65aa5acd2ef4855,
5-
.minimum_zig_version = "0.15.1",
5+
.minimum_zig_version = "0.16.0",
66

77
.dependencies = .{},
88

99
.paths = .{
1010
"LICENSE",
1111
"build.zig",
1212
"build.zig.zon",
13-
"src/array_hash_set/managed.zig",
14-
"src/array_hash_set/unmanaged.zig",
15-
"src/hash_set/managed.zig",
16-
"src/hash_set/unmanaged.zig",
13+
"src/hash_set.zig",
14+
"src/array_hash_set.zig",
1715
"src/root.zig",
1816
},
1917
}

docs/index.html

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@
4040
code a {
4141
color: #000000;
4242
}
43+
.source-code {
44+
display: grid;
45+
grid-template-columns: auto 1fr;
46+
align-items: start;
47+
}
48+
.source-line-numbers pre {
49+
text-align: right;
50+
color: #666;
51+
}
4352
#listFields > div, #listParams > div {
4453
margin-bottom: 1em;
4554
}
@@ -429,7 +438,14 @@ <h2>Example Usage</h2>
429438
</div>
430439
<div id="sectSource" class="hidden">
431440
<h2>Source Code</h2>
432-
<pre><code id="sourceText"></code></pre>
441+
<div class="source-code">
442+
<div class="source-line-numbers">
443+
<pre><code id="sourceLineNumbers"></code></pre>
444+
</div>
445+
<div class="source-text">
446+
<pre><code id="sourceText"></code></pre>
447+
</div>
448+
</div>
433449
</div>
434450
</section>
435451
<div id="helpDialog" class="hidden">

docs/main.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
const domSectTypes = document.getElementById("sectTypes");
5151
const domSectValues = document.getElementById("sectValues");
5252
const domSourceText = document.getElementById("sourceText");
53+
const domSourceLineNumbers = document.getElementById("sourceLineNumbers");
5354
const domStatus = document.getElementById("status");
5455
const domTableFnErrors = document.getElementById("tableFnErrors");
5556
const domTldDocs = document.getElementById("tldDocs");
@@ -129,6 +130,11 @@
129130
domSearch.addEventListener('input', onSearchChange, false);
130131
window.addEventListener('keydown', onWindowKeyDown, false);
131132
onHashChange(null);
133+
if (domSearch.value) {
134+
// user started typing a search query while the page was loading
135+
curSearchIndex = -1;
136+
startAsyncSearch();
137+
}
132138
});
133139
});
134140

@@ -233,6 +239,7 @@
233239
href: location.hash,
234240
}]);
235241

242+
domSourceLineNumbers.innerHTML = declLineNumbersHtml(decl_index);
236243
domSourceText.innerHTML = declSourceHtml(decl_index);
237244

238245
domSectSource.classList.remove("hidden");
@@ -384,6 +391,7 @@
384391
if (members.length !== 0 || fields.length !== 0) {
385392
renderNamespace(decl_index, members, fields);
386393
} else {
394+
domSourceLineNumbers.innerHTML = declLineNumbersHtml(decl_index);
387395
domSourceText.innerHTML = declSourceHtml(decl_index);
388396
domSectSource.classList.remove("hidden");
389397
}
@@ -414,6 +422,7 @@
414422
renderErrorSet(base_decl, errorSetNodeList(decl_index, errorSetNode));
415423
}
416424

425+
domSourceLineNumbers.innerHTML = declLineNumbersHtml(decl_index);
417426
domSourceText.innerHTML = declSourceHtml(decl_index);
418427
domSectSource.classList.remove("hidden");
419428
}
@@ -428,6 +437,7 @@
428437
domTldDocs.classList.remove("hidden");
429438
}
430439

440+
domSourceLineNumbers.innerHTML = declLineNumbersHtml(decl_index);
431441
domSourceText.innerHTML = declSourceHtml(decl_index);
432442
domSectSource.classList.remove("hidden");
433443
}
@@ -643,27 +653,32 @@
643653
}
644654

645655
function onHashChange(state) {
656+
// Use a non-null state value to prevent the window scrolling if the user goes back to this history entry.
646657
history.replaceState({}, "");
647658
navigate(location.hash);
648659
if (state == null) window.scrollTo({top: 0});
649660
}
650661

651662
function onPopState(ev) {
652663
onHashChange(ev.state);
664+
syncDomSearch();
653665
}
654666

655667
function navigate(location_hash) {
656668
updateCurNav(location_hash);
657-
if (domSearch.value !== curNavSearch) {
658-
domSearch.value = curNavSearch;
659-
}
660669
render();
661670
if (imFeelingLucky) {
662671
imFeelingLucky = false;
663672
activateSelectedResult();
664673
}
665674
}
666675

676+
function syncDomSearch() {
677+
if (domSearch.value !== curNavSearch) {
678+
domSearch.value = curNavSearch;
679+
}
680+
}
681+
667682
function activateSelectedResult() {
668683
if (domSectSearchResults.classList.contains("hidden")) {
669684
return;
@@ -908,6 +923,10 @@
908923
return unwrapString(wasm_exports.decl_source_html(decl_index));
909924
}
910925

926+
function declLineNumbersHtml(decl_index) {
927+
return unwrapString(wasm_exports.decl_line_numbers_html(decl_index));
928+
}
929+
911930
function declDoctestHtml(decl_index) {
912931
return unwrapString(wasm_exports.decl_doctest_html(decl_index));
913932
}

docs/main.wasm

3.47 KB
Binary file not shown.

docs/sources.tar

2.44 MB
Binary file not shown.

src/array_hash_set.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// Open Source Initiative OSI - The MIT License (MIT):Licensing
22
/// The MIT License (MIT)
3-
/// Copyright (c) 2025 Ralph Caraveo (deckarep@gmail.com)
3+
/// Copyright (c) 2026 Ralph Caraveo (deckarep@gmail.com)
44
/// Permission is hereby granted, free of charge, to any person obtaining a copy of
55
/// this software and associated documentation files (the "Software"), to deal in
66
/// the Software without restriction, including without limitation the rights to
@@ -69,11 +69,11 @@ pub fn ArraySet(comptime E: type) type {
6969
};
7070

7171
const Self = @This();
72-
72+
7373
pub const empty: Self = .{
7474
.unmanaged = Map{},
7575
};
76-
76+
7777
// pub fn init() Self {
7878
// return .{
7979
// .unmanaged = Map{},
@@ -86,7 +86,7 @@ pub fn ArraySet(comptime E: type) type {
8686
return self;
8787
}
8888

89-
/// TODO: zig has still not changed neither of the two maps from selectMap 0.16,
89+
/// TODO: zig has still not changed neither of the two maps from selectMap 0.16,
9090
/// so we need to pass the allocator to deinit that.
9191
pub fn deinit(self: *Self, allocator: Allocator) void {
9292
self.unmanaged.deinit(allocator);
@@ -827,6 +827,6 @@ test "removals" {
827827
test "sizeOf matches" {
828828
// No bloat guarantee, after all we're just building on top of what's good.
829829
const expectedByteSize = 40;
830-
try expectEqual(expectedByteSize, @sizeOf(std.array_hash_map.AutoArrayHashMapUnmanaged(u32, void)));
830+
try expectEqual(expectedByteSize, @sizeOf(std.AutoArrayHashMapUnmanaged(u32, void)));
831831
try expectEqual(expectedByteSize, @sizeOf(ArraySet(u32)));
832832
}

src/hash_set.zig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// Open Source Initiative OSI - The MIT License (MIT):Licensing
22
/// The MIT License (MIT)
3-
/// Copyright (c) 2025 Ralph Caraveo (deckarep@gmail.com)
3+
/// Copyright (c) 2026 Ralph Caraveo (deckarep@gmail.com)
44
/// Permission is hereby granted, free of charge, to any person obtaining a copy of
55
/// this software and associated documentation files (the "Software"), to deal in
66
/// the Software without restriction, including without limitation the rights to
@@ -72,7 +72,7 @@ pub fn HashSetWithContext(comptime E: type, comptime Context: type, comptime max
7272
pub const Iterator = Map.KeyIterator;
7373

7474
const Self = @This();
75-
75+
7676
pub const empty: Self = if (@sizeOf(Context) == 0) .{
7777
.unmanaged = Map{},
7878
.context = if (Context == void) {} else undefined,
@@ -105,7 +105,7 @@ pub fn HashSetWithContext(comptime E: type, comptime Context: type, comptime max
105105
}
106106

107107
/// Destroys the unmanaged Set.
108-
/// TODO: zig has still not changed the HashMap in 0.16, so we need to pass
108+
/// TODO: zig has still not changed the HashMap in 0.16, so we need to pass
109109
/// the allocator here. It needs to be removed.
110110
pub fn deinit(self: *Self, allocator: Allocator) void {
111111
self.unmanaged.deinit(allocator);
@@ -251,10 +251,10 @@ pub fn HashSetWithContext(comptime E: type, comptime Context: type, comptime max
251251
/// and other. This set will contain all elements of this set that are not
252252
/// also elements of other.
253253
pub fn differenceUpdate(self: *Self, other: Self) Allocator.Error!void {
254-
var iter = other.iterator();
255-
256-
while (iter.next()) |key_ptr| {
257-
_ = self.remove(key_ptr.*);
254+
var iter = other.iterator();
255+
256+
while (iter.next()) |key_ptr| {
257+
_ = self.remove(key_ptr.*);
258258
}
259259
}
260260

@@ -344,7 +344,7 @@ pub fn HashSetWithContext(comptime E: type, comptime Context: type, comptime max
344344

345345
for (to_remove.items) |item| {
346346
_ = self.remove(item);
347-
}
347+
}
348348
}
349349

350350
/// isDisjoint returns true if the intersection between two sets is the null set.

src/main.zig

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
/// Open Source Initiative OSI - The MIT License (MIT):Licensing
2+
/// The MIT License (MIT)
3+
/// Copyright (c) 2026 Ralph Caraveo (deckarep@gmail.com)
4+
/// Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
/// this software and associated documentation files (the "Software"), to deal in
6+
/// the Software without restriction, including without limitation the rights to
7+
/// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8+
/// of the Software, and to permit persons to whom the Software is furnished to do
9+
/// so, subject to the following conditions:
10+
/// The above copyright notice and this permission notice shall be included in all
11+
/// copies or substantial portions of the Software.
12+
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13+
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14+
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15+
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16+
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18+
/// SOFTWARE.
19+
///
20+
///
121
const std = @import("std");
222
const set = @import("root.zig");
323

@@ -20,12 +40,11 @@ pub fn main(init: std.process.Init) void {
2040
// now we can initialize a HashSet with empty if no context is provided
2141
var A: HashSet(u32) = .empty;
2242
defer A.deinit(gpa);
23-
43+
2444
var B: ArraySet(u32) = .empty;
2545
defer B.deinit(gpa);
2646

2747
const ctx = SimpleHasher{};
2848
var C: set.HashSetContext(u32, SimpleHasher, 75) = .initContext(ctx);
2949
defer C.deinit(gpa);
30-
3150
}

src/root.zig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// Open Source Initiative OSI - The MIT License (MIT):Licensing
22
/// The MIT License (MIT)
3-
/// Copyright (c) 2025 Ralph Caraveo (deckarep@gmail.com)
3+
/// Copyright (c) 2026 Ralph Caraveo (deckarep@gmail.com)
44
/// Permission is hereby granted, free of charge, to any person obtaining a copy of
55
/// this software and associated documentation files (the "Software"), to deal in
66
/// the Software without restriction, including without limitation the rights to
@@ -18,7 +18,6 @@
1818
/// SOFTWARE.
1919
///
2020
///
21-
2221
/// Set is just a short convenient "default" alias. If you don't know
2322
/// which to pick, just use Set.
2423
pub const Set = HashSet;
@@ -30,7 +29,6 @@ pub const HashSetContext = @import("hash_set.zig").HashSetWithContext;
3029
/// This is a bit more specialized and optimized for heavy iteration.
3130
pub const ArraySet = @import("array_hash_set.zig").ArraySet;
3231

33-
3432
test "tests" {
3533
_ = @import("hash_set.zig");
3634
_ = @import("array_hash_set.zig");

0 commit comments

Comments
 (0)