Skip to content

Commit 82c36a2

Browse files
committed
add more special examples
1 parent db489d9 commit 82c36a2

File tree

6 files changed

+102
-8
lines changed

6 files changed

+102
-8
lines changed

special/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ edition = "2021"
99
async-lock = "2.5.0"
1010
async-oneshot = "0.5.0"
1111
atomic_float = "0.1.0"
12+
awaitgroup = "0.6.0"
1213
catty = "0.1.5"
1314
concurrent-queue = "1.2.4"
1415
dashmap = "5.4.0"
@@ -18,11 +19,13 @@ flurry = "0.4.0"
1819
oneshot = "0.1.5"
1920
portable-atomic = { version = "0.3", features=["float"] }
2021
process_lock = "0.1.0"
22+
scc = "0.11.1"
2123
sharded-slab = "0.1.4"
2224
simple-mutex = "1.1.5"
2325
slab = "0.4.7"
2426
smol = "1.2.5"
2527
triggered = "0.1.2"
28+
triple_buffer = "6.2.0"
2629
try-lock = "0.2.3"
2730
waitgroup = "0.1.2"
2831
wg = "0.3.1"

special/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
pub mod oslock;
2-
pub mod oneshots;
3-
pub mod map;
4-
pub mod primitive;
5-
pub mod notify;
6-
pub mod queue;
1+
mod oslock;
2+
mod oneshots;
3+
mod map;
4+
mod primitive;
5+
mod notify;
6+
mod queue;
7+
mod scc_examples;
78

89
pub use oslock::*;
910
pub use oneshots::*;
1011
pub use map::*;
1112
pub use primitive::*;
1213
pub use notify::*;
13-
pub use queue::*;
14+
pub use queue::*;
15+
pub use scc_examples::*;

special/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ fn main() {
3939

4040
waitgroup_example();
4141
wg_example();
42+
awaitgroup_example();
43+
44+
scc_hashmap();
45+
scc_hashindex();
46+
scc_treeindex();
47+
scc_hashset();
48+
scc_queue();
4249

4350
}
4451

special/src/primitive/waitgroup_examples.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,25 @@ pub fn wg_example() {
4141
wg.wait();
4242
assert_eq!(ctr.load(Ordering::Relaxed), 5);
4343
}
44+
45+
pub fn awaitgroup_example() {
46+
use awaitgroup::WaitGroup;
47+
48+
smol::block_on(async {
49+
let mut wg = WaitGroup::new();
50+
for _ in 0..5 {
51+
// Create a new worker.
52+
let worker = wg.worker();
53+
54+
let _ = smol::spawn(async {
55+
// Do some work...
56+
57+
// This task is done all of its work.
58+
worker.done();
59+
});
60+
}
61+
62+
// Block until all other tasks have finished their work.
63+
wg.wait().await;
64+
});
65+
}

special/src/scc.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

special/src/scc_examples.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use scc::*;
2+
use std::collections::hash_map::RandomState;
3+
4+
pub fn scc_hashmap() {
5+
let hashmap: HashMap<usize, usize, RandomState> = HashMap::with_capacity(1000);
6+
assert_eq!(hashmap.capacity(), 1024);
7+
8+
let ticket = hashmap.reserve(10000);
9+
assert!(ticket.is_some());
10+
assert_eq!(hashmap.capacity(), 16384);
11+
for i in 0..16 {
12+
assert!(hashmap.insert(i, i).is_ok());
13+
}
14+
drop(ticket);
15+
16+
assert_eq!(hashmap.capacity(), 1024);
17+
}
18+
19+
pub fn scc_hashindex() {
20+
let hashindex: HashIndex<u64, u32> = HashIndex::default();
21+
22+
assert!(!hashindex.remove(&1));
23+
assert!(hashindex.insert(1, 0).is_ok());
24+
assert!(hashindex.remove(&1));
25+
}
26+
27+
pub fn scc_treeindex() {
28+
let treeindex: TreeIndex<u64, u32> = TreeIndex::new();
29+
30+
assert!(treeindex.insert(1, 10).is_ok());
31+
assert_eq!(treeindex.insert(1, 11).err().unwrap(), (1, 11));
32+
assert_eq!(treeindex.read(&1, |_k, v| *v).unwrap(), 10);
33+
}
34+
35+
pub fn scc_hashset() {
36+
let hashset: HashSet<usize, RandomState> = HashSet::with_capacity(1000);
37+
assert_eq!(hashset.capacity(), 1024);
38+
39+
let ticket = hashset.reserve(10000);
40+
assert!(ticket.is_some());
41+
assert_eq!(hashset.capacity(), 16384);
42+
for i in 0..16 {
43+
assert!(hashset.insert(i).is_ok());
44+
}
45+
drop(ticket);
46+
47+
assert_eq!(hashset.capacity(), 1024);
48+
}
49+
50+
pub fn scc_queue() {
51+
let queue: Queue<usize> = Queue::default();
52+
53+
queue.push(37);
54+
queue.push(3);
55+
queue.push(1);
56+
57+
assert_eq!(queue.pop().map(|e| **e), Some(37));
58+
assert_eq!(queue.pop().map(|e| **e), Some(3));
59+
assert_eq!(queue.pop().map(|e| **e), Some(1));
60+
assert!(queue.pop().is_none());
61+
}

0 commit comments

Comments
 (0)