fix: upgrade everywhere to rand 0.9
This commit is contained in:
parent
bb0a08a427
commit
8911e582d8
10 changed files with 65 additions and 97 deletions
45
conformance-tests/generator/Cargo.lock
generated
45
conformance-tests/generator/Cargo.lock
generated
|
|
@ -20,13 +20,14 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.16"
|
version = "0.3.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
|
checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"libc",
|
"libc",
|
||||||
"wasi",
|
"r-efi",
|
||||||
|
"wasip2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -49,7 +50,7 @@ checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "peoplesgrocers-lseq"
|
name = "peoplesgrocers-lseq"
|
||||||
version = "1.0.0"
|
version = "0.99.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rand",
|
"rand",
|
||||||
]
|
]
|
||||||
|
|
@ -82,21 +83,26 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand"
|
name = "r-efi"
|
||||||
version = "0.8.5"
|
version = "5.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.9.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
|
||||||
"rand_chacha",
|
"rand_chacha",
|
||||||
"rand_core",
|
"rand_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_chacha"
|
name = "rand_chacha"
|
||||||
version = "0.3.1"
|
version = "0.9.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ppv-lite86",
|
"ppv-lite86",
|
||||||
"rand_core",
|
"rand_core",
|
||||||
|
|
@ -104,9 +110,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_core"
|
name = "rand_core"
|
||||||
version = "0.6.4"
|
version = "0.9.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"getrandom",
|
"getrandom",
|
||||||
]
|
]
|
||||||
|
|
@ -178,10 +184,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
|
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasi"
|
name = "wasip2"
|
||||||
version = "0.11.1+wasi-snapshot-preview1"
|
version = "1.0.1+wasi-0.2.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7"
|
||||||
|
dependencies = [
|
||||||
|
"wit-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wit-bindgen"
|
||||||
|
version = "0.46.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zerocopy"
|
name = "zerocopy"
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,4 @@ edition = "2024"
|
||||||
peoplesgrocers-lseq = { path = "../../rust" }
|
peoplesgrocers-lseq = { path = "../../rust" }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
rand = "0.8"
|
rand = "0.9"
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,9 @@ impl RecordingRng {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LseqRng for RecordingRng {
|
impl LseqRng for RecordingRng {
|
||||||
fn gen_bool(&mut self, p: f64) -> bool {
|
fn random_bool(&mut self, p: f64) -> bool {
|
||||||
// Use fully qualified syntax to call rand::Rng method
|
// Use fully qualified syntax to call rand::Rng method
|
||||||
let result = Rng::gen_bool(&mut self.inner, p);
|
let result = Rng::random_bool(&mut self.inner, p);
|
||||||
// Record a float that TypeScript's `f < p` would produce the same result
|
// Record a float that TypeScript's `f < p` would produce the same result
|
||||||
// If result is true, we need f < p, so use p/2
|
// If result is true, we need f < p, so use p/2
|
||||||
// If result is false, we need f >= p, so use (1 + p) / 2
|
// If result is false, we need f >= p, so use (1 + p) / 2
|
||||||
|
|
@ -37,9 +37,9 @@ impl LseqRng for RecordingRng {
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_range(&mut self, range: std::ops::Range<u64>) -> u64 {
|
fn random_range(&mut self, range: std::ops::Range<u64>) -> u64 {
|
||||||
// Use fully qualified syntax to call rand::Rng method
|
// Use fully qualified syntax to call rand::Rng method
|
||||||
let result: u64 = Rng::gen_range(&mut self.inner, range.clone());
|
let result: u64 = Rng::random_range(&mut self.inner, range.clone());
|
||||||
// Record a float that TypeScript's `Math.floor(f * range_size)` would produce the same result
|
// Record a float that TypeScript's `Math.floor(f * range_size)` would produce the same result
|
||||||
// For result r in [0, range_size), we need floor(f * range_size) = r
|
// For result r in [0, range_size), we need floor(f * range_size) = r
|
||||||
// So f should be in [r/range_size, (r+1)/range_size)
|
// So f should be in [r/range_size, (r+1)/range_size)
|
||||||
|
|
@ -137,7 +137,7 @@ fn main() {
|
||||||
let idx = if state.is_empty() {
|
let idx = if state.is_empty() {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
Rng::gen_range(&mut position_rng, 0..=state.len())
|
Rng::random_range(&mut position_rng, 0..=state.len())
|
||||||
};
|
};
|
||||||
|
|
||||||
// Derive beforeKey and afterKey from the insertion index
|
// Derive beforeKey and afterKey from the insertion index
|
||||||
|
|
|
||||||
53
research/Cargo.lock
generated
53
research/Cargo.lock
generated
|
|
@ -203,17 +203,6 @@ version = "0.1.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
|
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "getrandom"
|
|
||||||
version = "0.2.16"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if 1.0.1",
|
|
||||||
"libc",
|
|
||||||
"wasi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.3.4"
|
version = "0.3.4"
|
||||||
|
|
@ -439,7 +428,7 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"lseq",
|
"lseq",
|
||||||
"peoplesgrocers-lseq",
|
"peoplesgrocers-lseq",
|
||||||
"rand 0.8.5",
|
"rand 0.9.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -526,37 +515,16 @@ dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rand"
|
|
||||||
version = "0.8.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"rand_chacha 0.3.1",
|
|
||||||
"rand_core 0.6.4",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand"
|
name = "rand"
|
||||||
version = "0.9.2"
|
version = "0.9.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
|
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rand_chacha 0.9.0",
|
"rand_chacha",
|
||||||
"rand_core 0.9.3",
|
"rand_core 0.9.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rand_chacha"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
|
||||||
dependencies = [
|
|
||||||
"ppv-lite86",
|
|
||||||
"rand_core 0.6.4",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_chacha"
|
name = "rand_chacha"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
|
|
@ -582,22 +550,13 @@ version = "0.4.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
|
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rand_core"
|
|
||||||
version = "0.6.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
|
||||||
dependencies = [
|
|
||||||
"getrandom 0.2.16",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_core"
|
name = "rand_core"
|
||||||
version = "0.9.3"
|
version = "0.9.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"getrandom 0.3.4",
|
"getrandom",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -795,12 +754,6 @@ dependencies = [
|
||||||
"winapi-util",
|
"winapi-util",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wasi"
|
|
||||||
version = "0.11.1+wasi-snapshot-preview1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasip2"
|
name = "wasip2"
|
||||||
version = "1.0.1+wasi-0.2.4"
|
version = "1.0.1+wasi-0.2.4"
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
peoplesgrocers-lseq = { path = "../rust" }
|
peoplesgrocers-lseq = { path = "../rust" }
|
||||||
rand = "0.8"
|
rand = "0.9"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
env_logger = "0.10"
|
env_logger = "0.10"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ fn benchmark_random_insertions(c: &mut Criterion) {
|
||||||
let key = lseq.allocate(None, None).unwrap();
|
let key = lseq.allocate(None, None).unwrap();
|
||||||
keys.push(key);
|
keys.push(key);
|
||||||
} else {
|
} else {
|
||||||
let idx = rng.gen_range(0..keys.len());
|
let idx = rng.random_range(0..keys.len());
|
||||||
let before = if idx == 0 { None } else { Some(&keys[idx - 1]) };
|
let before = if idx == 0 { None } else { Some(&keys[idx - 1]) };
|
||||||
let after = if idx == keys.len() { None } else { Some(&keys[idx]) };
|
let after = if idx == keys.len() { None } else { Some(&keys[idx]) };
|
||||||
|
|
||||||
|
|
@ -147,7 +147,7 @@ fn benchmark_random_insertions(c: &mut Criterion) {
|
||||||
let key = lseq.alloc(None, None);
|
let key = lseq.alloc(None, None);
|
||||||
keys.push(key);
|
keys.push(key);
|
||||||
} else {
|
} else {
|
||||||
let idx = rng.gen_range(0..keys.len());
|
let idx = rng.random_range(0..keys.len());
|
||||||
let before = if idx == 0 { None } else { Some(&keys[idx - 1]) };
|
let before = if idx == 0 { None } else { Some(&keys[idx - 1]) };
|
||||||
let after = if idx == keys.len() { None } else { Some(&keys[idx]) };
|
let after = if idx == keys.len() { None } else { Some(&keys[idx]) };
|
||||||
|
|
||||||
|
|
@ -176,7 +176,7 @@ fn benchmark_random_insertions(c: &mut Criterion) {
|
||||||
let key = lseq.allocate(None, None).unwrap();
|
let key = lseq.allocate(None, None).unwrap();
|
||||||
keys.push(key);
|
keys.push(key);
|
||||||
} else {
|
} else {
|
||||||
let idx = rng.gen_range(0..keys.len());
|
let idx = rng.random_range(0..keys.len());
|
||||||
let before = if idx == 0 { None } else { Some(&keys[idx - 1]) };
|
let before = if idx == 0 { None } else { Some(&keys[idx - 1]) };
|
||||||
let after = if idx == keys.len() { None } else { Some(&keys[idx]) };
|
let after = if idx == keys.len() { None } else { Some(&keys[idx]) };
|
||||||
|
|
||||||
|
|
@ -206,7 +206,7 @@ fn benchmark_random_insertions(c: &mut Criterion) {
|
||||||
let key = lseq.allocate(None, None);
|
let key = lseq.allocate(None, None);
|
||||||
keys.push(key);
|
keys.push(key);
|
||||||
} else {
|
} else {
|
||||||
let idx = rng.gen_range(0..keys.len());
|
let idx = rng.random_range(0..keys.len());
|
||||||
let before = if idx == 0 { None } else { Some(&keys[idx - 1]) };
|
let before = if idx == 0 { None } else { Some(&keys[idx - 1]) };
|
||||||
let after = if idx == keys.len() { None } else { Some(&keys[idx]) };
|
let after = if idx == keys.len() { None } else { Some(&keys[idx]) };
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,7 @@ impl<R: Rng + std::fmt::Debug> LSEQBase64<R> {
|
||||||
trace!("Current carry_flag: {}", borrow_flag);
|
trace!("Current carry_flag: {}", borrow_flag);
|
||||||
|
|
||||||
if self.strategies.len() <= depth {
|
if self.strategies.len() <= depth {
|
||||||
let new_strategy = self.rng.gen_bool(0.5);
|
let new_strategy = self.rng.random_bool(0.5);
|
||||||
trace!("BRANCH: Generating new strategy for depth {}: {} (+ strategy: {})",
|
trace!("BRANCH: Generating new strategy for depth {}: {} (+ strategy: {})",
|
||||||
depth, new_strategy, new_strategy);
|
depth, new_strategy, new_strategy);
|
||||||
self.strategies.push(new_strategy);
|
self.strategies.push(new_strategy);
|
||||||
|
|
@ -245,7 +245,7 @@ impl<R: Rng + std::fmt::Debug> LSEQBase64<R> {
|
||||||
let step = std::cmp::min(BOUNDARY, interval);
|
let step = std::cmp::min(BOUNDARY, interval);
|
||||||
|
|
||||||
let allocated_value = if self.strategies[depth] {
|
let allocated_value = if self.strategies[depth] {
|
||||||
let delta = self.rng.gen_range(1..=step);
|
let delta = self.rng.random_range(1..=step);
|
||||||
trace!("Space allocation: interval={}, step={}, delta={}", interval, step, delta);
|
trace!("Space allocation: interval={}, step={}, delta={}", interval, step, delta);
|
||||||
let val = p_val + delta;
|
let val = p_val + delta;
|
||||||
trace!("BRANCH: Using + strategy, allocated_value = p_val + delta = {} + {} = {}",
|
trace!("BRANCH: Using + strategy, allocated_value = p_val + delta = {} + {} = {}",
|
||||||
|
|
@ -253,10 +253,10 @@ impl<R: Rng + std::fmt::Debug> LSEQBase64<R> {
|
||||||
val
|
val
|
||||||
} else {
|
} else {
|
||||||
let delta = if borrow_flag {
|
let delta = if borrow_flag {
|
||||||
//self.rng.gen_range(0..step)
|
//self.rng.random_range(0..step)
|
||||||
self.rng.gen_range(1..=step)
|
self.rng.random_range(1..=step)
|
||||||
} else {
|
} else {
|
||||||
self.rng.gen_range(1..=step)
|
self.rng.random_range(1..=step)
|
||||||
};
|
};
|
||||||
trace!("Space allocation: interval={}, step={}, delta={}", interval, step, delta);
|
trace!("Space allocation: interval={}, step={}, delta={}", interval, step, delta);
|
||||||
let val = q_val - delta;
|
let val = q_val - delta;
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ impl<R: Rng> ReferenceLSEQ<R> {
|
||||||
trace!("Current carry_flag: {}", borrow_flag);
|
trace!("Current carry_flag: {}", borrow_flag);
|
||||||
|
|
||||||
if self.strategies.len() <= depth {
|
if self.strategies.len() <= depth {
|
||||||
let new_strategy = self.rng.gen_bool(0.5);
|
let new_strategy = self.rng.random_bool(0.5);
|
||||||
trace!("BRANCH: Generating new strategy for depth {}: {} (+ strategy: {})",
|
trace!("BRANCH: Generating new strategy for depth {}: {} (+ strategy: {})",
|
||||||
depth, new_strategy, new_strategy);
|
depth, new_strategy, new_strategy);
|
||||||
self.strategies.push(new_strategy);
|
self.strategies.push(new_strategy);
|
||||||
|
|
@ -241,7 +241,7 @@ impl<R: Rng> ReferenceLSEQ<R> {
|
||||||
let step = std::cmp::min(BOUNDARY, interval);
|
let step = std::cmp::min(BOUNDARY, interval);
|
||||||
|
|
||||||
let allocated_value = if self.strategies[depth] {
|
let allocated_value = if self.strategies[depth] {
|
||||||
let delta = self.rng.gen_range(1..=step);
|
let delta = self.rng.random_range(1..=step);
|
||||||
trace!("Space allocation: interval={}, step={}, delta={}", interval, step, delta);
|
trace!("Space allocation: interval={}, step={}, delta={}", interval, step, delta);
|
||||||
let val = p_val + delta;
|
let val = p_val + delta;
|
||||||
trace!("BRANCH: Using + strategy, allocated_value = p_val + delta = {} + {} = {}",
|
trace!("BRANCH: Using + strategy, allocated_value = p_val + delta = {} + {} = {}",
|
||||||
|
|
@ -249,9 +249,9 @@ impl<R: Rng> ReferenceLSEQ<R> {
|
||||||
val
|
val
|
||||||
} else {
|
} else {
|
||||||
let delta = if borrow_flag {
|
let delta = if borrow_flag {
|
||||||
self.rng.gen_range(1..=step)
|
self.rng.random_range(1..=step)
|
||||||
} else {
|
} else {
|
||||||
self.rng.gen_range(1..=step)
|
self.rng.random_range(1..=step)
|
||||||
};
|
};
|
||||||
trace!("Space allocation: interval={}, step={}, delta={}", interval, step, delta);
|
trace!("Space allocation: interval={}, step={}, delta={}", interval, step, delta);
|
||||||
let val = q_val - delta;
|
let val = q_val - delta;
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ fn generate_insertion_positions(count: usize, rng: &mut StdRng) -> Vec<usize> {
|
||||||
positions.push(0); // First element always goes at position 0
|
positions.push(0); // First element always goes at position 0
|
||||||
} else {
|
} else {
|
||||||
// Insert after position 0 to i-1 (current list has i elements)
|
// Insert after position 0 to i-1 (current list has i elements)
|
||||||
positions.push(rng.gen_range(0..i));
|
positions.push(rng.random_range(0..i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,17 +14,17 @@ const ALPHABET: &[u8] = b"-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnop
|
||||||
/// This allows custom implementations (e.g., recording wrappers) without
|
/// This allows custom implementations (e.g., recording wrappers) without
|
||||||
/// implementing the full Rng trait.
|
/// implementing the full Rng trait.
|
||||||
pub trait LseqRng {
|
pub trait LseqRng {
|
||||||
fn gen_bool(&mut self, p: f64) -> bool;
|
fn random_bool(&mut self, p: f64) -> bool;
|
||||||
fn gen_range(&mut self, range: std::ops::Range<u64>) -> u64;
|
fn random_range(&mut self, range: std::ops::Range<u64>) -> u64;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Blanket implementation for anything that implements rand::Rng
|
/// Blanket implementation for anything that implements rand::Rng
|
||||||
impl<R: Rng> LseqRng for R {
|
impl<R: Rng> LseqRng for R {
|
||||||
fn gen_bool(&mut self, p: f64) -> bool {
|
fn random_bool(&mut self, p: f64) -> bool {
|
||||||
Rng::gen_bool(self, p)
|
Rng::random_bool(self, p)
|
||||||
}
|
}
|
||||||
fn gen_range(&mut self, range: std::ops::Range<u64>) -> u64 {
|
fn random_range(&mut self, range: std::ops::Range<u64>) -> u64 {
|
||||||
Rng::gen_range(self, range)
|
Rng::random_range(self, range)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -154,7 +154,7 @@ pub struct LSEQ<R: LseqRng> {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
impl<R: LseqRng> LSEQ<R> {
|
impl<R: LseqRng> LSEQ<R> {
|
||||||
pub fn new(mut rng: R) -> Self {
|
pub fn new(mut rng: R) -> Self {
|
||||||
let strategies = vec![rng.gen_bool(0.5)];
|
let strategies = vec![rng.random_bool(0.5)];
|
||||||
LSEQ { strategies, rng }
|
LSEQ { strategies, rng }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -233,7 +233,7 @@ impl<R: LseqRng> LSEQ<R> {
|
||||||
|
|
||||||
if min_alloc <= max_alloc {
|
if min_alloc <= max_alloc {
|
||||||
let range = max_alloc - min_alloc + 1;
|
let range = max_alloc - min_alloc + 1;
|
||||||
let offset = self.rng.gen_range(0..range);
|
let offset = self.rng.random_range(0..range);
|
||||||
let new_value = if self.strategies[depth] {
|
let new_value = if self.strategies[depth] {
|
||||||
min_alloc + offset
|
min_alloc + offset
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -248,7 +248,7 @@ impl<R: LseqRng> LSEQ<R> {
|
||||||
|
|
||||||
depth += 1;
|
depth += 1;
|
||||||
if depth >= self.strategies.len() {
|
if depth >= self.strategies.len() {
|
||||||
self.strategies.push(self.rng.gen_bool(0.5));
|
self.strategies.push(self.rng.random_bool(0.5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue