他真的很抽象你知道吧(
This commit is contained in:
parent
ed9e2736d6
commit
4969c8cf6b
@ -90,6 +90,7 @@ fn cacl(config: Command, id: u64, outfile: &PathBuf) {
|
|||||||
// 写入 (写到最后一行)
|
// 写入 (写到最后一行)
|
||||||
match std::fs::OpenOptions::new()
|
match std::fs::OpenOptions::new()
|
||||||
.append(true)
|
.append(true)
|
||||||
|
.create(true)
|
||||||
.open(outfile)
|
.open(outfile)
|
||||||
.and_then(|mut file| file.write(format!("{}\n", full_name).as_bytes()))
|
.and_then(|mut file| file.write(format!("{}\n", full_name).as_bytes()))
|
||||||
{
|
{
|
||||||
@ -159,10 +160,6 @@ fn main() {
|
|||||||
if let Err(e) = std::fs::create_dir_all(&out_path.parent().unwrap()) {
|
if let Err(e) = std::fs::create_dir_all(&out_path.parent().unwrap()) {
|
||||||
warn!("创建文件夹失败: {}", e);
|
warn!("创建文件夹失败: {}", e);
|
||||||
}
|
}
|
||||||
// 再创建文件
|
|
||||||
if let Err(e) = std::fs::File::create(&out_path) {
|
|
||||||
warn!("创建文件失败: {}", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
info!("开始: {} 结尾: {}", cli_arg.start, cli_arg.end);
|
info!("开始: {} 结尾: {}", cli_arg.start, cli_arg.end);
|
||||||
info!("线程数: {}", cli_arg.thread_count);
|
info!("线程数: {}", cli_arg.thread_count);
|
||||||
|
182
src/name.rs
182
src/name.rs
@ -1,9 +1,8 @@
|
|||||||
#[cfg(feature = "simd")]
|
use std::cmp::min;
|
||||||
use std::simd::u8x64;
|
|
||||||
#[cfg(feature = "simd")]
|
#[cfg(feature = "simd")]
|
||||||
use std::simd::cmp::SimdPartialOrd;
|
use std::simd::cmp::SimdPartialOrd;
|
||||||
#[cfg(feature = "simd")]
|
#[cfg(feature = "simd")]
|
||||||
use std::simd::Simd;
|
use std::simd::u8x64;
|
||||||
|
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
@ -257,16 +256,11 @@ impl Namer {
|
|||||||
// 计算 name_prop
|
// 计算 name_prop
|
||||||
let mut prop_name = name_base[0..32].to_vec();
|
let mut prop_name = name_base[0..32].to_vec();
|
||||||
prop_name[0..10].sort_unstable();
|
prop_name[0..10].sort_unstable();
|
||||||
/*
|
name_prop[0] = 154
|
||||||
st[0] = 154 + a[3] + a[4] + a[5] + a[6];
|
+ prop_name[3] as u32
|
||||||
st[1] = median(prop_name[10], prop_name[11], prop_name[12]) + 36;
|
+ prop_name[4] as u32
|
||||||
st[2] = median(prop_name[13], prop_name[14], prop_name[15]) + 36;
|
+ prop_name[5] as u32
|
||||||
st[3] = median(prop_name[16], prop_name[17], prop_name[18]) + 36;
|
+ prop_name[6] as u32;
|
||||||
st[4] = median(prop_name[19], prop_name[20], prop_name[21]) + 36;
|
|
||||||
st[5] = median(prop_name[22], prop_name[23], prop_name[24]) + 36;
|
|
||||||
st[6] = median(prop_name[25], prop_name[26], prop_name[27]) + 36;
|
|
||||||
st[7] = median(prop_name[28], prop_name[29], prop_name[30]) + 36; */
|
|
||||||
name_prop[0] = 154 + prop_name[3] as u32 + prop_name[4] as u32 + prop_name[5] as u32 + prop_name[6] as u32;
|
|
||||||
name_prop[1] = median(prop_name[10], prop_name[11], prop_name[12]) as u32 + 36;
|
name_prop[1] = median(prop_name[10], prop_name[11], prop_name[12]) as u32 + 36;
|
||||||
name_prop[2] = median(prop_name[13], prop_name[14], prop_name[15]) as u32 + 36;
|
name_prop[2] = median(prop_name[13], prop_name[14], prop_name[15]) as u32 + 36;
|
||||||
name_prop[3] = median(prop_name[16], prop_name[17], prop_name[18]) as u32 + 36;
|
name_prop[3] = median(prop_name[16], prop_name[17], prop_name[18]) as u32 + 36;
|
||||||
@ -291,41 +285,48 @@ impl Namer {
|
|||||||
/*
|
/*
|
||||||
template <int len>
|
template <int len>
|
||||||
void calc_skills() {
|
void calc_skills() {
|
||||||
// q_len = -1;
|
// q_len = -1;
|
||||||
// memcpy(val, val_base, sizeof val);
|
// memcpy(val, val_base, sizeof val);
|
||||||
// for (int _ = 0; _ < 2; _++)
|
// for (int _ = 0; _ < 2; _++)
|
||||||
// for (int i = s = 0, j = 0; i < N; i++, j++) {
|
// for (int i = s = 0, j = 0; i < N; i++, j++) {
|
||||||
// s += name[j];
|
// s += name[j];
|
||||||
// s += val[i];
|
// s += val[i];
|
||||||
// std::swap(val[i], val[s]);
|
// std::swap(val[i], val[s]);
|
||||||
// if (j == len) j = -1;
|
// if (j == len) j = -1;
|
||||||
// }
|
// }
|
||||||
for (int i = 0; i < N; i++)
|
for (int i = 0; i < N; i++)
|
||||||
if (val[i] * 181 + 199 & 128) name_base[++q_len] = val[i] * 53 & 63 ^ 32;
|
if (val[i] * 181 + 199 & 128) name_base[++q_len] = val[i] * 53 & 63 ^ 32;
|
||||||
|
|
||||||
u8_t *a = name_base + K;
|
u8_t *a = name_base + K;
|
||||||
for (int i = 0; i < skill_cnt; i++) skill[i] = i;
|
for (int i = 0; i < skill_cnt; i++) skill[i] = i;
|
||||||
p = q = s = 0;
|
p = q = s = 0;
|
||||||
for (int _ = 0; _ < 2; _++)
|
for (int _ = 0; _ < 2; _++)
|
||||||
for (int i = 0; i < skill_cnt; i++) {
|
for (int i = 0; i < skill_cnt; i++) {
|
||||||
s = (s + rnd() + skill[i]) % skill_cnt;
|
s = (s + rnd() + skill[i]) % skill_cnt;
|
||||||
std::swap(skill[i], skill[s]);
|
std::swap(skill[i], skill[s]);
|
||||||
}
|
}
|
||||||
int last = -1;
|
int last = -1;
|
||||||
for (int i = 0, j = 0; j < 16; i += 4, j++) {
|
for (int i = 0, j = 0; j < 16; i += 4, j++) {
|
||||||
u8_t p = std::min(std::min(a[i], a[i + 1]), std::min(a[i + 2], a[i + 3]));
|
u8_t p = std::min(std::min(a[i], a[i + 1]), std::min(a[i + 2], a[i + 3]));
|
||||||
if (p > 10 && skill[j] < 35) {
|
if (p > 10 && skill[j] < 35) {
|
||||||
freq[j] = p - 10;
|
freq[j] = p - 10;
|
||||||
if (skill[j] < 25) last = j;
|
if (skill[j] < 25) last = j;
|
||||||
} else
|
} else
|
||||||
freq[j] = 0;
|
freq[j] = 0;
|
||||||
}
|
}
|
||||||
if (last != -1) freq[last] <<= 1;
|
if (last != -1) freq[last] <<= 1;
|
||||||
if (freq[14] && last != 14)
|
if (freq[14] && last != 14)
|
||||||
freq[14] += std::min(std::min(name_base[60], name_base[61]), freq[14]);
|
freq[14] += std::min(std::min(name_base[60], name_base[61]), freq[14]);
|
||||||
if (freq[15] && last != 15)
|
if (freq[15] && last != 15)
|
||||||
freq[15] += std::min(std::min(name_base[62], name_base[63]), freq[15]);
|
freq[15] += std::min(std::min(name_base[62], name_base[63]), freq[15]);
|
||||||
} */
|
} */
|
||||||
|
|
||||||
|
let mut skill_id = [0u8; 40];
|
||||||
|
for i in 0..40 {
|
||||||
|
skill_id[i] = i as u8
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut name_base = self.name_base.clone();
|
||||||
#[cfg(feature = "simd")]
|
#[cfg(feature = "simd")]
|
||||||
{
|
{
|
||||||
let mut simd_val = self.val.clone();
|
let mut simd_val = self.val.clone();
|
||||||
@ -345,14 +346,87 @@ impl Namer {
|
|||||||
x.copy_to_slice(&mut simd_val[i..]);
|
x.copy_to_slice(&mut simd_val[i..]);
|
||||||
y.copy_to_slice(&mut simd_val_b[i..]);
|
y.copy_to_slice(&mut simd_val_b[i..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut mod_count = 0;
|
||||||
|
for i in 0..256 {
|
||||||
|
if simd_val[i] != 0 {
|
||||||
|
name_base[mod_count as usize] = simd_val_b[i];
|
||||||
|
mod_count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// const int N = 256, M = 128, K = 64, skill_cnt = 40, max_len = 25;
|
||||||
|
let mut p: u8 = 0;
|
||||||
|
let mut q: u8 = 0;
|
||||||
|
let mut s: u8 = 0;
|
||||||
|
for _ in 0..2 {
|
||||||
|
for i in 0..40 {
|
||||||
|
/*
|
||||||
|
inline u8_t rnd() {
|
||||||
|
q += val[++p];
|
||||||
|
std::swap(val[p], val[q]);
|
||||||
|
u8_t u = val[(val[p] + val[q]) & 255];
|
||||||
|
q += val[++p];
|
||||||
|
std::swap(val[p], val[q]);
|
||||||
|
return (u << 8 | val[(val[p] + val[q]) & 255]) % skill_cnt;
|
||||||
|
} */
|
||||||
|
let rnd = {
|
||||||
|
q = q.wrapping_add(self.val[p as usize]);
|
||||||
|
p += 1;
|
||||||
|
self.val.swap(p as usize, q as usize);
|
||||||
|
let u: u8 = self.val
|
||||||
|
[((self.val[p as usize] as u16 + self.val[q as usize] as u16) & 255) as usize];
|
||||||
|
q = q.wrapping_add(self.val[p as usize]);
|
||||||
|
p += 1;
|
||||||
|
self.val.swap(p as usize, q as usize);
|
||||||
|
let t = self.val
|
||||||
|
[((self.val[p as usize] as u16 + self.val[q as usize] as u16) & 255) as usize];
|
||||||
|
(((u as u32) << 8 | t as u32) % 40) as u8
|
||||||
|
};
|
||||||
|
// s = (s.wrapping_add(rnd).wrapping_add(skill_id[i])) % 40;
|
||||||
|
s = (s as u16 + rnd as u16 + skill_id[i] as u16) as u8 % 40;
|
||||||
|
skill_id.swap(i as usize, s as usize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut last = -1;
|
||||||
|
let mut j = 0;
|
||||||
|
for i in (64..128).step_by(4) {
|
||||||
|
// a[k] == self.name_base[k+10]
|
||||||
|
let p = min(
|
||||||
|
min(self.name_base[i + 0], self.name_base[i + 1]),
|
||||||
|
min(self.name_base[i + 2], self.name_base[i + 3]),
|
||||||
|
);
|
||||||
|
if p > 10 && skill_id[j] < 35 {
|
||||||
|
self.skl_freq[j] = p - 10;
|
||||||
|
if skill_id[j] < 25 {
|
||||||
|
last = j as i32;
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
self.skl_freq[j] = 0
|
||||||
|
}
|
||||||
|
j += 1;
|
||||||
|
}
|
||||||
|
if last != -1 {
|
||||||
|
self.skl_freq[last as usize] <<= 1;
|
||||||
|
// *= 2
|
||||||
|
}
|
||||||
|
if (self.skl_freq[14] != 0) && (last != 14) {
|
||||||
|
self.skl_freq[14] += min(
|
||||||
|
min(self.name_base[60], self.name_base[61]),
|
||||||
|
self.skl_freq[14],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (self.skl_freq[15] != 0) && (last != 15) {
|
||||||
|
self.skl_freq[15] += min(
|
||||||
|
min(self.name_base[62], self.name_base[63]),
|
||||||
|
self.skl_freq[15],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "simd"))]
|
#[cfg(not(feature = "simd"))]
|
||||||
{
|
{
|
||||||
|
todo!("none simd 还没写呢")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@ -416,6 +490,16 @@ mod test {
|
|||||||
assert_eq!(namer.name_base.to_vec(), base_name_vec);
|
assert_eq!(namer.name_base.to_vec(), base_name_vec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn skill_prop_test() {
|
||||||
|
let team = TeamNamer::new_unchecked("x");
|
||||||
|
let mut namer = Namer::new_from_team_namer_unchecked(&team, "x");
|
||||||
|
|
||||||
|
namer.update_skill();
|
||||||
|
println!("namer: {:?}", namer);
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn prop_test() {
|
fn prop_test() {
|
||||||
let team = TeamNamer::new_unchecked("x");
|
let team = TeamNamer::new_unchecked("x");
|
||||||
|
Loading…
Reference in New Issue
Block a user