chore: checkpoint before Python removal

This commit is contained in:
2026-03-26 22:33:59 +00:00
parent 683cec9307
commit e568ddf82a
29972 changed files with 11269302 additions and 2 deletions

1
vendor/flurry/tests/jdk/README.md vendored Normal file
View File

@@ -0,0 +1 @@
These tests are ported from https://hg.openjdk.java.net/jdk/jdk13/file/tip/test/jdk/java/util/concurrent/ConcurrentHashMap

View File

@@ -0,0 +1,62 @@
use flurry::HashMap;
use rand::Rng;
use std::sync::Arc;
/// Number of entries for each thread to place in the map.
const NUM_ENTRIES: usize = 128;
/// Number of iterations for each test
const ITERATIONS: usize = 64;
#[derive(Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
struct KeyVal {
_data: usize,
}
impl KeyVal {
pub fn new() -> Self {
let mut rng = rand::thread_rng();
Self { _data: rng.gen() }
}
}
fn insert(map: Arc<HashMap<KeyVal, KeyVal>>, k: KeyVal) {
map.insert(k, k, &map.guard());
}
#[test]
#[cfg_attr(miri, ignore)]
fn test_concurrent_insert<'g>() {
test(insert);
}
fn test<F>(associator: F)
where
F: Fn(Arc<HashMap<KeyVal, KeyVal>>, KeyVal) + Send + Copy + 'static,
{
for _ in 0..ITERATIONS {
test_once(associator);
}
}
fn test_once<F>(associator: F)
where
F: Fn(Arc<HashMap<KeyVal, KeyVal>>, KeyVal) + Send + Copy + 'static,
{
let map = Arc::new(HashMap::new());
let mut threads = Vec::new();
for _ in 0..num_cpus::get().min(8) {
let map = map.clone();
let handle = std::thread::spawn(move || {
for _ in 0..NUM_ENTRIES {
let key = KeyVal::new();
associator(map.clone(), key);
assert!(map.contains_key(&key, &map.guard()));
}
});
threads.push(handle);
}
for t in threads {
t.join().expect("failed to join thread");
}
}

View File

@@ -0,0 +1,52 @@
use flurry::HashMap;
use std::{sync::Arc, thread};
/// Number of entries for each thread to place in the map.
const NUM_ENTRIES: usize = 16;
/// Number of iterations for each test
const ITERATIONS: usize = 256;
/// Number of rounds every thread perfoms per entry.
const ROUNDS: usize = 32;
#[test]
#[cfg_attr(miri, ignore)]
fn test_concurrent_contains_key() {
let map = HashMap::new();
let mut content = [0; NUM_ENTRIES];
{
let guard = map.guard();
for k in 0..NUM_ENTRIES {
map.insert(k, k, &guard);
content[k] = k;
}
}
test(content, Arc::new(map));
}
fn test(content: [usize; NUM_ENTRIES], map: Arc<HashMap<usize, usize>>) {
for _ in 0..ITERATIONS {
test_once(content, map.clone());
}
}
fn test_once(content: [usize; NUM_ENTRIES], map: Arc<HashMap<usize, usize>>) {
let mut threads = Vec::new();
for _ in 0..num_cpus::get().min(8) {
let map = map.clone();
let content = content;
let handle = thread::spawn(move || {
let guard = map.guard();
let map = map.clone();
for i in 0..NUM_ENTRIES * ROUNDS {
let key = content[i % content.len()];
assert!(map.contains_key(&key, &guard));
}
});
threads.push(handle);
}
for t in threads {
t.join().expect("failed to join thread");
}
}

3
vendor/flurry/tests/jdk/main.rs vendored Normal file
View File

@@ -0,0 +1,3 @@
mod concurrent_associate;
mod concurrent_contains;
mod map_check;

201
vendor/flurry/tests/jdk/map_check.rs vendored Normal file
View File

@@ -0,0 +1,201 @@
use flurry::*;
use rand::prelude::*;
use std::hash::Hash;
#[cfg(not(miri))]
const SIZE: usize = 50_000;
#[cfg(miri)]
const SIZE: usize = 12;
// there must be more things absent than present!
#[cfg(not(miri))]
const ABSENT_SIZE: usize = 1 << 17;
#[cfg(miri)]
const ABSENT_SIZE: usize = 1 << 5;
const ABSENT_MASK: usize = ABSENT_SIZE - 1;
fn t1<K, V>(map: &HashMap<K, V>, keys: &[K], expect: usize)
where
K: Sync + Send + Clone + Hash + Ord,
V: Sync + Send,
{
let mut sum = 0;
let iters = 4;
let guard = map.guard();
for _ in 0..iters {
for key in keys {
if map.get(key, &guard).is_some() {
sum += 1;
}
}
}
assert_eq!(sum, expect * iters);
}
fn t2<K>(map: &HashMap<K, usize>, keys: &[K], expect: usize)
where
K: Sync + Send + Copy + Hash + Ord + std::fmt::Display,
{
let mut sum = 0;
let guard = map.guard();
for key in keys {
if map.remove(key, &guard).is_some() {
sum += 1;
}
}
assert_eq!(sum, expect);
}
fn t3<K>(map: &HashMap<K, usize>, keys: &[K], expect: usize)
where
K: Sync + Send + Copy + Hash + Ord,
{
let mut sum = 0;
let guard = map.guard();
for i in 0..keys.len() {
if map.insert(keys[i], 0, &guard).is_none() {
sum += 1;
}
}
assert_eq!(sum, expect);
}
fn t4<K>(map: &HashMap<K, usize>, keys: &[K], expect: usize)
where
K: Sync + Send + Copy + Hash + Ord,
{
let mut sum = 0;
let guard = map.guard();
for i in 0..keys.len() {
if map.contains_key(&keys[i], &guard) {
sum += 1;
}
}
assert_eq!(sum, expect);
}
fn t5<K>(map: &HashMap<K, usize>, keys: &[K], expect: usize)
where
K: Sync + Send + Copy + Hash + Ord,
{
let mut sum = 0;
let guard = map.guard();
let mut i = keys.len() as isize - 2;
while i >= 0 {
if map.remove(&keys[i as usize], &guard).is_some() {
sum += 1;
}
i -= 2;
}
assert_eq!(sum, expect);
}
fn t6<K, V>(map: &HashMap<K, V>, keys1: &[K], keys2: &[K], expect: usize)
where
K: Sync + Send + Clone + Hash + Ord,
V: Sync + Send,
{
let mut sum = 0;
let guard = map.guard();
for i in 0..expect {
if map.get(&keys1[i], &guard).is_some() {
sum += 1;
}
if map.get(&keys2[i & ABSENT_MASK], &guard).is_some() {
sum += 1;
}
}
assert_eq!(sum, expect);
}
fn t7<K>(map: &HashMap<K, usize>, k1: &[K], k2: &[K])
where
K: Sync + Send + Copy + Hash + Ord,
{
let mut sum = 0;
let guard = map.guard();
for i in 0..k1.len() {
if map.contains_key(&k1[i], &guard) {
sum += 1;
}
if map.contains_key(&k2[i], &guard) {
sum += 1;
}
}
assert_eq!(sum, k1.len());
}
fn ittest1<K>(map: &HashMap<K, usize>, expect: usize)
where
K: Sync + Send + Copy + Hash + Eq,
{
let mut sum = 0;
let guard = map.guard();
for _ in map.keys(&guard) {
sum += 1;
}
assert_eq!(sum, expect);
}
fn ittest2<K>(map: &HashMap<K, usize>, expect: usize)
where
K: Sync + Send + Copy + Hash + Eq,
{
let mut sum = 0;
let guard = map.guard();
for _ in map.values(&guard) {
sum += 1;
}
assert_eq!(sum, expect);
}
fn ittest3<K>(map: &HashMap<K, usize>, expect: usize)
where
K: Sync + Send + Copy + Hash + Eq,
{
let mut sum = 0;
let guard = map.guard();
for _ in map.iter(&guard) {
sum += 1;
}
assert_eq!(sum, expect);
}
#[test]
fn everything() {
let mut rng = rand::thread_rng();
let map = HashMap::new();
let mut keys: Vec<_> = (0..ABSENT_SIZE + SIZE).collect();
keys.shuffle(&mut rng);
let absent_keys = &keys[0..ABSENT_SIZE];
let keys = &keys[ABSENT_SIZE..];
// put (absent)
t3(&map, keys, SIZE);
// put (present)
t3(&map, keys, 0);
// contains_key (present & absent)
t7(&map, keys, absent_keys);
// contains_key (present)
t4(&map, keys, SIZE);
// contains_key (absent)
t4(&map, absent_keys, 0);
// get
t6(&map, keys, absent_keys, SIZE);
// get (present)
t1(&map, keys, SIZE);
// get (absent)
t1(&map, absent_keys, 0);
// remove (absent)
t2(&map, absent_keys, 0);
// remove (present)
t5(&map, keys, SIZE / 2);
// put (half present)
t3(&map, keys, SIZE / 2);
// iter, keys, values (present)
ittest1(&map, SIZE);
ittest2(&map, SIZE);
ittest3(&map, SIZE);
}