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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ zig build test

```sh
# With Zig installed:
zigup build docs && cp -a zig-out/docs/. docs/
zig build docs && cp -a zig-out/docs/. docs/

# Alternatively, using Zigup:
zigup run <zig-version> build docs && cp -a zig-out/docs/. docs/
Expand Down
10 changes: 4 additions & 6 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
.{
.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 = .{},

.paths = .{
"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",
},
}
18 changes: 17 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -429,7 +438,14 @@ <h2>Example Usage</h2>
</div>
<div id="sectSource" class="hidden">
<h2>Source Code</h2>
<pre><code id="sourceText"></code></pre>
<div class="source-code">
<div class="source-line-numbers">
<pre><code id="sourceLineNumbers"></code></pre>
</div>
<div class="source-text">
<pre><code id="sourceText"></code></pre>
</div>
</div>
</div>
</section>
<div id="helpDialog" class="hidden">
Expand Down
25 changes: 22 additions & 3 deletions docs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
}
});
});

Expand Down Expand Up @@ -233,6 +239,7 @@
href: location.hash,
}]);

domSourceLineNumbers.innerHTML = declLineNumbersHtml(decl_index);
domSourceText.innerHTML = declSourceHtml(decl_index);

domSectSource.classList.remove("hidden");
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
}
Expand All @@ -428,6 +437,7 @@
domTldDocs.classList.remove("hidden");
}

domSourceLineNumbers.innerHTML = declLineNumbersHtml(decl_index);
domSourceText.innerHTML = declSourceHtml(decl_index);
domSectSource.classList.remove("hidden");
}
Expand Down Expand Up @@ -643,27 +653,32 @@
}

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});
}

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;
activateSelectedResult();
}
}

function syncDomSearch() {
if (domSearch.value !== curNavSearch) {
domSearch.value = curNavSearch;
}
}

function activateSelectedResult() {
if (domSectSearchResults.classList.contains("hidden")) {
return;
Expand Down Expand Up @@ -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));
}
Expand Down
Binary file modified docs/main.wasm
Binary file not shown.
Binary file modified docs/sources.tar
Binary file not shown.
10 changes: 5 additions & 5 deletions src/array_hash_set.zig
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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{},
Expand All @@ -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);
Expand Down Expand Up @@ -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)));
}
16 changes: 8 additions & 8 deletions src/hash_set.zig
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.*);
}
}

Expand Down Expand Up @@ -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.
Expand Down
23 changes: 21 additions & 2 deletions src/main.zig
Original file line number Diff line number Diff line change
@@ -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");

Expand All @@ -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);

}
4 changes: 1 addition & 3 deletions src/root.zig
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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");
Expand Down
Loading