BTreeMap/BTreeSet: separate off code supporting tests
This commit is contained in:
parent
f4008fe949
commit
6d2247eac2
|
@ -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;
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use super::super::DeterministicRng;
|
||||
use super::super::testing::rng::DeterministicRng;
|
||||
use super::*;
|
||||
use crate::vec::Vec;
|
||||
use std::cmp::Ordering;
|
||||
|
|
2
library/alloc/src/collections/btree/testing/mod.rs
Normal file
2
library/alloc/src/collections/btree/testing/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
pub mod ord_chaos;
|
||||
pub mod rng;
|
28
library/alloc/src/collections/btree/testing/rng.rs
Normal file
28
library/alloc/src/collections/btree/testing/rng.rs
Normal file
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue