Skip to content

Commit 4e7ca1d

Browse files
authored
Upgrade Zig version to 0.16.0 and add an AGENTS.md (#10)
1 parent 5257af9 commit 4e7ca1d

28 files changed

+623
-255
lines changed

.editorconfig

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,12 @@ indent_size = 4
88
insert_final_newline = true
99
trim_trailing_whitespace = true
1010

11-
[*.zig]
11+
[*.{zig,py}]
1212
max_line_length = 100
1313

1414
[*.md]
15-
max_line_length = 120
15+
max_line_length = 150
1616
trim_trailing_whitespace = false
1717

18-
[*.sh]
18+
[*.{yml,yaml,json}]
1919
indent_size = 2
20-
21-
[*.{yml,yaml}]
22-
indent_size = 2
23-
24-
[*.py]
25-
max_line_length = 100

.github/workflows/benches.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Run Benchmarks
33
on:
44
workflow_dispatch:
55
push:
6+
branches:
7+
- develop
68
tags:
79
- 'v*'
810
pull_request:
@@ -23,7 +25,7 @@ jobs:
2325
- name: Install Zig
2426
uses: goto-bus-stop/setup-zig@v2
2527
with:
26-
version: '0.15.2'
28+
version: '0.16.0'
2729

2830
- name: Install Dependencies
2931
run: |

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Install Zig
2020
uses: goto-bus-stop/setup-zig@v2
2121
with:
22-
version: '0.15.2'
22+
version: '0.16.0'
2323

2424
- name: Install System Dependencies
2525
run: |

.github/workflows/lints.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

.github/workflows/tests.yml

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,55 @@ name: Run Tests
33
on:
44
workflow_dispatch:
55
push:
6+
branches:
7+
- develop
68
tags:
79
- 'v*'
810
pull_request:
911
branches:
1012
- main
1113

14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
1218
permissions:
1319
contents: read
1420

1521
jobs:
1622
tests:
17-
runs-on: ubuntu-latest
23+
runs-on: ${{ matrix.os }}
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
include:
28+
- os: ubuntu-latest
29+
zig-url: https://ziglang.org/download/0.16.0/zig-x86_64-linux-0.16.0.tar.xz
30+
zig-dir: zig-x86_64-linux-0.16.0
31+
- os: macos-latest
32+
zig-url: https://ziglang.org/download/0.16.0/zig-aarch64-macos-0.16.0.tar.xz
33+
zig-dir: zig-aarch64-macos-0.16.0
34+
- os: windows-latest
35+
zig-url: https://ziglang.org/download/0.16.0/zig-x86_64-windows-0.16.0.zip
36+
zig-dir: zig-x86_64-windows-0.16.0
1837

1938
steps:
20-
- name: Checkout Repository
39+
- name: Checkout repository
2140
uses: actions/checkout@v4
2241

23-
- name: Install Zig
24-
uses: goto-bus-stop/setup-zig@v2
25-
with:
26-
version: '0.15.2'
42+
- name: Install Zig 0.16.0 (Unix)
43+
if: runner.os != 'Windows'
44+
run: |
45+
curl -sSfL ${{ matrix.zig-url }} | tar -xJ
46+
echo "$PWD/${{ matrix.zig-dir }}" >> "$GITHUB_PATH"
2747
28-
- name: Install Dependencies
48+
- name: Install Zig 0.16.0 (Windows)
49+
if: runner.os == 'Windows'
50+
shell: pwsh
2951
run: |
30-
sudo apt-get update
31-
sudo apt-get install -y make
52+
Invoke-WebRequest -Uri "${{ matrix.zig-url }}" -OutFile zig.zip
53+
Expand-Archive zig.zip -DestinationPath .
54+
echo "$PWD\${{ matrix.zig-dir }}" | Out-File -Append -FilePath $env:GITHUB_PATH
3255
33-
- name: Run the Tests
34-
run: make test
56+
- name: Run tests
57+
run: zig build test --summary all

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,5 @@ docs/api/
104104
*.dll
105105
*.exe
106106
latest
107+
.claude/
108+
.codex

AGENTS.md

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# AGENTS.md
2+
3+
This file provides guidance to coding agents collaborating on this repository.
4+
5+
## Mission
6+
7+
Ordered is a sorted-collection library for Zig. It provides in-memory data structures that keep their elements sorted:
8+
two set types (value-only) and four map types (key-value), all exposing a small, uniform API for insertion, lookup,
9+
removal, and in-order iteration.
10+
Priorities, in order:
11+
12+
1. Correctness of ordering, iteration, and memory management across insertions and removals.
13+
2. Minimal public API that is consistent across every container type.
14+
3. Zero non-Zig dependencies, maintainable, and well-tested code.
15+
4. Cross-platform support (Linux, macOS, and Windows).
16+
17+
## Core Rules
18+
19+
- Use English for code, comments, docs, and tests.
20+
- Prefer small, focused changes over large refactoring.
21+
- Add comments only when they clarify non-obvious behavior.
22+
- Do not add features, error handling, or abstractions beyond what is needed for the current task.
23+
- Keep the project dependency-free: no external Zig packages or C libraries unless explicitly agreed.
24+
25+
## Writing Style
26+
27+
- Use Oxford commas in inline lists: "a, b, and c" not "a, b, c".
28+
- Do not use em dashes. Restructure the sentence, or use a colon or semicolon instead.
29+
- Avoid colorful adjectives and adverbs. Write "TCP proxy" not "lightweight TCP proxy", "scoring components" not "transparent scoring components".
30+
- Use noun phrases for checklist items, not imperative verbs. Write "redundant index detection" not "detect redundant indexes".
31+
- Headings in Markdown files must be in the title case: "Build from Source" not "Build from source". Minor words (a, an, the, and, but, or, for, in,
32+
on, at, to, by, of, is, are, was, were, be) stay lowercase unless they are the first word.
33+
34+
## Repository Layout
35+
36+
- `src/lib.zig`: Public API entry point. Re-exports `SortedSet`, `RedBlackTreeSet`, `BTreeMap`, `SkipListMap`, `TrieMap`, and `CartesianTreeMap`.
37+
- `src/ordered/sorted_set.zig`: `SortedSet` (insertion-sorted `std.ArrayList` backed by a linear scan for insert and removal).
38+
- `src/ordered/red_black_tree_set.zig`: `RedBlackTreeSet` (self-balancing BST; takes an explicit three-way comparison function, consistent with the other generic-key containers).
39+
- `src/ordered/btree_map.zig`: `BTreeMap` (cache-friendly B-tree with configurable branching factor).
40+
- `src/ordered/skip_list_map.zig`: `SkipListMap` (probabilistic skip list with a per-instance PRNG).
41+
- `src/ordered/trie_map.zig`: `TrieMap` (prefix tree, specialised for `[]const u8` keys).
42+
- `src/ordered/cartesian_tree_map.zig`: `CartesianTreeMap` (treap combining BST ordering with max-heap priorities; takes an explicit key-comparison function).
43+
- `examples/`: Self-contained example programs (`e1_btree_map.zig` through `e6_cartesian_tree_map.zig`) built as executables via `build.zig`.
44+
- `benches/`: Benchmark programs (`b1_btree_map.zig` through `b6_cartesian_tree_map.zig`) built in `ReleaseFast`.
45+
- `benches/util/timer.zig`: Internal compatibility shim for the removed `std.time.Timer`, backed by `std.Io.Timestamp`.
46+
- `.github/workflows/`: CI workflows (`tests.yml` for unit tests on Linux, macOS, and Windows, `docs.yml`, `lints.yml`, and `benches.yml`).
47+
- `build.zig` / `build.zig.zon`: Zig build configuration and package metadata.
48+
- `Makefile`: GNU Make wrapper around `zig build` targets.
49+
- `docs/`: Generated API docs land in `docs/api/` (produced by `make docs`).
50+
51+
## Architecture
52+
53+
### Common API Across Containers
54+
55+
Every map exposes `init(allocator)`, `deinit()`, `count()`, `contains(key)`, `get(key)`, `getPtr(key)`, `put(key, value)`,
56+
`remove(key)`, and `iterator()`. Every set exposes the same shape with value-only variants. New containers should
57+
adopt this surface instead of inventing new method names.
58+
59+
### Iteration
60+
61+
Iterators return entries in the natural sort order of the underlying structure. Modifying a container during
62+
iteration is undefined behaviour; each container's docstring states this explicitly. New iterators should follow
63+
the same convention and document the contract.
64+
65+
### Randomised Containers
66+
67+
`SkipListMap` and `CartesianTreeMap` use randomness internally (levels and priorities, respectively). Each instance
68+
owns its own `std.Random.DefaultPrng`, seeded at `init` from an ASLR-derived hash of a stack address, which is
69+
sufficient randomness for skip-list level selection and treap priority generation. Callers do not need to provide
70+
a seed. Tests that require deterministic behaviour should use the explicit `*WithPriority` / level-setting API
71+
on the container rather than seeding the PRNG directly.
72+
73+
### Public API Surface
74+
75+
Everything re-exported from `src/lib.zig` is part of the public API. Changes to names, signatures, or semantics
76+
there are breaking. The rest of `src/ordered/` is internal and may be refactored freely as long as the public
77+
surface and its behavior are preserved.
78+
79+
### Dependencies
80+
81+
Ordered has **no external Zig or C dependencies**.
82+
The only `build.zig.zon` entries should be Ordered itself.
83+
Please do not add dependencies without prior discussion.
84+
85+
## Zig Conventions
86+
87+
- Zig version: 0.16.0 (as declared in `build.zig.zon` and the Makefile's `ZIG_LOCAL` path).
88+
- Formatting is enforced by `zig fmt`. Run `make format` before committing.
89+
- Naming follows Zig standard-library conventions: `camelCase` for functions (e.g. `getPtr`, `keysWithPrefix`), `snake_case` for local variables and
90+
struct fields, `PascalCase` for types and structs, and `SCREAMING_SNAKE_CASE` for top-level compile-time constants.
91+
92+
## Required Validation
93+
94+
Run the relevant targets for any change:
95+
96+
| Target | Command | What It Runs |
97+
|------------------|-------------------------------------|-------------------------------------------------------------------|
98+
| Unit tests | `make test` | Inline `test` blocks across `src/lib.zig` and `src/ordered/*.zig` |
99+
| Lint | `make lint` | Checks Zig formatting with `zig fmt --check src examples` |
100+
| Single example | `make run EXAMPLE=e1_btree_map` | Builds and runs one example program |
101+
| All examples | `make run` | Builds and runs every example under `examples/` |
102+
| Single benchmark | `make bench BENCHMARK=b1_btree_map` | Builds (ReleaseFast) and runs one benchmark program |
103+
| All benchmarks | `make bench` | Builds and runs every benchmark under `benches/` |
104+
| Docs | `make docs` | Generates API docs into `docs/api` |
105+
| Everything | `make all` | Runs `build`, `test`, `lint`, and `docs` |
106+
107+
## First Contribution Flow
108+
109+
1. Read the relevant module under `src/ordered/` (often one container file per change).
110+
2. Implement the smallest change that covers the requirement.
111+
3. Add or update inline `test` blocks in the changed Zig module to cover the new behavior.
112+
4. Run `make test` and `make lint`.
113+
5. If the change could affect performance, also run the corresponding benchmark with `make bench BENCHMARK=bN_*`.
114+
115+
Good first tasks:
116+
117+
- New example under `examples/` demonstrating a container method, listed in `examples/README.md`.
118+
- Additional inline `test` block covering a boundary case (empty container, single element, duplicate key, unicode key).
119+
- Performance improvement in an existing container, paired with benchmark output before/after.
120+
- Documentation refinement in a container module's top-level docstring.
121+
122+
## Testing Expectations
123+
124+
- Unit and regression tests live as inline `test` blocks in the module they cover (`src/lib.zig` and `src/ordered/*.zig`). There is no separate
125+
`tests/` directory.
126+
- Tests are discovered automatically via `std.testing.refAllDecls(@This())` in `src/lib.zig`, so new `test` blocks only need to live in a module that
127+
is reachable from `lib.zig`.
128+
- Every new public function or container branch must ship with at least one `test` block that exercises it, including the error paths where
129+
applicable.
130+
- Memory tests should use `std.testing.allocator` so leaks are caught automatically.
131+
- No public API change is complete without a test covering the new or changed behavior.
132+
133+
## Change Design Checklist
134+
135+
Before coding:
136+
137+
1. Modules affected by the change (which container file, or `lib.zig` if the public surface moves).
138+
2. Whether the change alters ordering, iteration, or removal semantics, and therefore needs explicit test coverage.
139+
3. Public API impact, i.e. whether the change adds to or alters anything re-exported from `src/lib.zig`, and is therefore additive or breaking.
140+
4. Cross-platform implications, especially for anything that touches timing, the filesystem, or non-deterministic ordering.
141+
142+
Before submitting:
143+
144+
1. `make test` passes.
145+
2. `make lint` passes.
146+
3. `make bench` still succeeds for any benchmark whose container was touched, with a note on whether performance moved.
147+
4. Docs updated (`make docs`) if the public API surface changed, and `README.md` ticked or updated if a container was added or removed.
148+
149+
## Commit and PR Hygiene
150+
151+
- Keep commits scoped to one logical change.
152+
- PR descriptions should include:
153+
1. Behavioral change summary.
154+
2. Tests added or updated.
155+
3. Whether benchmarks were run locally (yes/no), and on which OS, with before/after numbers when relevant.

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ would like to work on or if it has already been resolved.
2828
2929
### Development Workflow
3030

31+
> [!IMPORTANT]
32+
> If you're using an AI-assisted coding tool like Claude Code or Codex, make sure the AI follows the instructions in the [AGENTS.md](AGENTS.md) file.
33+
3134
#### Prerequisites
3235

3336
Install GNU Make on your system if it's not already installed.

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# ################################################################################
22
# # Configuration and Variables
33
# ################################################################################
4-
ZIG ?= $(shell which zig || echo ~/.local/share/zig/0.15.2/zig)
4+
ZIG_LOCAL := $(HOME)/.local/share/zig/0.16.0/zig
5+
ZIG ?= $(shell test -x $(ZIG_LOCAL) && echo $(ZIG_LOCAL) || which zig)
56
BUILD_TYPE ?= Debug
67
BUILD_OPTS = -Doptimize=$(BUILD_TYPE)
78
JOBS ?= $(shell nproc || echo 2)

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88

99
[![Tests](https://img.shields.io/github/actions/workflow/status/CogitatorTech/ordered/tests.yml?label=tests&style=flat&labelColor=282c34&logo=github)](https://github.com/CogitatorTech/ordered/actions/workflows/tests.yml)
1010
[![Benchmarks](https://img.shields.io/github/actions/workflow/status/CogitatorTech/ordered/benches.yml?label=benchmarks&style=flat&labelColor=282c34&logo=github)](https://github.com/CogitatorTech/ordered/actions/workflows/benches.yml)
11-
[![CodeFactor](https://img.shields.io/codefactor/grade/github/CogitatorTech/ordered?label=quality&style=flat&labelColor=282c34&logo=codefactor)](https://www.codefactor.io/repository/github/CogitatorTech/ordered)
12-
[![Zig Version](https://img.shields.io/badge/Zig-0.15.2-orange?logo=zig&labelColor=282c34)](https://ziglang.org/download/)
11+
[![Zig Version](https://img.shields.io/badge/Zig-0.16.0-orange?logo=zig&labelColor=282c34)](https://ziglang.org/download/)
1312
[![Release](https://img.shields.io/github/release/CogitatorTech/ordered.svg?label=release&style=flat&labelColor=282c34&logo=github)](https://github.com/CogitatorTech/ordered/releases/latest)
14-
<br>
1513
[![Docs](https://img.shields.io/badge/docs-read-blue?style=flat&labelColor=282c34&logo=read-the-docs)](https://CogitatorTech.github.io/ordered/)
1614
[![Examples](https://img.shields.io/badge/examples-view-green?style=flat&labelColor=282c34&logo=zig)](https://github.com/CogitatorTech/ordered/tree/main/examples)
1715
[![License](https://img.shields.io/badge/license-MIT-007ec6?label=license&style=flat&labelColor=282c34&logo=open-source-initiative)](https://github.com/CogitatorTech/ordered/blob/main/LICENSE)
@@ -78,9 +76,18 @@ Run the following command in the root directory of your project to download Orde
7876
zig fetch --save=ordered "https://github.com/CogitatorTech/ordered/archive/<branch_or_tag>.tar.gz"
7977
```
8078

81-
Replace `<branch_or_tag>` with the desired branch or release tag, like `main` (for the development version) or `v0.1.0`.
79+
Replace `<branch_or_tag>` with the desired branch or release tag, like `main` (for the development version) or `v0.3.0`.
8280
This command will download Ordered and add it to Zig's global cache and update your project's `build.zig.zon` file.
8381

82+
Zig version supported by each tagged release:
83+
84+
| Zig | Ordered Tags |
85+
|----------|--------------|
86+
| `0.16.0` | `v0.2.x` |
87+
| `0.15.2` | `v0.1.0` |
88+
89+
The `main` branch normally is developed and build using the latest (non-developmental) Zig release.
90+
8491
#### Adding to Build Script
8592

8693
Next, modify your `build.zig` file to make Ordered available to your build target as a module.

0 commit comments

Comments
 (0)