Skip to content

Commit 15393a3

Browse files
committed
The base commit
1 parent f92a92c commit 15393a3

33 files changed

+1089
-209
lines changed

.editorconfig

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
1-
# Top-most EditorConfig file
21
root = true
32

4-
# Global settings (applicable to all files unless overridden)
53
[*]
6-
charset = utf-8 # Default character encoding
7-
end_of_line = lf # Use LF for line endings (Unix-style)
8-
indent_style = space # Use spaces for indentation
9-
indent_size = 4 # Default indentation size
10-
insert_final_newline = true # Make sure files end with a newline
11-
trim_trailing_whitespace = true # Remove trailing whitespace
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_style = space
7+
indent_size = 4
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
1210

13-
# Zig files
1411
[*.zig]
1512
max_line_length = 100
1613

17-
# Markdown files
1814
[*.md]
1915
max_line_length = 120
20-
trim_trailing_whitespace = false # Don't remove trailing whitespace in Markdown files
16+
trim_trailing_whitespace = false
2117

22-
# Bash scripts
2318
[*.sh]
2419
indent_size = 2
2520

26-
# YAML files
2721
[*.{yml,yaml}]
2822
indent_size = 2
2923

30-
# Python files
3124
[*.py]
3225
max_line_length = 100

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Install Zig
2121
uses: goto-bus-stop/setup-zig@v2
2222
with:
23-
version: '0.14.1'
23+
version: '0.15.1'
2424

2525
- name: Install System Dependencies
2626
run: |

.github/workflows/lints.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Install Zig
2828
uses: goto-bus-stop/setup-zig@v2
2929
with:
30-
version: '0.14.1'
30+
version: '0.15.1'
3131

3232
- name: Install Dependencies
3333
run: |

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Install Zig
2828
uses: goto-bus-stop/setup-zig@v2
2929
with:
30-
version: '0.14.1'
30+
version: '0.15.1'
3131

3232
- name: Install Dependencies
3333
run: |

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ repos:
2222
- repo: local
2323
hooks:
2424
- id: format
25-
name: Format the code
25+
name: Format Code
2626
entry: make format
2727
language: system
2828
pass_filenames: false
2929
stages: [ pre-commit ]
3030

3131
- id: lint
32-
name: Check code style
32+
name: Check Code Style
3333
entry: make lint
3434
language: system
3535
pass_filenames: false
3636
stages: [ pre-commit ]
3737

3838
- id: test
39-
name: Run the tests
39+
name: Run Test
4040
entry: make test
4141
language: system
4242
pass_filenames: false

CODE_OF_CONDUCT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Code of Conduct
1+
## Code of Conduct
22

33
We adhere to the [Contributor Covenant](https://www.contributor-covenant.org/version/2/1/code_of_conduct/) version 2.1.

CONTRIBUTING.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
# Contribution Guidelines
1+
## Contribution Guidelines
22

33
Thank you for considering contributing to this project!
44
Contributions are always welcome and appreciated.
55

6-
## How to Contribute
6+
### How to Contribute
77

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

11-
### Reporting Bugs
11+
#### Reporting Bugs
1212

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

16-
### Suggesting Features
16+
#### Suggesting Features
1717

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

21-
## Submitting Pull Requests
21+
### Submitting Pull Requests
2222

2323
- Ensure all tests pass before submitting a pull request.
2424
- Write a clear description of the changes you made and the reasons behind them.
2525

2626
> [!IMPORTANT]
2727
> It's assumed that by submitting a pull request, you agree to license your contributions under the project's license.
2828
29-
## Development Workflow
29+
### Development Workflow
3030

31-
### Prerequisites
31+
#### Prerequisites
3232

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

@@ -39,22 +39,22 @@ sudo apt-get install make
3939

4040
- Use the `make install-deps` command to install the development dependencies.
4141

42-
### Code Style
42+
#### Code Style
4343

4444
- Use the `make format` command to format the code.
4545

46-
### Running Tests
46+
#### Running Tests
4747

4848
- Use the `make test` command to run the tests.
4949

50-
### Running Linters
50+
#### Running Linters
5151

5252
- Use the `make lint` command to run the linters.
5353

54-
### See Available Commands
54+
#### See Available Commands
5555

5656
- Run `make help` to see all available commands for managing different tasks.
5757

58-
## Code of Conduct
58+
### Code of Conduct
5959

60-
We adhere to the [Contributor Covenant](https://www.contributor-covenant.org/version/2/1/code_of_conduct/) version 2.1.
60+
We adhere to the project's [Code of Conduct](CODE_OF_CONDUCT.md).

Makefile

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# ################################################################################
22
# # Configuration and Variables
33
# ################################################################################
4-
ZIG ?= $(shell which zig || echo ~/.local/share/zig/0.14.1/zig)
4+
ZIG ?= $(shell which zig || echo ~/.local/share/zig/0.15.1/zig)
55
BUILD_TYPE ?= Debug
66
BUILD_OPTS = -Doptimize=$(BUILD_TYPE)
77
JOBS ?= $(shell nproc || echo 2)
88
SRC_DIR := src
99
EXAMPLES_DIR := examples
10+
BENCHMARKS_DIR:= benches
1011
BUILD_DIR := zig-out
1112
CACHE_DIR := .zig-cache
1213
BINARY_NAME := example
@@ -18,14 +19,18 @@ JUNK_FILES := *.o *.obj *.dSYM *.dll *.so *.dylib *.a *.lib *.pdb temp/
1819
EXAMPLES := $(patsubst %.zig,%,$(notdir $(wildcard examples/*.zig)))
1920
EXAMPLE ?= all
2021

22+
# Automatically find all benchmark names
23+
BENCHMARKS := $(patsubst %.zig,%,$(notdir $(wildcard benches/*.zig)))
24+
BENCHMARK ?= all
25+
2126
SHELL := /usr/bin/env bash
2227
.SHELLFLAGS := -eu -o pipefail -c
2328

2429
################################################################################
2530
# Targets
2631
################################################################################
2732

28-
.PHONY: all help build rebuild run test release clean lint format docs serve-docs install-deps setup-hooks test-hooks
33+
.PHONY: all help build rebuild run bench test release clean lint format docs serve-docs install-deps setup-hooks test-hooks
2934
.DEFAULT_GOAL := help
3035

3136
help: ## Show the help messages for all targets
@@ -43,7 +48,7 @@ build: ## Build project (e.g. 'make build BUILD_TYPE=ReleaseSmall' or 'make buil
4348

4449
rebuild: clean build ## clean and build
4550

46-
run: ## Run an example (e.g. 'make run EXAMPLE=sorted_set' or 'make run' to run all examples)
51+
run: ## Run an example (like 'make run EXAMPLE=e1_btree_map' or 'make run' to run all examples)
4752
@if [ "$(EXAMPLE)" = "all" ]; then \
4853
echo "--> Running all examples..."; \
4954
for ex in $(EXAMPLES); do \
@@ -56,6 +61,19 @@ run: ## Run an example (e.g. 'make run EXAMPLE=sorted_set' or 'make run' to run
5661
$(ZIG) build run-$(EXAMPLE) $(BUILD_OPTS); \
5762
fi
5863

64+
bench: ## Run a benchmark (like 'make bench BENCHMARK=b1_btree_map' or 'make run' to run all benchmarks)
65+
@if [ "$(BENCHMARK)" = "all" ]; then \
66+
echo "--> Running all benchmarks..."; \
67+
for ex in $(BENCHMARKS); do \
68+
echo ""; \
69+
echo "--> Running '$$ex'"; \
70+
$(ZIG) build bench-$$ex $(BUILD_OPTS); \
71+
done; \
72+
else \
73+
echo "--> Running benchmark: $(BENCHMARK)"; \
74+
$(ZIG) build bench-$(BENCHMARK) $(BUILD_OPTS); \
75+
fi
76+
5977
test: ## Run tests
6078
@echo "Running tests..."
6179
@$(ZIG) build test $(BUILD_OPTS) -j$(JOBS) $(TEST_FLAGS)

README.md

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,50 @@
66

77
<h2>Ordered</h2>
88

9-
[![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)
10-
[![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)
11-
[![Zig Version](https://img.shields.io/badge/Zig-0.14.1-orange?logo=zig&labelColor=282c34)](https://ziglang.org/download/)
12-
[![Docs](https://img.shields.io/github/v/tag/habedi/ordered?label=docs&color=blue&style=flat&labelColor=282c34&logo=read-the-docs)](https://habedi.github.io/ordered/)
13-
[![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)
14-
[![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)
9+
[![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)
10+
[![CodeFactor](https://img.shields.io/codefactor/grade/github/CogitatorTech/ordered?label=code%20quality&style=flat&labelColor=282c34&logo=codefactor)](https://www.codefactor.io/repository/github/CogitatorTech/ordered)
11+
[![Zig Version](https://img.shields.io/badge/Zig-0.15.1-orange?logo=zig&labelColor=282c34)](https://ziglang.org/download/)
12+
[![Docs](https://img.shields.io/badge/docs-view-blue?style=flat&labelColor=282c34&logo=read-the-docs)](https://CogitatorTech.github.io/ordered/)
13+
[![Examples](https://img.shields.io/badge/examples-view-green?style=flat&labelColor=282c34&logo=zig)](https://github.com/CogitatorTech/ordered/tree/main/examples)
14+
[![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)
15+
[![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)
1516

16-
A Zig library of common data structures that keep data in order
17+
A collection of data structures that keep data in order
1718

1819
</div>
1920

2021
---
2122

22-
Ordered Zig library includes implementations of popular data structures including B-tree, skip list, trie, and
23-
red-black tree.
23+
Ordered library includes fast and efficient implementations of popular data structures including
24+
B-tree, skip list, trie, and red-black tree for Zig programming language.
2425

25-
### Features
26+
### Supported Data Structures
2627

27-
- Implementations for common data structures that maintain the order of keys:
28-
- [`BTreeMap`](src/btree_map.zig): A balanced tree map that maintains order of keys.
29-
- [`OrderedSet`](src/sorted_set.zig): A set with ordered elements.
30-
- [`SkipList`](src/skip_list.zig): A probabilistic data structure that allows fast search, insertion, and deletion.
31-
- [`Trie`](src/trie.zig): A prefix tree for fast retrieval of keys with common prefixes.
32-
- [`RedBlackTree`](src/red_black_tree.zig): A self-balancing binary search tree that maintains order of keys.
28+
Currently supported data structures include:
29+
30+
- [B-tree](src/ordered/btree_map.zig): a balanced n-array tree that maintains the order of keys.
31+
- [Sorted set](src/ordered/sorted_set.zig): a set with ordered elements based on keys.
32+
- [Skip list](src/ordered/skip_list.zig): a probabilistic data structure that maintains sorted order using multiple linked lists.
33+
- [Trie](src/ordered/trie.zig): a prefix tree that supports efficient retrieval of keys with common prefixes.
34+
- [Red-black tree](src/ordered/red_black_tree.zig): A self-balancing binary search tree that maintains the order of keys
35+
- [Cartesian tree](src/ordered/cartesian_tree.zig): A binary tree that maintains both a binary search tree property on keys and a heap property on priorities.
36+
37+
| # | Data Structure | Build Complexity | Memory Complexity | Search Complexity |
38+
|---|----------------|------------------|-------------------|----------------------|
39+
| 1 | B-tree | $O(\log n)$ | $O(n)$ | $O(\log n)$ |
40+
| 2 | Cartesian tree | $O(\log n)$\* | $O(n)$ | $O(\log n)$\* |
41+
| 3 | Red-black tree | $O(\log n)$ | $O(n)$ | $O(\log n)$ |
42+
| 4 | Skip list | $O(\log n)$\* | $O(n)$ | $O(\log n)$\* |
43+
| 5 | Sorted set | $O(n)$ | $O(n)$ | $O(\log n)$ |
44+
| 6 | Trie | $O(m)$ | $O(n \cdot m)$ | $O(m)$ |
45+
46+
- $n$: number of stored elements
47+
- $m$: maximum length of a key
48+
- \*: average case complexity
3349

3450
> [!IMPORTANT]
35-
> Zig-DbC is in early development, so bugs and breaking API changes are expected.
36-
> Please use the [issues page](https://github.com/habedi/zig-dbc/issues) to report bugs or request features.
51+
> Ordered is in early development, so bugs and breaking API changes are expected.
52+
> Please use the [issues page](https://github.com/CogitatorTech/ordered/issues) to report bugs or request features.
3753
3854
---
3955

@@ -45,15 +61,15 @@ To be added.
4561

4662
### Documentation
4763

48-
You can find the API documentation for the latest release of Ordered [here](https://habedi.github.io/ordered/).
64+
You can find the API documentation for the latest release of Ordered [here](https://CogitatorTech.github.io/ordered/).
4965

5066
Alternatively, you can use the `make docs` command to generate the documentation for the current version of Ordered.
5167
This will generate HTML documentation in the `docs/api` directory, which you can serve locally with `make serve-docs`
5268
and view in a web browser.
5369

5470
### Examples
5571

56-
Check out the [examples](examples/) directory for example usages of Ordered.
72+
Check out the [examples](examples) directory for example usages of Ordered.
5773

5874
---
5975

@@ -67,4 +83,4 @@ Ordered is licensed under the MIT License (see [LICENSE](LICENSE)).
6783

6884
### Acknowledgements
6985

70-
* The logo is from [SVG Repo](https://www.svgrepo.com/svg/469537/zig-zag-left-right-arrow).
86+
* The logo is from [SVG Repo](https://www.svgrepo.com/svg/469537/zig-zag-left-right-arrow) with some modifications.

benches/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)