build docs && cp -a zig-out/docs/. docs/
diff --git a/build.zig.zon b/build.zig.zon
index 66a3e9f..26e0a5a 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -1,8 +1,8 @@
.{
.name = .ziglangSet,
- .version = "0.0.1",
+ .version = "0.1.0",
.fingerprint = 0x65aa5acd2ef4855,
- .minimum_zig_version = "0.15.1",
+ .minimum_zig_version = "0.16.0",
.dependencies = .{},
@@ -10,10 +10,8 @@
"LICENSE",
"build.zig",
"build.zig.zon",
- "src/array_hash_set/managed.zig",
- "src/array_hash_set/unmanaged.zig",
- "src/hash_set/managed.zig",
- "src/hash_set/unmanaged.zig",
+ "src/hash_set.zig",
+ "src/array_hash_set.zig",
"src/root.zig",
},
}
diff --git a/docs/index.html b/docs/index.html
index e60a3f9..75c0daf 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -40,6 +40,15 @@
code a {
color: #000000;
}
+ .source-code {
+ display: grid;
+ grid-template-columns: auto 1fr;
+ align-items: start;
+ }
+ .source-line-numbers pre {
+ text-align: right;
+ color: #666;
+ }
#listFields > div, #listParams > div {
margin-bottom: 1em;
}
@@ -429,7 +438,14 @@ Example Usage
diff --git a/docs/main.js b/docs/main.js
index 330b51b..a9bf4a7 100644
--- a/docs/main.js
+++ b/docs/main.js
@@ -50,6 +50,7 @@
const domSectTypes = document.getElementById("sectTypes");
const domSectValues = document.getElementById("sectValues");
const domSourceText = document.getElementById("sourceText");
+ const domSourceLineNumbers = document.getElementById("sourceLineNumbers");
const domStatus = document.getElementById("status");
const domTableFnErrors = document.getElementById("tableFnErrors");
const domTldDocs = document.getElementById("tldDocs");
@@ -129,6 +130,11 @@
domSearch.addEventListener('input', onSearchChange, false);
window.addEventListener('keydown', onWindowKeyDown, false);
onHashChange(null);
+ if (domSearch.value) {
+ // user started typing a search query while the page was loading
+ curSearchIndex = -1;
+ startAsyncSearch();
+ }
});
});
@@ -233,6 +239,7 @@
href: location.hash,
}]);
+ domSourceLineNumbers.innerHTML = declLineNumbersHtml(decl_index);
domSourceText.innerHTML = declSourceHtml(decl_index);
domSectSource.classList.remove("hidden");
@@ -384,6 +391,7 @@
if (members.length !== 0 || fields.length !== 0) {
renderNamespace(decl_index, members, fields);
} else {
+ domSourceLineNumbers.innerHTML = declLineNumbersHtml(decl_index);
domSourceText.innerHTML = declSourceHtml(decl_index);
domSectSource.classList.remove("hidden");
}
@@ -414,6 +422,7 @@
renderErrorSet(base_decl, errorSetNodeList(decl_index, errorSetNode));
}
+ domSourceLineNumbers.innerHTML = declLineNumbersHtml(decl_index);
domSourceText.innerHTML = declSourceHtml(decl_index);
domSectSource.classList.remove("hidden");
}
@@ -428,6 +437,7 @@
domTldDocs.classList.remove("hidden");
}
+ domSourceLineNumbers.innerHTML = declLineNumbersHtml(decl_index);
domSourceText.innerHTML = declSourceHtml(decl_index);
domSectSource.classList.remove("hidden");
}
@@ -643,6 +653,7 @@
}
function onHashChange(state) {
+ // Use a non-null state value to prevent the window scrolling if the user goes back to this history entry.
history.replaceState({}, "");
navigate(location.hash);
if (state == null) window.scrollTo({top: 0});
@@ -650,13 +661,11 @@
function onPopState(ev) {
onHashChange(ev.state);
+ syncDomSearch();
}
function navigate(location_hash) {
updateCurNav(location_hash);
- if (domSearch.value !== curNavSearch) {
- domSearch.value = curNavSearch;
- }
render();
if (imFeelingLucky) {
imFeelingLucky = false;
@@ -664,6 +673,12 @@
}
}
+ function syncDomSearch() {
+ if (domSearch.value !== curNavSearch) {
+ domSearch.value = curNavSearch;
+ }
+ }
+
function activateSelectedResult() {
if (domSectSearchResults.classList.contains("hidden")) {
return;
@@ -908,6 +923,10 @@
return unwrapString(wasm_exports.decl_source_html(decl_index));
}
+ function declLineNumbersHtml(decl_index) {
+ return unwrapString(wasm_exports.decl_line_numbers_html(decl_index));
+ }
+
function declDoctestHtml(decl_index) {
return unwrapString(wasm_exports.decl_doctest_html(decl_index));
}
diff --git a/docs/main.wasm b/docs/main.wasm
index 1fca7d6..99e35d7 100755
Binary files a/docs/main.wasm and b/docs/main.wasm differ
diff --git a/docs/sources.tar b/docs/sources.tar
index 4b17030..55e1bca 100644
Binary files a/docs/sources.tar and b/docs/sources.tar differ
diff --git a/src/array_hash_set.zig b/src/array_hash_set.zig
index 17330c2..59bc4b7 100644
--- a/src/array_hash_set.zig
+++ b/src/array_hash_set.zig
@@ -1,6 +1,6 @@
/// Open Source Initiative OSI - The MIT License (MIT):Licensing
/// The MIT License (MIT)
-/// Copyright (c) 2025 Ralph Caraveo (deckarep@gmail.com)
+/// Copyright (c) 2026 Ralph Caraveo (deckarep@gmail.com)
/// Permission is hereby granted, free of charge, to any person obtaining a copy of
/// this software and associated documentation files (the "Software"), to deal in
/// the Software without restriction, including without limitation the rights to
@@ -69,11 +69,11 @@ pub fn ArraySet(comptime E: type) type {
};
const Self = @This();
-
+
pub const empty: Self = .{
.unmanaged = Map{},
};
-
+
// pub fn init() Self {
// return .{
// .unmanaged = Map{},
@@ -86,7 +86,7 @@ pub fn ArraySet(comptime E: type) type {
return self;
}
- /// TODO: zig has still not changed neither of the two maps from selectMap 0.16,
+ /// TODO: zig has still not changed neither of the two maps from selectMap 0.16,
/// so we need to pass the allocator to deinit that.
pub fn deinit(self: *Self, allocator: Allocator) void {
self.unmanaged.deinit(allocator);
@@ -827,6 +827,6 @@ test "removals" {
test "sizeOf matches" {
// No bloat guarantee, after all we're just building on top of what's good.
const expectedByteSize = 40;
- try expectEqual(expectedByteSize, @sizeOf(std.array_hash_map.AutoArrayHashMapUnmanaged(u32, void)));
+ try expectEqual(expectedByteSize, @sizeOf(std.AutoArrayHashMapUnmanaged(u32, void)));
try expectEqual(expectedByteSize, @sizeOf(ArraySet(u32)));
}
diff --git a/src/hash_set.zig b/src/hash_set.zig
index e26fad6..435651e 100644
--- a/src/hash_set.zig
+++ b/src/hash_set.zig
@@ -1,6 +1,6 @@
/// Open Source Initiative OSI - The MIT License (MIT):Licensing
/// The MIT License (MIT)
-/// Copyright (c) 2025 Ralph Caraveo (deckarep@gmail.com)
+/// Copyright (c) 2026 Ralph Caraveo (deckarep@gmail.com)
/// Permission is hereby granted, free of charge, to any person obtaining a copy of
/// this software and associated documentation files (the "Software"), to deal in
/// 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
pub const Iterator = Map.KeyIterator;
const Self = @This();
-
+
pub const empty: Self = if (@sizeOf(Context) == 0) .{
.unmanaged = Map{},
.context = if (Context == void) {} else undefined,
@@ -105,7 +105,7 @@ pub fn HashSetWithContext(comptime E: type, comptime Context: type, comptime max
}
/// Destroys the unmanaged Set.
- /// TODO: zig has still not changed the HashMap in 0.16, so we need to pass
+ /// TODO: zig has still not changed the HashMap in 0.16, so we need to pass
/// the allocator here. It needs to be removed.
pub fn deinit(self: *Self, allocator: Allocator) void {
self.unmanaged.deinit(allocator);
@@ -251,10 +251,10 @@ pub fn HashSetWithContext(comptime E: type, comptime Context: type, comptime max
/// and other. This set will contain all elements of this set that are not
/// also elements of other.
pub fn differenceUpdate(self: *Self, other: Self) Allocator.Error!void {
- var iter = other.iterator();
-
- while (iter.next()) |key_ptr| {
- _ = self.remove(key_ptr.*);
+ var iter = other.iterator();
+
+ while (iter.next()) |key_ptr| {
+ _ = self.remove(key_ptr.*);
}
}
@@ -344,7 +344,7 @@ pub fn HashSetWithContext(comptime E: type, comptime Context: type, comptime max
for (to_remove.items) |item| {
_ = self.remove(item);
- }
+ }
}
/// isDisjoint returns true if the intersection between two sets is the null set.
diff --git a/src/main.zig b/src/main.zig
index 1a4f836..aa02ce6 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -1,3 +1,23 @@
+/// Open Source Initiative OSI - The MIT License (MIT):Licensing
+/// The MIT License (MIT)
+/// Copyright (c) 2026 Ralph Caraveo (deckarep@gmail.com)
+/// Permission is hereby granted, free of charge, to any person obtaining a copy of
+/// this software and associated documentation files (the "Software"), to deal in
+/// the Software without restriction, including without limitation the rights to
+/// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+/// of the Software, and to permit persons to whom the Software is furnished to do
+/// so, subject to the following conditions:
+/// The above copyright notice and this permission notice shall be included in all
+/// copies or substantial portions of the Software.
+/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+/// SOFTWARE.
+///
+///
const std = @import("std");
const set = @import("root.zig");
@@ -20,12 +40,11 @@ pub fn main(init: std.process.Init) void {
// now we can initialize a HashSet with empty if no context is provided
var A: HashSet(u32) = .empty;
defer A.deinit(gpa);
-
+
var B: ArraySet(u32) = .empty;
defer B.deinit(gpa);
const ctx = SimpleHasher{};
var C: set.HashSetContext(u32, SimpleHasher, 75) = .initContext(ctx);
defer C.deinit(gpa);
-
}
diff --git a/src/root.zig b/src/root.zig
index 627c717..2c3b9e5 100644
--- a/src/root.zig
+++ b/src/root.zig
@@ -1,6 +1,6 @@
/// Open Source Initiative OSI - The MIT License (MIT):Licensing
/// The MIT License (MIT)
-/// Copyright (c) 2025 Ralph Caraveo (deckarep@gmail.com)
+/// Copyright (c) 2026 Ralph Caraveo (deckarep@gmail.com)
/// Permission is hereby granted, free of charge, to any person obtaining a copy of
/// this software and associated documentation files (the "Software"), to deal in
/// the Software without restriction, including without limitation the rights to
@@ -18,7 +18,6 @@
/// SOFTWARE.
///
///
-
/// Set is just a short convenient "default" alias. If you don't know
/// which to pick, just use Set.
pub const Set = HashSet;
@@ -30,7 +29,6 @@ pub const HashSetContext = @import("hash_set.zig").HashSetWithContext;
/// This is a bit more specialized and optimized for heavy iteration.
pub const ArraySet = @import("array_hash_set.zig").ArraySet;
-
test "tests" {
_ = @import("hash_set.zig");
_ = @import("array_hash_set.zig");