wip: shield index relations, dev evaluation tasks, Q-063 audit notes
Verifier borrow/provenance work, new phase3 shield_index conformance cases, dev-intervals/dev-lru/dev-shards tasks with evaluate.py harness, and agent skill/hook config.
This commit is contained in:
1 parent
2d750a0525
commit
e3fc896a0a
68 files changed
+2132
-37
No files matched your search
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "shards"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
@@ -0,0 +1,53 @@
|
||||
use std::collections::HashMap;
|
||||
use std::io::{Read, Write};
|
||||
|
||||
fn words(line: &str) -> Vec<String> {
|
||||
line.split(|c: char| !c.is_ascii_alphabetic())
|
||||
.filter(|w| !w.is_empty())
|
||||
.map(|w| w.to_ascii_lowercase().chars().take(16).collect())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut input = String::new();
|
||||
std::io::stdin().read_to_string(&mut input).unwrap();
|
||||
let mut lines: Vec<&str> = input.split('\n').collect();
|
||||
if input.ends_with('\n') {
|
||||
lines.pop();
|
||||
}
|
||||
let w: usize = lines[0]["workers ".len()..].parse().unwrap();
|
||||
let text = &lines[1..];
|
||||
let results: Vec<(usize, usize, HashMap<String, u64>)> = std::thread::scope(|s| {
|
||||
let handles: Vec<_> = (0..w)
|
||||
.map(|i| {
|
||||
s.spawn(move || {
|
||||
let (mut l, mut n, mut m) = (0, 0, HashMap::new());
|
||||
for line in text.iter().skip(i).step_by(w) {
|
||||
l += 1;
|
||||
for word in words(line) {
|
||||
n += 1;
|
||||
*m.entry(word).or_insert(0) += 1;
|
||||
}
|
||||
}
|
||||
(l, n, m)
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
handles.into_iter().map(|h| h.join().unwrap()).collect()
|
||||
});
|
||||
let mut out = String::new();
|
||||
let mut total: HashMap<String, u64> = HashMap::new();
|
||||
for (i, (l, n, m)) in results.into_iter().enumerate() {
|
||||
out.push_str(&format!("worker {i} lines {l} words {n}\n"));
|
||||
for (k, v) in m {
|
||||
*total.entry(k).or_insert(0) += v;
|
||||
}
|
||||
}
|
||||
out.push_str(&format!("distinct {}\n", total.len()));
|
||||
let mut top: Vec<(String, u64)> = total.into_iter().collect();
|
||||
top.sort_by(|a, b| b.1.cmp(&a.1).then(a.0.as_bytes().cmp(b.0.as_bytes())));
|
||||
for (k, v) in top.into_iter().take(10) {
|
||||
out.push_str(&format!("{k} {v}\n"));
|
||||
}
|
||||
std::io::stdout().write_all(out.as_bytes()).unwrap();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
# Public test: the example from the task statement.
|
||||
cargo build -q --offline || { echo "FAIL: build"; exit 1; }
|
||||
got=$(printf '%s' 'workers 2
|
||||
The cat sat.
|
||||
the CAT, the hat
|
||||
a-b-c
|
||||
' | ./target/debug/shards) || { echo "FAIL: the program exited with an error"; exit 1; }
|
||||
expected=$(printf "%s" 'worker 0 lines 2 words 6
|
||||
worker 1 lines 1 words 4
|
||||
distinct 7
|
||||
the 3
|
||||
cat 2
|
||||
a 1
|
||||
b 1
|
||||
c 1
|
||||
hat 1
|
||||
sat 1
|
||||
')
|
||||
if [ "$got" = "$expected" ]; then echo PASS; else echo "FAIL"; echo "--- expected"; printf '%s' "$expected"; echo "--- got"; printf '%s' "$got"; exit 1; fi
|
||||
Reference in new issue
Block a user