Skip to content

Commit 468a0a9

Browse files
committed
Small tweaks for Zig 0.14.0, updating docs, updating copyright
1 parent a727a16 commit 468a0a9

File tree

12 files changed

+103
-38
lines changed

12 files changed

+103
-38
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 Ralph Caraveo
3+
Copyright (c) 2025 Ralph Caraveo
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
![License](https://img.shields.io/github/license/deckarep/ziglang-set) ![Issue](https://img.shields.io/github/issues-raw/deckarep/ziglang-set?style=flat) ![Commit](https://img.shields.io/github/last-commit/deckarep/ziglang-set) ![CI](https://github.com/deckarep/ziglang-set/workflows/CI/badge.svg)
44

55
<p align="center">
6-
Ziglang-Set: a generic and general-purpose Set implementation for Zig. <br/> 🚧 PRE-ALPHA 🚧
6+
Ziglang-Set: a generic and general-purpose Set implementation for Zig. <br/> 🚧 BETA 🚧
77
</p>
88

99
#
@@ -21,21 +21,22 @@ Ziglang-Set: a generic and general-purpose Set implementation for Zig. <br/>
2121

2222
Zig currently [does not have](https://github.com/ziglang/zig/issues/6919) a built-in, general purpose Set data structure at this point in time. Until it does, try this!
2323

24-
Rationale: It may be common knowledge that a dictionary or map or hashset can be used as a set where the value is basically void. While this is true, there's a lot to think about in terms of supporting all the common set operations in a performant and correct way and there's no good reason why a common module for this can't exist. After studying the Zig stdlib, I'm hoping this implementation can fill that gap and provide some value.
24+
Rationale: It may be common knowledge that a dictionary, map or hashset can be used as a set with a value of `void`. While this is true, there's a lot to think about in terms of supporting all the common set operations in a performant and correct way and there's no good reason why a common module for this shouldn't exist. After studying the Zig stdlib, I'm hoping this implementation can fill that gap and provide some value.
2525

2626
#
2727

2828
This module offers a Set implementation built in the same vein and spirit of the other data structures within the Zig standard library. This is my attempt to model one that can get better over time and grow with community interest and support. See a problem, file a bug! Or better yet contribute and let's build the best implementation together.
2929

30-
I am the original author of the popular Go based set package: [golang-set](https://github.com/deckarep/golang-set) that is used by software components built by Docker, 1Password, Ethereum, SendGrid, CrowdStrike and HashiCorp. At just shy of `4k stars`, I figured I'd take a crack at building a comprehensive and generic Zig-based set that goes above and beyond the original Go implementation. After using Zig for over 2.5 years on personal projects, I thought it was time that Zig had a robust Set implementation for itself.
30+
I am the original author of the popular Go based set package: [golang-set](https://github.com/deckarep/golang-set) that is used by software components built by Docker, 1Password, Ethereum, SendGrid, CrowdStrike and HashiCorp. At just shy of `4.5k stars`, I figured I'd take a crack at building a comprehensive and generic Zig-based set that goes above and beyond the original Go implementation. After using Zig for over 3+ years on personal projects, I thought it was time that Zig had a robust Set implementation for itself.
3131

3232
This implementation gives credit and acknowledgement to the [Zig language](https://ziglang.org) and powerful [Std Library](https://ziglang.org/documentation/master/std/#std) [HashMap](https://ziglang.org/documentation/master/std/#std.hash_map.HashMap) data structure of which this set implementation is built on top of. Without that, this probably wouldn't exist. Efforts will be made to keep the Ziglang Set code fast and straightforward but this Set's raw speed will largely be bounded by the performance of the Zig HashMap of which it is built on top of.
3333

3434
#
3535

3636
#### Features
37-
* Offers idiomatic, generic-based Zig API - allocators, iterators, capacity hints, clearing, resizing, etc.
37+
* Offers idiomatic, generic-based Zig API - allocator support, iterators, capacity hints, clearing, resizing, etc.
3838
* A few flavors to choose from
39+
* NOTE: Future versions of Zig will be deprecating the `managed` variants, and this repo will be following suit.
3940
* Hash-based: everyday usecase, optimized for lookups primarily, insertion/removal secondarily - [further reading](https://devlog.hexops.com/2022/zig-hashmaps-explained/)
4041
* HashSetManaged - initializes with an allocator and holds it internally (built on top of unmanaged)
4142
* HashSetUnmanaged - does not hold an allocator, smaller footprint
@@ -57,11 +58,11 @@ This implementation gives credit and acknowledgement to the [Zig language](https
5758
* isProperSubset
5859
* isProperSuperset
5960
* pop
60-
* Fully documented and robustly tested - in progress
61+
* Fully documented and robustly tested
6162
* Performance aware to minimize unecessary allocs/iteration internally
6263
* Custom hash function support
63-
* "string" support - coming soon
64-
* Benchmarks - coming soon
64+
* "string" support
65+
* Benchmarks
6566
#
6667
#### Why use a set?
6768
* A set offers a fast way to manipulate data and avoid excessive looping. Look into it as there is already tons of literature on the advantages of having a set in your arsenal of tools.
@@ -213,3 +214,13 @@ Check the tests for more comprehensive examples on how to use this package.
213214
```sh
214215
zig build test
215216
```
217+
218+
#### Docs Generation
219+
220+
```sh
221+
# With Zig installed:
222+
zig build-lib -femit-docs src/root.zig
223+
224+
# Alternatively, using Zigup:
225+
zigup run {zig-version} build-lib -femit-docs src/root.zig
226+
```

build.zig.zon

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
.{
2-
.name = "ziglangSet",
2+
.name = .ziglangSet,
33
.version = "0.0.1",
4-
.minimum_zig_version = "0.12.0",
4+
.fingerprint = 0x65aa5acd2ef4855,
5+
.minimum_zig_version = "0.14.0",
56

67
.dependencies = .{},
78

docs/index.html

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
56
<title>Zig Documentation</title>
67
<link rel="icon" href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNTMgMTQwIj48ZyBmaWxsPSIjRjdBNDFEIj48Zz48cG9seWdvbiBwb2ludHM9IjQ2LDIyIDI4LDQ0IDE5LDMwIi8+PHBvbHlnb24gcG9pbnRzPSI0NiwyMiAzMywzMyAyOCw0NCAyMiw0NCAyMiw5NSAzMSw5NSAyMCwxMDAgMTIsMTE3IDAsMTE3IDAsMjIiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMzEsOTUgMTIsMTE3IDQsMTA2Ii8+PC9nPjxnPjxwb2x5Z29uIHBvaW50cz0iNTYsMjIgNjIsMzYgMzcsNDQiLz48cG9seWdvbiBwb2ludHM9IjU2LDIyIDExMSwyMiAxMTEsNDQgMzcsNDQgNTYsMzIiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMTE2LDk1IDk3LDExNyA5MCwxMDQiLz48cG9seWdvbiBwb2ludHM9IjExNiw5NSAxMDAsMTA0IDk3LDExNyA0MiwxMTcgNDIsOTUiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMTUwLDAgNTIsMTE3IDMsMTQwIDEwMSwyMiIvPjwvZz48Zz48cG9seWdvbiBwb2ludHM9IjE0MSwyMiAxNDAsNDAgMTIyLDQ1Ii8+PHBvbHlnb24gcG9pbnRzPSIxNTMsMjIgMTUzLDExNyAxMDYsMTE3IDEyMCwxMDUgMTI1LDk1IDEzMSw5NSAxMzEsNDUgMTIyLDQ1IDEzMiwzNiAxNDEsMjIiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMTI1LDk1IDEzMCwxMTAgMTA2LDExNyIvPjwvZz48L2c+PC9zdmc+">
78
<style type="text/css">
9+
*, *::before, *::after {
10+
box-sizing: border-box;
11+
}
812
body {
913
font-family: system-ui, -apple-system, Roboto, "Segoe UI", sans-serif;
1014
color: #000000;
@@ -26,6 +30,9 @@
2630
margin: 0;
2731
overflow-x: auto;
2832
}
33+
:not(pre) > code {
34+
white-space: break-spaces;
35+
}
2936
code {
3037
font-family:"Source Code Pro",monospace;
3138
font-size: 0.9em;
@@ -153,6 +160,23 @@
153160
cursor: default;
154161
}
155162

163+
#errors {
164+
background-color: #faa;
165+
position: fixed;
166+
left: 0;
167+
bottom: 0;
168+
width: 100%;
169+
max-height: min(20em, 50vh);
170+
padding: 0.5em;
171+
overflow: auto;
172+
}
173+
#errors h1 {
174+
font-size: 1.5em;
175+
}
176+
#errors pre {
177+
background-color: #fcc;
178+
}
179+
156180
#listSearchResults li.selected {
157181
background-color: #93e196;
158182
}
@@ -167,7 +191,8 @@
167191
margin-top: 0.5em;
168192
}
169193

170-
td {
194+
td, th {
195+
text-align: unset;
171196
vertical-align: top;
172197
margin: 0;
173198
padding: 0.5em;
@@ -247,6 +272,14 @@
247272
#listSearchResults li.selected a {
248273
color: #fff;
249274
}
275+
#errors {
276+
background-color: #800;
277+
color: #fff;
278+
}
279+
#errors pre {
280+
background-color: #a00;
281+
color: #fff;
282+
}
250283
dl > div {
251284
border-color: #373737;
252285
}
@@ -409,6 +442,10 @@ <h1>Keyboard Shortcuts</h1>
409442
<dl><dt><kbd></kbd></dt><dd>Move down in search results</dd></dl>
410443
<dl><dt><kbd></kbd></dt><dd>Go to active search result</dd></dl>
411444
</div>
445+
<div id="errors" class="hidden">
446+
<h1>Errors</h1>
447+
<pre id="errorsText"></pre>
448+
</div>
412449
<script src="main.js"></script>
413450
</body>
414451
</html>

docs/main.js

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
(function() {
22
const CAT_namespace = 0;
3-
const CAT_global_variable = 1;
4-
const CAT_function = 2;
5-
const CAT_primitive = 3;
6-
const CAT_error_set = 4;
7-
const CAT_global_const = 5;
8-
const CAT_alias = 6;
9-
const CAT_type = 7;
10-
const CAT_type_type = 8;
11-
const CAT_type_function = 9;
3+
const CAT_container = 1;
4+
const CAT_global_variable = 2;
5+
const CAT_function = 3;
6+
const CAT_primitive = 4;
7+
const CAT_error_set = 5;
8+
const CAT_global_const = 6;
9+
const CAT_alias = 7;
10+
const CAT_type = 8;
11+
const CAT_type_type = 9;
12+
const CAT_type_function = 10;
13+
14+
const LOG_err = 0;
15+
const LOG_warn = 1;
16+
const LOG_info = 2;
17+
const LOG_debug = 3;
1218

1319
const domDocTestsCode = document.getElementById("docTestsCode");
1420
const domFnErrorsAnyError = document.getElementById("fnErrorsAnyError");
@@ -47,6 +53,8 @@
4753
const domStatus = document.getElementById("status");
4854
const domTableFnErrors = document.getElementById("tableFnErrors");
4955
const domTldDocs = document.getElementById("tldDocs");
56+
const domErrors = document.getElementById("errors");
57+
const domErrorsText = document.getElementById("errorsText");
5058

5159
var searchTimer = null;
5260

@@ -83,13 +91,24 @@
8391

8492
WebAssembly.instantiateStreaming(wasm_promise, {
8593
js: {
86-
log: function(ptr, len) {
94+
log: function(level, ptr, len) {
8795
const msg = decodeString(ptr, len);
88-
console.log(msg);
89-
},
90-
panic: function (ptr, len) {
91-
const msg = decodeString(ptr, len);
92-
throw new Error("panic: " + msg);
96+
switch (level) {
97+
case LOG_err:
98+
console.error(msg);
99+
domErrorsText.textContent += msg + "\n";
100+
domErrors.classList.remove("hidden");
101+
break;
102+
case LOG_warn:
103+
console.warn(msg);
104+
break;
105+
case LOG_info:
106+
console.info(msg);
107+
break;
108+
case LOG_debug:
109+
console.debug(msg);
110+
break;
111+
}
93112
},
94113
},
95114
}).then(function(obj) {
@@ -184,6 +203,7 @@
184203
const category = wasm_exports.categorize_decl(decl_index, 0);
185204
switch (category) {
186205
case CAT_namespace:
206+
case CAT_container:
187207
return renderNamespacePage(decl_index);
188208
case CAT_global_variable:
189209
case CAT_primitive:
@@ -426,16 +446,12 @@
426446
while (true) {
427447
const member_category = wasm_exports.categorize_decl(member, 0);
428448
switch (member_category) {
429-
case CAT_namespace:
430-
if (wasm_exports.decl_field_count(member) > 0) {
431-
typesList.push({original: original, member: member});
432-
} else {
433-
namespacesList.push({original: original, member: member});
434-
}
435-
continue member_loop;
436449
case CAT_namespace:
437450
namespacesList.push({original: original, member: member});
438451
continue member_loop;
452+
case CAT_container:
453+
typesList.push({original: original, member: member});
454+
continue member_loop;
439455
case CAT_global_variable:
440456
varsList.push(member);
441457
continue member_loop;

docs/main.wasm

55 Bytes
Binary file not shown.

docs/sources.tar

1.8 MB
Binary file not shown.

src/array_hash_set/managed.zig

Lines changed: 1 addition & 1 deletion
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) 2024 Ralph Caraveo ([email protected])
3+
/// Copyright (c) 2025 Ralph Caraveo ([email protected])
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

src/array_hash_set/unmanaged.zig

Lines changed: 1 addition & 1 deletion
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) 2024 Ralph Caraveo ([email protected])
3+
/// Copyright (c) 2025 Ralph Caraveo ([email protected])
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

src/hash_set/managed.zig

Lines changed: 1 addition & 1 deletion
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) 2024 Ralph Caraveo ([email protected])
3+
/// Copyright (c) 2025 Ralph Caraveo ([email protected])
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

0 commit comments

Comments
 (0)