Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
BTreeMap/BTreeSet: separate off code supporting tests
  • Loading branch information
ssomers committed Feb 9, 2021
1 parent f4008fe commit 6d2247e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.
6 changes: 2 additions & 4 deletions library/alloc/src/collections/btree/map/tests.rs
@@ -1,4 +1,5 @@
use super::super::{node, DeterministicRng};
use super::super::testing::ord_chaos::{Cyclic3, Governed, Governor};
use super::super::testing::rng::DeterministicRng;
use super::Entry::{Occupied, Vacant};
use super::*;
use crate::boxed::Box;
Expand All @@ -15,9 +16,6 @@ use std::ops::RangeBounds;
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};

mod ord_chaos;
use ord_chaos::{Cyclic3, Governed, Governor};

// Capacity of a tree with a single level,
// i.e., a tree who's root is a leaf node at height 0.
const NODE_CAPACITY: usize = node::CAPACITY;
Expand Down
30 changes: 1 addition & 29 deletions library/alloc/src/collections/btree/mod.rs
Expand Up @@ -20,32 +20,4 @@ trait Recover<Q: ?Sized> {
}

#[cfg(test)]
/// XorShiftRng
struct DeterministicRng {
count: usize,
x: u32,
y: u32,
z: u32,
w: u32,
}

#[cfg(test)]
impl DeterministicRng {
fn new() -> Self {
DeterministicRng { count: 0, x: 0x193a6754, y: 0xa8a7d469, z: 0x97830e05, w: 0x113ba7bb }
}

/// Guarantees that each returned number is unique.
fn next(&mut self) -> u32 {
self.count += 1;
assert!(self.count <= 70029);
let x = self.x;
let t = x ^ (x << 11);
self.x = self.y;
self.y = self.z;
self.z = self.w;
let w_ = self.w;
self.w = w_ ^ (w_ >> 19) ^ (t ^ (t >> 8));
self.w
}
}
mod testing;
2 changes: 1 addition & 1 deletion library/alloc/src/collections/btree/set/tests.rs
@@ -1,4 +1,4 @@
use super::super::DeterministicRng;
use super::super::testing::rng::DeterministicRng;
use super::*;
use crate::vec::Vec;
use std::cmp::Ordering;
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/src/collections/btree/testing/mod.rs
@@ -0,0 +1,2 @@
pub mod ord_chaos;
pub mod rng;
28 changes: 28 additions & 0 deletions library/alloc/src/collections/btree/testing/rng.rs
@@ -0,0 +1,28 @@
/// XorShiftRng
pub struct DeterministicRng {
count: usize,
x: u32,
y: u32,
z: u32,
w: u32,
}

impl DeterministicRng {
pub fn new() -> Self {
DeterministicRng { count: 0, x: 0x193a6754, y: 0xa8a7d469, z: 0x97830e05, w: 0x113ba7bb }
}

/// Guarantees that each returned number is unique.
pub fn next(&mut self) -> u32 {
self.count += 1;
assert!(self.count <= 70029);
let x = self.x;
let t = x ^ (x << 11);
self.x = self.y;
self.y = self.z;
self.z = self.w;
let w_ = self.w;
self.w = w_ ^ (w_ >> 19) ^ (t ^ (t >> 8));
self.w
}
}

0 comments on commit 6d2247e

Please sign in to comment.