stage2 更多的工具库

This commit is contained in:
zzy committed 2026-09-17 22:32:36 +08:00
1 parent 4141e7d574
commit 16a1f030d4
15 files changed
+1914 -109

No files matched your search

+1 -24
View File
@@ -6,6 +6,7 @@
type .{ .Error, .Status, .make } = @import("error.spl");
type .{ .Vec } = @import("vec.spl");
type .{ .ByteView } = @import("byte_view.spl");
type .{ .hash_usize, .eq_usize, .hash_view, .eq_view } = @import("hash.spl");
type .{ .copy } = @import("../sys/mem.spl");
// 槽位状态:0=EMPTY,1=OCCUPIED,2=DELETED(墓碑,仅在扩容重哈希时清除)。
@@ -239,15 +240,6 @@ fn take(source: *Map): Map {
// ---- 测试辅助 ----
fn hash_usize(key: *u8): usize {
var value = (key as *usize).*;
ret value * 2654435761;
}
fn eq_usize(a: *u8, b: *u8): bool {
ret (a as *usize).* == (b as *usize).*;
}
fn expect_ok(result: Status) {
match result {
.Ok => {},
@@ -391,21 +383,6 @@ fn test_take_and_self_put() {
drop(&moved);
}
fn hash_view(key: *u8): usize {
var view = (key as *ByteView).*;
var h: usize = 14695981039346656037;
var i: usize = 0;
while i < view.len {
h = (h ^ (view.ptr[i] as usize)) * 1099511628211;
i = i + 1;
}
ret h;
}
fn eq_view(a: *u8, b: *u8): bool {
ret ByteView.eq((a as *ByteView).*, (b as *ByteView).*);
}
fn test_byte_view_keys() {
var m = new(@sizeof(ByteView), @alignof(ByteView), @sizeof(i32), @alignof(i32),
hash_view, eq_view);