Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinTimperio committed Feb 25, 2024
0 parents commit fe67443
Show file tree
Hide file tree
Showing 11 changed files with 514 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.history/*
target/*
75 changes: 75 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "rpq"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.4"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Justin Timperio

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.
78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<p align="center">
<img src="./docs/rpq.png">
</p>

<h4 align="center">
RPQ is a my first Rust project is very experimental at this stage. It will be sometime before this project is in a stable place.
</h4>


## Table of Contents
1. [Table of Contents](https://github.com/JustinTimperio/rpq?tab=readme-ov-file#table-of-contents)
2. [Background](https://github.com/JustinTimperio/rpq?tab=readme-ov-file#background)
4. [Benchmarks](https://github.com/JustinTimperio/rpq?tab=readme-ov-file#benchmarks)
3. [Usage](https://github.com/JustinTimperio/rpq?tab=readme-ov-file#usage)
5. [Contributing](https://github.com/JustinTimperio/rpq?tab=readme-ov-file#contributing)
6. [License](https://github.com/JustinTimperio/rpq?tab=readme-ov-file#license)

## Background

#### Other Priority Queues I'm Working On
- [fibheap (Fibonacci Heaps)](https://github.com/JustinTimperio/fibheap)
- [gpq (Go Priority Queue)](https://github.com/JustinTimperio/gpq)
- [rpq (Rust Priority Queue)](https://github.com/JustinTimperio/rpq)

## Benchmarks

## Usage

### Prerequisites

### Import Directly

### API Reference

#### Example Usage


## Contributing
RPQ is actively looking for maintainers so feel free to help out when:

- Reporting a bug
- Discussing the current state of the code
- Submitting a fix
- Proposing new features

### We Develop with Github
We use github to host code, to track issues and feature requests, as well as accept pull requests.

### All Code Changes Happen Through Pull Requests
1. Fork the repo and create your branch from `master`.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes.
5. Make sure your code lints.
6. Issue that pull request!

### Any contributions you make will be under the MIT Software License
In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern.

### Report bugs using Github's [Issues](https://github.com/JustinTimperio/rpq/issues)
We use GitHub issues to track public bugs. Report a bug by opening a new issue; it's that easy!

### Write bug reports with detail, background, and sample code
**Great Bug Reports** tend to have:

- A quick summary and/or background
- Steps to reproduce
- Be specific!
- Give sample code if you can.
- What you expected would happen
- What actually happens
- Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)

### License
By contributing, you agree that your contributions will be licensed under its MIT License.

## License
All code here was originally written by me, Justin Timperio, under an MIT license with the exception of some code directly forked under a BSD license from the Go maintainers.
31 changes: 31 additions & 0 deletions bench/c++/bench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <iostream>
#include <queue>
#include <chrono>

int main() {
std::priority_queue<int> pq;

auto start = std::chrono::high_resolution_clock::now();

// Push 10 million integers onto the priority queue
for (int i = 0; i < 10000000; ++i) {
pq.push(i);
}

auto mid = std::chrono::high_resolution_clock::now();

// Pop 10 million integers from the priority queue
while (!pq.empty()) {
pq.pop();
}

auto end = std::chrono::high_resolution_clock::now();

std::chrono::duration<double> diff_insert = mid - start;
std::chrono::duration<double> diff_remove = end - mid;

std::cout << "Time to insert 10 million integers: " << diff_insert.count() << " s\n";
std::cout << "Time to remove 10 million integers: " << diff_remove.count() << " s\n";

return 0;
}
89 changes: 89 additions & 0 deletions bench/go/bench.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package main

import (
"log"
"math/rand"
_ "net/http/pprof"
"sync"
"sync/atomic"
"time"

"github.com/JustinTimperio/gpq"
)

var (
total int = 10000000
prioritize bool = false
print bool = false
maxBuckets int = 100
sent uint64
received uint64
)

func main() {

queue := gpq.NewGPQ[int](10)
wg := &sync.WaitGroup{}
wg.Add(17)

timer := time.Now()
for i := 0; i < 16; i++ {
go func() {
defer wg.Done()
for i := 0; i < total/16; i++ {
p := rand.Intn(10)
timer := time.Now()
err := queue.EnQueue(
i,
int64(p),
false,
time.Second,
false,
10*time.Second,
)
if err != nil {
log.Fatalln(err)
}
if print {
log.Println("EnQueue", p, time.Since(timer))
}
atomic.AddUint64(&sent, 1)
}
}()
}

var missed int64
var hits int64

go func() {
defer wg.Done()

var lastPriority int64

for total > int(received) {
timer := time.Now()
priority, item, err := queue.DeQueue()
if err != nil {
log.Println(err)
time.Sleep(10 * time.Millisecond)
lastPriority = 0
continue
}
received++
if print {
log.Println("DeQueue", priority, received, item, time.Since(timer))
}

if lastPriority > priority {
missed++
} else {
hits++
}
lastPriority = priority
}
}()

wg.Wait()
log.Println("Sent", sent, "Received", received, "Finished in", time.Since(timer), "Missed", missed, "Hits", hits)

}
5 changes: 5 additions & 0 deletions bench/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module bench

go 1.22.0

require github.com/JustinTimperio/gpq v0.0.0-20240225021737-743a01f55f4a
2 changes: 2 additions & 0 deletions bench/go/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/JustinTimperio/gpq v0.0.0-20240225021737-743a01f55f4a h1:zII+TdeHP3Y1B6XuBvVYKpEJRlgfTHAIh3pEO5ytM88=
github.com/JustinTimperio/gpq v0.0.0-20240225021737-743a01f55f4a/go.mod h1:/XqcgvK8G09Sg2PUOtL+I4LR1BP/UQJvkQubBb/i6/M=
Binary file added docs/rpq.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit fe67443

Please sign in to comment.