Compare commits
No commits in common. "33888f6b64a7d2a9e44adb60198f4172bb5a48d3" and "a56d1ff7c31aef95728c5bcc41951847f2ccf9d1" have entirely different histories.
33888f6b64
...
a56d1ff7c3
@ -56,12 +56,10 @@ pub fn cacl(config: CacluateConfig, id: u64, outfile: &PathBuf) {
|
||||
// 提前准备好 team_namer
|
||||
let team_namer = TeamNamer::new(&config.team).unwrap();
|
||||
|
||||
let mut main_namer = Namer::new_from_team_namer_unchecked(&team_namer, "dummy");
|
||||
|
||||
for i in (config.start + id..config.end).step_by(config.thread_count as usize) {
|
||||
let name = gen_name(i);
|
||||
main_namer.replace_name(&team_namer, &name);
|
||||
let prop = main_namer.get_property();
|
||||
let mut namer = Namer::new_from_team_namer_unchecked(&team_namer, name.as_str());
|
||||
let prop = namer.get_property();
|
||||
|
||||
k += 1;
|
||||
if k >= report_interval {
|
||||
@ -105,26 +103,26 @@ pub fn cacl(config: CacluateConfig, id: u64, outfile: &PathBuf) {
|
||||
let name = gen_name(i);
|
||||
let full_name = format!("{}@{}", name, config.team);
|
||||
// 虚评
|
||||
main_namer.update_skill();
|
||||
namer.update_skill();
|
||||
|
||||
let xu = crate::evaluate::xuping::XuPing2_0_1015::evaluate(&main_namer);
|
||||
let xu_qd = crate::evaluate::xuping::XuPing2_0_1015_QD::evaluate(&main_namer);
|
||||
let xu = crate::evaluate::xuping::XuPing2_0_1015::evaluate(&namer);
|
||||
let xu_qd = crate::evaluate::xuping::XuPing2_0_1015_QD::evaluate(&namer);
|
||||
|
||||
if xu < config.qp_expect as f64 && xu_qd < config.qp_expect as f64 {
|
||||
continue;
|
||||
}
|
||||
|
||||
get_count += 1;
|
||||
info!("Id:{:>15}|{}|{:.4}|{:.4}|{}", i, full_name, xu, xu_qd, main_namer.get_info());
|
||||
info!("Id:{:>15}|{}|{:.4}|{:.4}|{}", i, full_name, xu, xu_qd, namer.get_info());
|
||||
|
||||
let write_in = format!(
|
||||
// <full_name>,<id>,<xu>,<xuqd>,<main_namer.get_info()>
|
||||
// <full_name>,<id>,<xu>,<xuqd>,<namer.get_info()>
|
||||
"{},{:>15},{:.4},{:.4},{}\n",
|
||||
full_name,
|
||||
i,
|
||||
xu,
|
||||
xu_qd,
|
||||
main_namer.get_info_csv()
|
||||
namer.get_info_csv()
|
||||
);
|
||||
|
||||
// 写入 (写到最后一行)
|
||||
|
@ -293,140 +293,6 @@ impl Namer {
|
||||
}
|
||||
}
|
||||
|
||||
/// 更新当前的名字
|
||||
#[inline(always)]
|
||||
pub fn replace_name(&mut self, team_namer: &TeamNamer, name: &str) {
|
||||
self.val = team_namer.clone_vals();
|
||||
|
||||
let name_bytes = name.as_bytes();
|
||||
let name_len = name_bytes.len();
|
||||
let b_name_len = name_len + 1;
|
||||
|
||||
for _ in 0..2 {
|
||||
let mut s = 0_u8;
|
||||
unsafe {
|
||||
self.val.swap_unchecked(s as usize, 0);
|
||||
let mut k = 0;
|
||||
for i in 0..256 {
|
||||
s = s.wrapping_add(if k == 0 { 0 } else { *name_bytes.get_unchecked(k - 1) });
|
||||
s = s.wrapping_add(*self.val.get_unchecked(i));
|
||||
self.val.swap_unchecked(i, s as usize);
|
||||
k = if k == b_name_len - 1 { 0 } else { k + 1 };
|
||||
}
|
||||
}
|
||||
}
|
||||
// simd!
|
||||
#[cfg(feature = "simd")]
|
||||
{
|
||||
let mut simd_val = [0_u8; 256];
|
||||
let mut simd_val_b = [0_u8; 256];
|
||||
let simd_181 = u8x64::splat(181);
|
||||
let simd_160 = u8x64::splat(160);
|
||||
let simd_63 = u8x64::splat(63);
|
||||
|
||||
for i in (0..256).step_by(64) {
|
||||
unsafe {
|
||||
let mut x = u8x64::from_slice(self.val.get_unchecked(i..i+64));
|
||||
x = x * simd_181 + simd_160;
|
||||
x.copy_to_slice(simd_val.get_unchecked_mut(i..i+64));
|
||||
let y = x & simd_63;
|
||||
y.copy_to_slice(simd_val_b.get_unchecked_mut(i..i+64));
|
||||
}
|
||||
}
|
||||
let mut mod_count = 0;
|
||||
for i in 0..96 {
|
||||
unsafe {
|
||||
if simd_val.get_unchecked(i) > &88 && simd_val.get_unchecked(i) < &217 {
|
||||
*self.name_base.get_unchecked_mut(mod_count as usize) = *simd_val_b.get_unchecked(i);
|
||||
mod_count += 1;
|
||||
}
|
||||
}
|
||||
if mod_count > 30 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if mod_count < 31 {
|
||||
for i in 96..256 {
|
||||
unsafe {
|
||||
if simd_val.get_unchecked(i) > &88 && simd_val.get_unchecked(i) < &217 {
|
||||
*self.name_base.get_unchecked_mut(mod_count as usize) = *simd_val_b.get_unchecked(i);
|
||||
mod_count += 1;
|
||||
}
|
||||
}
|
||||
if mod_count > 30 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(not(feature = "simd"))]
|
||||
{
|
||||
let mut s = 0;
|
||||
for i in 0..256 {
|
||||
let m = ((self.val[i] as u32 * 181) + 160) % 256;
|
||||
if m >= 89 && m < 217 {
|
||||
self.name_base[s as usize] = (m & 63) as u8;
|
||||
s += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 计算 name_prop
|
||||
unsafe {
|
||||
let mut prop_name = [0_u8; 32];
|
||||
prop_name.copy_from_slice(self.name_base.get_unchecked(0..32));
|
||||
prop_name.get_unchecked_mut(0..10).sort_unstable();
|
||||
*self.name_prop.get_unchecked_mut(0) = 154
|
||||
+ *prop_name.get_unchecked(3) as u32
|
||||
+ *prop_name.get_unchecked(4) as u32
|
||||
+ *prop_name.get_unchecked(5) as u32
|
||||
+ *prop_name.get_unchecked(6) as u32;
|
||||
|
||||
*self.name_prop.get_unchecked_mut(1) = median(
|
||||
*prop_name.get_unchecked(10),
|
||||
*prop_name.get_unchecked(11),
|
||||
*prop_name.get_unchecked(12),
|
||||
) as u32
|
||||
+ 36;
|
||||
*self.name_prop.get_unchecked_mut(2) = median(
|
||||
*prop_name.get_unchecked(13),
|
||||
*prop_name.get_unchecked(14),
|
||||
*prop_name.get_unchecked(15),
|
||||
) as u32
|
||||
+ 36;
|
||||
*self.name_prop.get_unchecked_mut(3) = median(
|
||||
*prop_name.get_unchecked(16),
|
||||
*prop_name.get_unchecked(17),
|
||||
*prop_name.get_unchecked(18),
|
||||
) as u32
|
||||
+ 36;
|
||||
*self.name_prop.get_unchecked_mut(4) = median(
|
||||
*prop_name.get_unchecked(19),
|
||||
*prop_name.get_unchecked(20),
|
||||
*prop_name.get_unchecked(21),
|
||||
) as u32
|
||||
+ 36;
|
||||
*self.name_prop.get_unchecked_mut(5) = median(
|
||||
*prop_name.get_unchecked(22),
|
||||
*prop_name.get_unchecked(23),
|
||||
*prop_name.get_unchecked(24),
|
||||
) as u32
|
||||
+ 36;
|
||||
*self.name_prop.get_unchecked_mut(6) = median(
|
||||
*prop_name.get_unchecked(25),
|
||||
*prop_name.get_unchecked(26),
|
||||
*prop_name.get_unchecked(27),
|
||||
) as u32
|
||||
+ 36;
|
||||
*self.name_prop.get_unchecked_mut(7) = median(
|
||||
*prop_name.get_unchecked(28),
|
||||
*prop_name.get_unchecked(29),
|
||||
*prop_name.get_unchecked(30),
|
||||
) as u32
|
||||
+ 36;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn update_skill(&mut self) {
|
||||
let skill_id = self.skl_id.as_mut();
|
||||
@ -754,26 +620,4 @@ mod test {
|
||||
|
||||
assert_eq!(name.name_prop.to_vec(), prop_vec);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_name_test() {
|
||||
// 先创建一个正常的 namer
|
||||
// 然后更新名字
|
||||
let team = TeamNamer::new_unchecked("x");
|
||||
let mut namer = Namer::new_from_team_namer_unchecked(&team, "x");
|
||||
|
||||
let update_name = "k";
|
||||
namer.replace_name(&team, update_name);
|
||||
|
||||
let mut none_update_name = Namer::new_from_team_namer_unchecked(&team, update_name);
|
||||
none_update_name.update_skill();
|
||||
namer.update_skill();
|
||||
|
||||
assert_eq!(namer.name_base.to_vec(), none_update_name.name_base.to_vec());
|
||||
assert_eq!(namer.name_prop.to_vec(), none_update_name.name_prop.to_vec());
|
||||
assert_eq!(namer.val.to_vec(), none_update_name.val.to_vec());
|
||||
assert_eq!(namer.skl_id.to_vec(), none_update_name.skl_id.to_vec());
|
||||
assert_eq!(namer.skl_freq.to_vec(), none_update_name.skl_freq.to_vec());
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -260,17 +260,16 @@ impl RC4 {
|
||||
/// return X.map((e) => list[e]).toList();
|
||||
/// }
|
||||
/// ```
|
||||
pub fn sort_list<T>(&mut self, list: &mut [T]) {
|
||||
pub fn sort_list<T>(&mut self, &mut list: Vec<T>) {
|
||||
if list.len() <= 1 {
|
||||
return;
|
||||
}
|
||||
let n = list.len();
|
||||
// 直接对输入列表进行操作
|
||||
let mut b = 0;
|
||||
for _ in 0..2 {
|
||||
for a in 0..n {
|
||||
let key_v = self.next_i32(n as i32);
|
||||
b = (b + a + key_v as usize) % n;
|
||||
let b = (b + a + key_v) % n;
|
||||
list.swap(a, b);
|
||||
}
|
||||
}
|
||||
@ -291,7 +290,7 @@ impl RC4 {
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
pub fn pick<T>(&mut self, list: &mut [T]) -> Option<usize> {
|
||||
pub fn pick<T>(&mut self, list: Vec<T>) -> Option<usize> {
|
||||
match list.len() {
|
||||
1 => Some(0),
|
||||
n if n > 1 => Some(self.next_i32(n as i32) as usize),
|
||||
@ -328,7 +327,7 @@ impl RC4 {
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
pub fn pick_skip<T>(&mut self, list: &mut [T], skip_after_index: usize) -> Option<usize> {
|
||||
pub fn pick_skip<T>(&mut self, list: Vec<T>, skip_after_index: usize) -> Option<usize> {
|
||||
match list.len() {
|
||||
1 => {
|
||||
if skip_after_index == 0 {
|
||||
@ -378,7 +377,7 @@ impl RC4 {
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
pub fn pick_skip_range<T>(&mut self, list: &mut [T], skips: Vec<usize>) -> Option<usize> {
|
||||
pub fn pick_skip_range<T>(&mut self, list: Vec<T>, skips: Vec<usize>) -> Option<usize> {
|
||||
if skips.is_empty() {
|
||||
return self.pick(list);
|
||||
}
|
||||
|
1
zigs/.gitignore
vendored
1
zigs/.gitignore
vendored
@ -1 +0,0 @@
|
||||
zig-cache
|
@ -1,91 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
// Although this function looks imperative, note that its job is to
|
||||
// declaratively construct a build graph that will be executed by an external
|
||||
// runner.
|
||||
pub fn build(b: *std.Build) void {
|
||||
// Standard target options allows the person running `zig build` to choose
|
||||
// what target to build for. Here we do not override the defaults, which
|
||||
// means any target is allowed, and the default is native. Other options
|
||||
// for restricting supported target set are available.
|
||||
const target = b.standardTargetOptions(.{});
|
||||
|
||||
// Standard optimization options allow the person running `zig build` to select
|
||||
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
|
||||
// set a preferred release mode, allowing the user to decide how to optimize.
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const lib = b.addStaticLibrary(.{
|
||||
.name = "zigs",
|
||||
// In this case the main source file is merely a path, however, in more
|
||||
// complicated build scripts, this could be a generated file.
|
||||
.root_source_file = b.path("src/root.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
// This declares intent for the library to be installed into the standard
|
||||
// location when the user invokes the "install" step (the default step when
|
||||
// running `zig build`).
|
||||
b.installArtifact(lib);
|
||||
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "zigs",
|
||||
.root_source_file = b.path("src/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
// This declares intent for the executable to be installed into the
|
||||
// standard location when the user invokes the "install" step (the default
|
||||
// step when running `zig build`).
|
||||
b.installArtifact(exe);
|
||||
|
||||
// This *creates* a Run step in the build graph, to be executed when another
|
||||
// step is evaluated that depends on it. The next line below will establish
|
||||
// such a dependency.
|
||||
const run_cmd = b.addRunArtifact(exe);
|
||||
|
||||
// By making the run step depend on the install step, it will be run from the
|
||||
// installation directory rather than directly from within the cache directory.
|
||||
// This is not necessary, however, if the application depends on other installed
|
||||
// files, this ensures they will be present and in the expected location.
|
||||
run_cmd.step.dependOn(b.getInstallStep());
|
||||
|
||||
// This allows the user to pass arguments to the application in the build
|
||||
// command itself, like this: `zig build run -- arg1 arg2 etc`
|
||||
if (b.args) |args| {
|
||||
run_cmd.addArgs(args);
|
||||
}
|
||||
|
||||
// This creates a build step. It will be visible in the `zig build --help` menu,
|
||||
// and can be selected like this: `zig build run`
|
||||
// This will evaluate the `run` step rather than the default, which is "install".
|
||||
const run_step = b.step("run", "Run the app");
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
|
||||
// Creates a step for unit testing. This only builds the test executable
|
||||
// but does not run it.
|
||||
const lib_unit_tests = b.addTest(.{
|
||||
.root_source_file = b.path("src/root.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
|
||||
|
||||
const exe_unit_tests = b.addTest(.{
|
||||
.root_source_file = b.path("src/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
|
||||
|
||||
// Similar to creating the run step earlier, this exposes a `test` step to
|
||||
// the `zig build --help` menu, providing a way for the user to request
|
||||
// running the unit tests.
|
||||
const test_step = b.step("test", "Run unit tests");
|
||||
test_step.dependOn(&run_lib_unit_tests.step);
|
||||
test_step.dependOn(&run_exe_unit_tests.step);
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
.{
|
||||
.name = "zigs",
|
||||
// This is a [Semantic Version](https://semver.org/).
|
||||
// In a future version of Zig it will be used for package deduplication.
|
||||
.version = "0.0.0",
|
||||
|
||||
// This field is optional.
|
||||
// This is currently advisory only; Zig does not yet do anything
|
||||
// with this value.
|
||||
//.minimum_zig_version = "0.11.0",
|
||||
|
||||
// This field is optional.
|
||||
// Each dependency must either provide a `url` and `hash`, or a `path`.
|
||||
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
|
||||
// Once all dependencies are fetched, `zig build` no longer requires
|
||||
// internet connectivity.
|
||||
.dependencies = .{
|
||||
// See `zig fetch --save <url>` for a command-line interface for adding dependencies.
|
||||
//.example = .{
|
||||
// // When updating this field to a new URL, be sure to delete the corresponding
|
||||
// // `hash`, otherwise you are communicating that you expect to find the old hash at
|
||||
// // the new URL.
|
||||
// .url = "https://example.com/foo.tar.gz",
|
||||
//
|
||||
// // This is computed from the file contents of the directory of files that is
|
||||
// // obtained after fetching `url` and applying the inclusion rules given by
|
||||
// // `paths`.
|
||||
// //
|
||||
// // This field is the source of truth; packages do not come from a `url`; they
|
||||
// // come from a `hash`. `url` is just one of many possible mirrors for how to
|
||||
// // obtain a package matching this `hash`.
|
||||
// //
|
||||
// // Uses the [multihash](https://multiformats.io/multihash/) format.
|
||||
// .hash = "...",
|
||||
//
|
||||
// // When this is provided, the package is found in a directory relative to the
|
||||
// // build root. In this case the package's hash is irrelevant and therefore not
|
||||
// // computed. This field and `url` are mutually exclusive.
|
||||
// .path = "foo",
|
||||
|
||||
// // When this is set to `true`, a package is declared to be lazily
|
||||
// // fetched. This makes the dependency only get fetched if it is
|
||||
// // actually used.
|
||||
// .lazy = false,
|
||||
//},
|
||||
},
|
||||
|
||||
// Specifies the set of files and directories that are included in this package.
|
||||
// Only files and directories listed here are included in the `hash` that
|
||||
// is computed for this package.
|
||||
// Paths are relative to the build root. Use the empty string (`""`) to refer to
|
||||
// the build root itself.
|
||||
// A directory listed here means that all files within, recursively, are included.
|
||||
.paths = .{
|
||||
// This makes *all* files, recursively, included in this package. It is generally
|
||||
// better to explicitly list the files and directories instead, to insure that
|
||||
// fetching from tarballs, file system paths, and version control all result
|
||||
// in the same contents hash.
|
||||
"",
|
||||
// For example...
|
||||
//"build.zig",
|
||||
//"build.zig.zon",
|
||||
//"src",
|
||||
//"LICENSE",
|
||||
//"README.md",
|
||||
},
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() !void {
|
||||
// Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)
|
||||
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
|
||||
|
||||
// stdout is for the actual output of your application, for example if you
|
||||
// are implementing gzip, then only the compressed bytes should be sent to
|
||||
// stdout, not any debugging messages.
|
||||
const stdout_file = std.io.getStdOut().writer();
|
||||
var bw = std.io.bufferedWriter(stdout_file);
|
||||
const stdout = bw.writer();
|
||||
|
||||
try stdout.print("Run `zig build test` to run the tests.\n", .{});
|
||||
|
||||
try bw.flush(); // don't forget to flush!
|
||||
}
|
||||
|
||||
test "simple test" {
|
||||
var list = std.ArrayList(i32).init(std.testing.allocator);
|
||||
defer list.deinit(); // try commenting this out and see if zig detects the memory leak!
|
||||
try list.append(42);
|
||||
try std.testing.expectEqual(@as(i32, 42), list.pop());
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
const std = @import("std");
|
||||
const testing = std.testing;
|
||||
|
||||
export fn add(a: i32, b: i32) i32 {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
test "basic add functionality" {
|
||||
try testing.expect(add(3, 7) == 10);
|
||||
}
|
Loading…
Reference in New Issue
Block a user