Skip to content

Commit dbbdbac

Browse files
committed
The base commit
1 parent 965d5df commit dbbdbac

41 files changed

Lines changed: 2370 additions & 1380 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# EditorConfig is awesome: https://EditorConfig.org
2-
31
# Top-most EditorConfig file
42
root = true
53

@@ -29,4 +27,6 @@ indent_size = 2
2927
[*.{yml,yaml}]
3028
indent_size = 2
3129
32-
30+
# Python files
31+
[*.py]
32+
max_line_length = 100

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ temp/
9191

9292
# Dependency lock files (optional)
9393
poetry.lock
94+
uv.lock
9495

9596
# Additional files and directories to ignore (put below)
96-
docs/api/
9797
*_output.txt
98-
98+
public/
99+
docs/api/

.pre-commit-config.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
default_stages: [ pre-push ]
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v5.0.0
5+
hooks:
6+
- id: trailing-whitespace
7+
- id: end-of-file-fixer
8+
- id: check-yaml
9+
- id: check-merge-conflict
10+
- id: check-added-large-files
11+
args: [ '--maxkb=600' ]
12+
13+
- repo: local
14+
hooks:
15+
- id: format
16+
name: Format the code
17+
entry: make format
18+
language: system
19+
pass_filenames: false
20+
21+
- id: lint
22+
name: Check code style
23+
entry: make lint
24+
language: system
25+
pass_filenames: false
26+
27+
- id: test
28+
name: Run tests
29+
entry: make test
30+
language: system
31+
pass_filenames: false

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ Contributions are always welcome and appreciated.
55

66
## How to Contribute
77

8-
Please check the [issue tracker](https://github.com/habedi/template-zig-project/issues) to see if there is an issue you
8+
Please check the [issue tracker](https://github.com/habedi/ordered/issues) to see if there is an issue you
99
would like to work on or if it has already been resolved.
1010

1111
### Reporting Bugs
1212

13-
1. Open an issue on the [issue tracker](https://github.com/habedi/template-zig-project/issues).
13+
1. Open an issue on the [issue tracker](https://github.com/habedi/ordered/issues).
1414
2. Include information such as steps to reproduce the observed behavior and relevant logs or screenshots.
1515

1616
### Suggesting Features
1717

18-
1. Open an issue on the [issue tracker](https://github.com/habedi/template-zig-project/issues).
18+
1. Open an issue on the [issue tracker](https://github.com/habedi/ordered/issues).
1919
2. Provide details about the feature, its purpose, and potential implementation ideas.
2020

2121
## Submitting Pull Requests

Makefile

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,25 @@
1-
# Generic Makefile for Zig projects
2-
3-
# Load environment variables from .env file
4-
ifneq (,$(wildcard ./.env))
5-
include .env
6-
export $(shell sed 's/=.*//' .env)
7-
else
8-
$(warning .env file not found. Environment variables not loaded.)
9-
endif
10-
111
################################################################################
122
# Configuration and Variables
133
################################################################################
14-
ZIG ?= zig
15-
ZIG_VERSION := $(shell $(ZIG) version)
4+
ZIG ?= $(shell which zig || echo ~/.local/share/zig/0.14.1/zig)
165
BUILD_TYPE ?= Debug
176
BUILD_OPTS = -Doptimize=$(BUILD_TYPE)
187
JOBS ?= $(shell nproc || echo 2)
198
SRC_DIR := src
20-
TEST_DIR := tests
9+
EXAMPLES_DIR := examples
2110
BUILD_DIR := zig-out
2211
CACHE_DIR := .zig-cache
23-
DOC_SRC := src/root.zig
12+
DOC_SRC := src/lib.zig
2413
DOC_OUT := docs/api/
2514
COVERAGE_DIR := coverage
26-
BINARY_NAME := template-zig-project
27-
BINARY_PATH := $(BUILD_DIR)/bin/$(BINARY_NAME)
28-
TEST_EXECUTABLE := $(BUILD_DIR)/bin/test
29-
PREFIX ?= /usr/local
15+
BINARY_NAME := example
3016
RELEASE_MODE := ReleaseSmall
17+
TEST_FLAGS := --summary all --verbose
18+
19+
# Automatically find all example names (e.g., btree_map, trie, etc.)
20+
EXAMPLES := $(patsubst %.zig,%,$(notdir $(wildcard examples/*.zig)))
21+
# CHANGED: Default is now "all"
22+
EXAMPLE ?= all
3123

3224
SHELL := /usr/bin/env bash
3325
.SHELLFLAGS := -eu -o pipefail -c
@@ -36,68 +28,82 @@ SHELL := /usr/bin/env bash
3628
# Targets
3729
################################################################################
3830

39-
.PHONY: all build rebuild run test cov lint format doc clean install-deps release help coverage
31+
.PHONY: all help build rebuild run test release clean lint format doc install-deps coverage setup-hooks test-hooks
4032
.DEFAULT_GOAL := help
4133

4234
help: ## Show the help messages for all targets
43-
@grep -E '^[a-zA-Z0-9_-]+:.*?## ' Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf " %-10s %s\n", $$1, $$2}'
35+
@echo "Usage: make <target>"
36+
@echo ""
37+
@echo "Targets:"
38+
@grep -E '^[a-zA-Z_-]+:.*## .*$$' Makefile | \
39+
awk 'BEGIN {FS = ":.*## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
4440

4541
all: build test lint doc ## build, test, lint, and doc
4642

4743
build: ## Build project (Mode=$(BUILD_TYPE))
4844
@echo "Building project in $(BUILD_TYPE) mode with $(JOBS) concurrent jobs..."
49-
$(ZIG) build $(BUILD_OPTS) -j$(JOBS)
45+
@$(ZIG) build $(BUILD_OPTS) -j$(JOBS)
5046

5147
rebuild: clean build ## clean and build
5248

53-
run: build ## Run the main application
54-
@echo "Running $(BINARY_NAME)..."
55-
$(ZIG) build run $(BUILD_OPTS) --
49+
run: ## Run an example (e.g. 'make run EXAMPLE=trie' or 'make run' for all)
50+
@if [ "$(EXAMPLE)" = "all" ]; then \
51+
echo "--> Running all examples..."; \
52+
for ex in $(EXAMPLES); do \
53+
echo ""; \
54+
echo "--> Running example: $$ex"; \
55+
$(ZIG) build run-$$ex $(BUILD_OPTS); \
56+
done; \
57+
else \
58+
echo "--> Running example: $(EXAMPLE)"; \
59+
$(ZIG) build run-$(EXAMPLE) $(BUILD_OPTS); \
60+
fi
5661

57-
test: ## Run tests and generate coverage data
58-
@echo "Running tests with coverage enabled..."
59-
$(ZIG) build test $(BUILD_OPTS) -Denable-coverage=true -j$(JOBS)
62+
test: ## Run tests
63+
@echo "Running tests..."
64+
@$(ZIG) build test $(BUILD_OPTS) -j$(JOBS) $(TEST_FLAGS)
6065

6166
release: ## Build in Release mode
6267
@echo "Building the project in Release mode..."
6368
@$(MAKE) BUILD_TYPE=$(RELEASE_MODE) build
6469

6570
clean: ## Remove docs, build artifacts, and cache directories
6671
@echo "Removing build artifacts, cache, generated docs, and coverage files..."
67-
rm -rf $(BUILD_DIR) $(CACHE_DIR) $(DOC_OUT) *.profraw $(COVERAGE_DIR)
72+
@rm -rf $(BUILD_DIR) $(CACHE_DIR) $(DOC_OUT) *.profraw $(COVERAGE_DIR) public
6873

6974
lint: ## Check code style and formatting of Zig files
7075
@echo "Running code style checks..."
71-
$(ZIG) fmt --check $(SRC_DIR) $(TEST_DIR)
76+
@$(ZIG) fmt --check $(SRC_DIR) $(EXAMPLES_DIR)
7277

7378
format: ## Format Zig files
7479
@echo "Formatting Zig files..."
75-
$(ZIG) fmt .
80+
@$(ZIG) fmt .
7681

7782
doc: ## Generate API documentation
7883
@echo "Generating documentation from $(DOC_SRC) to $(DOC_OUT)..."
79-
mkdir -p $(DOC_OUT)
80-
@if $(ZIG) doc --help > /dev/null 2>&1; then \
81-
$(ZIG) doc $(DOC_SRC) --output-dir $(DOC_OUT); \
82-
else \
83-
$(ZIG) test -femit-docs $(DOC_SRC); \
84-
for f in docs/*; do \
85-
base=$$(basename "$$f"); \
86-
if [ "$$base" = "assets" ] || [ "$$base" = "api" ]; then \
87-
continue; \
88-
fi; \
89-
mv "$$f" $(DOC_OUT)/; \
90-
done; \
91-
fi
84+
@mkdir -p $(DOC_OUT)
85+
@$(ZIG) test $(DOC_SRC) -femit-docs=$(DOC_OUT)
9286

9387
install-deps: ## Install system dependencies (for Debian-based systems)
9488
@echo "Installing system dependencies..."
95-
sudo apt-get update
96-
sudo apt-get install -y make llvm snapd
97-
sudo snap install zig --beta --classic # Use `--edge --classic` to install the latest version
89+
@sudo apt-get update
90+
@sudo apt-get install -y make llvm snapd
91+
@sudo snap install zig --beta --classic
9892

99-
coverage: ## Generate code coverage report
100-
@echo "Building tests with coverage instrumentation..."
101-
@zig build test -Denable-coverage=true
93+
coverage: test ## Generate code coverage report
10294
@echo "Generating coverage report..."
103-
@kcov --include-pattern=src --verify coverage-out zig-out/bin/test-root
95+
@kcov --include-pattern=src --verify coverage-out-btree-map zig-out/bin/btree_map
96+
97+
setup-hooks: ## Install Git hooks (pre-commit and pre-push)
98+
@echo "Setting up Git hooks..."
99+
@if ! command -v pre-commit &> /dev/null; then \
100+
echo "pre-commit not found. Please install it using 'pip install pre-commit'"; \
101+
exit 1; \
102+
fi
103+
@pre-commit install --hook-type pre-commit
104+
@pre-commit install --hook-type pre-push
105+
@pre-commit install-hooks
106+
107+
test-hooks: ## Test Git hooks on all files
108+
@echo "Testing Git hooks..."
109+
@pre-commit run --all-files --show-diff-on-failure

README.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
1-
## Zig Project Template
1+
## Ordered
22

33
<div align="center">
44
<picture>
5-
<img alt="Zig Logo" src="docs/assets/logo/zero.svg" height="35%" width="35%">
5+
<img alt="Ordered Logo" src="logo.svg" height="25%" width="25%">
66
</picture>
77
</div>
88
<br>
99

10-
[![Tests](https://img.shields.io/github/actions/workflow/status/habedi/template-zig-project/tests.yml?label=tests&style=flat&labelColor=282c34&logo=github)](https://github.com/habedi/template-zig-project/actions/workflows/tests.yml)
11-
[![Lints](https://img.shields.io/github/actions/workflow/status/habedi/template-zig-project/lints.yml?label=lints&style=flat&labelColor=282c34&logo=github)](https://github.com/habedi/template-zig-project/actions/workflows/lints.yml)
12-
[![Code Coverage](https://img.shields.io/codecov/c/github/habedi/template-zig-project?label=coverage&style=flat&labelColor=282c34&logo=codecov)](https://codecov.io/gh/habedi/template-zig-project)
13-
[![CodeFactor](https://img.shields.io/codefactor/grade/github/habedi/template-zig-project?label=code%20quality&style=flat&labelColor=282c34&logo=codefactor)](https://www.codefactor.io/repository/github/habedi/template-zig-project)
14-
[![Docs](https://img.shields.io/badge/docs-latest-007ec6?label=docs&style=flat&labelColor=282c34&logo=readthedocs)](docs)
15-
[![License](https://img.shields.io/badge/license-MIT-007ec6?label=license&style=flat&labelColor=282c34&logo=open-source-initiative)](https://github.com/habedi/template-zig-project/blob/main/LICENSE)
16-
[![Release](https://img.shields.io/github/release/habedi/template-zig-project.svg?label=release&style=flat&labelColor=282c34&logo=github)](https://github.com/habedi/template-zig-project/releases/latest)
10+
[![Tests](https://img.shields.io/github/actions/workflow/status/habedi/ordered/tests.yml?label=tests&style=flat&labelColor=282c34&logo=github)](https://github.com/habedi/ordered/actions/workflows/tests.yml)
11+
[![Code Coverage](https://img.shields.io/codecov/c/github/habedi/ordered?label=coverage&style=flat&labelColor=282c34&logo=codecov)](https://codecov.io/gh/habedi/ordered)
12+
[![CodeFactor](https://img.shields.io/codefactor/grade/github/habedi/ordered?label=code%20quality&style=flat&labelColor=282c34&logo=codefactor)](https://www.codefactor.io/repository/github/habedi/ordered)
13+
[![License](https://img.shields.io/badge/license-MIT-007ec6?label=license&style=flat&labelColor=282c34&logo=open-source-initiative)](https://github.com/habedi/ordered/blob/main/LICENSE)
14+
[![Zig Version](https://img.shields.io/badge/Zig-0.14.1-orange?logo=zig&labelColor=282c34)](https://ziglang.org/download/)
15+
[![Release](https://img.shields.io/github/release/habedi/ordered.svg?label=release&style=flat&labelColor=282c34&logo=github)](https://github.com/habedi/ordered/releases/latest)
1716

18-
This is a project template for Zig projects.
19-
It provides a minimalistic project structure with pre-configured GitHub Actions, Makefile, and a few useful
20-
configuration files.
21-
I share it here in case it might be useful to others.
17+
---
2218

23-
### Features
19+
Ordered Zig library includes implementations of popular data structures including B-tree, skip lists, tries, and
20+
red-black tree.
2421

25-
- Minimalistic project structure
26-
- Pre-configured GitHub Actions for linting and testing
27-
- Makefile for managing the development workflow and tasks like code formatting, testing, linting, etc.
28-
- GitHub badges for tests, code quality and coverage, documentation, etc.
29-
- [Code of Conduct](CODE_OF_CONDUCT.md) and [Contributing Guidelines](CONTRIBUTING.md)
22+
> [!IMPORTANT]
23+
> This library is in very early stages of development and is not yet ready for serious use.
24+
> The API is not stable and may change frequently.
25+
> Additionally, it's not thoroughly tested or optimized so use it at your own risk.
3026
31-
### Getting Started
27+
### Features
3228

33-
Check out the [Makefile](Makefile) for available commands to manage the development workflow of the project.
29+
- Implementations for common data structures that maintain the order of keys:
30+
- [`BTreeMap`](src/btree_map.zig): A balanced tree map that maintains order of keys.
31+
- [`OrderedSet`](src/sorted_set.zig): A set with ordered elements.
32+
- [`SkipList`](src/skip_list.zig): A probabilistic data structure that allows fast search, insertion, and deletion.
33+
- [`Trie`](src/trie.zig): A prefix tree for fast retrieval of keys with common prefixes.
34+
- [`RedBlackTree`](src/red_black_tree.zig): A self-balancing binary search tree that maintains order of keys.
3435

35-
```shell
36-
# Install system and development dependencies (for Debian-based systems)
37-
sudo apt-get install make
38-
make install-deps
39-
```
36+
---
4037

41-
```shell
42-
# See all available commands and their descriptions
43-
make help
44-
```
38+
### Getting Started
39+
40+
To be added.
4541

4642
### Contributing
4743

4844
See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to make a contribution.
4945

46+
### Logo
47+
48+
The logo is from [SVG Repo](https://www.svgrepo.com/svg/469537/zig-zag-left-right-arrow).
49+
5050
### License
5151

52-
This project is licensed under the MIT License ([LICENSE](LICENSE) or https://opensource.org/licenses/MIT)
52+
This project is licensed under the MIT License ([LICENSE](LICENSE)).

benches/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)