Skip to content

Commit ae280d5

Browse files
authored
Merge pull request #37 from orxfun/migrate-to-2024edition
Migrate to 2024edition
2 parents 2e320a6 + 74a7981 commit ae280d5

File tree

17 files changed

+130
-61
lines changed

17 files changed

+130
-61
lines changed

.github/workflows/ci.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Rust
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
toolchain: ["stable"]
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Install toolchain
24+
uses: dtolnay/rust-toolchain@master
25+
with:
26+
toolchain: ${{ matrix.toolchain }}
27+
28+
- name: Install 32bit target
29+
run: rustup target add i686-unknown-linux-musl
30+
- name: Install wasm target
31+
run: rustup target add wasm32v1-none
32+
- name: Install miri
33+
run: rustup component add --toolchain nightly-x86_64-unknown-linux-gnu miri
34+
- name: Install no-std-check
35+
run: cargo install cargo-no-std-check
36+
37+
- name: Build
38+
run: cargo build --verbose --features impl_all
39+
- name: Build-32bit
40+
run: cargo build --verbose --target i686-unknown-linux-musl
41+
- name: Build-wasm
42+
run: cargo build --verbose --no-default-features --target wasm32v1-none
43+
44+
- name: Test
45+
run: cargo test --verbose --features impl_all
46+
- name: Test-32bit
47+
run: cargo test --verbose --target i686-unknown-linux-musl
48+
- name: Check-wasm
49+
run: cargo check --verbose --no-default-features --target wasm32v1-none
50+
51+
- name: Clippy
52+
run: cargo clippy --features impl_all -- -D warnings --verbose
53+
54+
- name: Miri
55+
run: cargo +nightly miri test --verbose
56+
57+
- name: NoStd
58+
run: cargo +nightly no-std-check --no-default-features

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
[package]
22
name = "orx-priority-queue"
33
version = "1.7.0"
4-
edition = "2021"
4+
edition = "2024"
55
authors = ["orxfun <orx.ugur.arikan@gmail.com>"]
6+
readme = "README.md"
67
description = "Priority queue traits and high performance d-ary heap implementations."
78
license = "MIT OR Apache-2.0"
89
repository = "https://github.com/orxfun/orx-priority-queue/"
@@ -13,9 +14,10 @@ categories = ["algorithms", "data-structures", "mathematics", "no-std"]
1314
default = ["std"]
1415
std = []
1516
impl_priority_queue = ["priority-queue"]
17+
impl_all = ["impl_priority_queue"]
1618

1719
[dependencies]
18-
priority-queue = { version = "2.1", optional = true }
20+
priority-queue = { version = "2.3", optional = true }
1921

2022

2123
[[bench]]

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
Priority queue traits and high performance d-ary heap implementations.
88

9+
> **no-std**: This crate supports **no-std**; however, *std* is added as a default feature. Please include with **no-default-features** for no-std use cases: `cargo add orx-priority-queue --no-default-features`.
10+
911
## A. Priority Queue Traits
1012

1113
This crate aims to provide algorithms with the abstraction over priority queues. In order to achieve this, two traits are defined: **`PriorityQueue<N, K>`** and **`PriorityQueueDecKey<N, K>`**. The prior is a simple queue while the latter extends it by providing additional methods to change priorities of the items that already exist in the queue.
@@ -52,6 +54,7 @@ In addition, queue implementations are provided in this crate for the following
5254
* `std::collections::BinaryHeap<(N, K)>` implements only `PriorityQueue<N, K>`,
5355
* `priority_queue:PriorityQueue<N, K>` implements both `PriorityQueue<N, K>` and `PriorityQueueDecKey<N, K>`
5456
* requires `--features impl_priority_queue`
57+
* or `--features impl_all`
5558

5659
This allows to use all the queue implementations interchangeably and pick the one fitting best to the use case.
5760

benches/basic_queue.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use criterion::{
2-
black_box, criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, BenchmarkId,
3-
Criterion,
2+
BenchmarkGroup, BenchmarkId, Criterion, black_box, criterion_group, criterion_main,
3+
measurement::WallTime,
44
};
55
use orx_priority_queue::*;
66
use rand::prelude::*;
@@ -16,12 +16,12 @@ impl TestData {
1616

1717
let mut first_push = Vec::new();
1818
for node in 0..n_first {
19-
first_push.push((node, rng.gen()));
19+
first_push.push((node, rng.random()));
2020
}
2121

2222
let mut second_push = Vec::new();
2323
for node in n_first..(n_first + n_second) {
24-
second_push.push((node, rng.gen()));
24+
second_push.push((node, rng.random()));
2525
}
2626

2727
Self {

benches/deckey_queue.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use criterion::{
2-
black_box, criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, BenchmarkId,
3-
Criterion,
2+
BenchmarkGroup, BenchmarkId, Criterion, black_box, criterion_group, criterion_main,
3+
measurement::WallTime,
44
};
55
use orx_priority_queue::*;
66
use rand::prelude::*;
@@ -17,19 +17,19 @@ impl TestData {
1717

1818
let mut push = Vec::new();
1919
for node in 0..n_push {
20-
push.push((node, rng.gen()));
20+
push.push((node, rng.random()));
2121
}
2222

2323
let mut first_deckey = Vec::new();
2424
for _ in 0..n_deckey1 {
25-
let node = rng.gen_range(0..n_push);
26-
first_deckey.push((node, rng.gen()));
25+
let node = rng.random_range(0..n_push);
26+
first_deckey.push((node, rng.random()));
2727
}
2828

2929
let mut second_deckey = Vec::new();
3030
for _ in 0..n_deckey2 {
31-
let node = rng.gen_range(0..n_push);
32-
second_deckey.push((node, rng.gen()));
31+
let node = rng.random_range(0..n_push);
32+
second_deckey.push((node, rng.random()));
3333
}
3434

3535
Self {

benches/push_then_pop.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use criterion::{
2-
black_box, criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, BenchmarkId,
3-
Criterion,
2+
BenchmarkGroup, BenchmarkId, Criterion, black_box, criterion_group, criterion_main,
3+
measurement::WallTime,
44
};
55
use orx_priority_queue::*;
66
use rand::prelude::*;
@@ -16,12 +16,12 @@ impl TestData {
1616

1717
let mut first_push = Vec::new();
1818
for node in 0..n_first {
19-
first_push.push((node, rng.gen()));
19+
first_push.push((node, rng.random()));
2020
}
2121

2222
let mut second_push_pop = Vec::new();
2323
for node in n_first..(n_first + n_second) {
24-
second_push_pop.push((node, rng.gen()));
24+
second_push_pop.push((node, rng.random()));
2525
}
2626

2727
Self {

tests/daryheap.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
mod priority_queue_tests;
1+
#![cfg(not(miri))]
22

3-
use orx_priority_queue::DaryHeap;
4-
use priority_queue_tests::*;
3+
mod priority_queue_tests;
54

65
#[test]
76
fn test_dary_forall() {
@@ -17,6 +16,9 @@ fn test_dary_forall() {
1716
}
1817

1918
fn test_dary_for<const D: usize>() {
19+
use orx_priority_queue::DaryHeap;
20+
use priority_queue_tests::*;
21+
2022
let new_heap = DaryHeap::<usize, f64, D>::default;
2123

2224
test_len(new_heap());

tests/daryheap_of_indices.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1+
#![cfg(not(miri))]
2+
13
mod priority_queue_deckey_tests;
24
mod priority_queue_tests;
35

4-
use orx_priority_queue::DaryHeapOfIndices;
5-
use priority_queue_deckey_tests::*;
6-
use priority_queue_tests::*;
7-
86
#[test]
97
fn test_dary_forall() {
108
test_dary_for::<2>();
@@ -19,6 +17,10 @@ fn test_dary_forall() {
1917
}
2018

2119
fn test_dary_for<const D: usize>() {
20+
use orx_priority_queue::DaryHeapOfIndices;
21+
use priority_queue_deckey_tests::*;
22+
use priority_queue_tests::*;
23+
2224
let new_heap = || DaryHeapOfIndices::<usize, f64, D>::with_index_bound(125);
2325

2426
let change_key = [

tests/daryheap_with_map.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1+
#![cfg(not(miri))]
2+
13
mod priority_queue_deckey_tests;
24
mod priority_queue_tests;
35

4-
use orx_priority_queue::DaryHeapWithMap;
5-
use priority_queue_deckey_tests::*;
6-
use priority_queue_tests::*;
7-
86
#[test]
97
fn test_dary_forall() {
108
test_dary_for::<2>();
@@ -19,6 +17,10 @@ fn test_dary_forall() {
1917
}
2018

2119
fn test_dary_for<const D: usize>() {
20+
use orx_priority_queue::DaryHeapWithMap;
21+
use priority_queue_deckey_tests::*;
22+
use priority_queue_tests::*;
23+
2224
let new_heap = DaryHeapWithMap::<usize, f64, D>::default;
2325

2426
let change_key = [

tests/priority_queue_deckey_tests/change_key.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ where
1919
pq.clear();
2020
assert!(pq.is_empty());
2121

22-
let mut rng = rand::thread_rng();
22+
let mut rng = rand::rng();
2323
let mut vec = Vec::new();
2424

2525
// push 100
2626
for node in 0..LEN {
27-
let priority = rng.gen();
27+
let priority = rng.random();
2828
pq.push(node, priority);
2929
vec.push((node, priority));
3030
}
3131

3232
// change keys 100 times
3333
for _ in 0..LEN {
34-
let node = rng.gen_range(0..LEN);
34+
let node = rng.random_range(0..LEN);
3535
let old_key = vec[node].1;
3636
assert_eq!(Some(old_key), pq.key_of(&node));
3737

38-
let new_key = rng.gen::<f64>()
38+
let new_key = rng.random::<f64>()
3939
* match change_key {
4040
ChangeKeyMethod::Decrease => old_key,
4141
_ => 1.0,
@@ -47,10 +47,10 @@ where
4747
vec[node] = (node, new_key);
4848
}
4949
ChangeKeyMethod::Update => {
50-
let res_updkey = pq.update_key(&node, new_key);
50+
let res_upd_key = pq.update_key(&node, new_key);
5151
assert_eq!(
5252
new_key < old_key,
53-
matches!(res_updkey, ResUpdateKey::Decreased)
53+
matches!(res_upd_key, ResUpdateKey::Decreased)
5454
);
5555
vec[node] = (node, new_key);
5656
}

0 commit comments

Comments
 (0)