Commit 75ed835d08
Changed files (1)
lib
lib/std/array_hash_map.zig
@@ -18,11 +18,11 @@ const builtin = @import("builtin");
const hash_map = @This();
pub fn AutoArrayHashMap(comptime K: type, comptime V: type) type {
- return ArrayHashMap(K, V, getAutoHashFn(K), getAutoEqlFn(K), autoEqlIsCheap(K));
+ return ArrayHashMap(K, V, getAutoHashFn(K), getAutoEqlFn(K), !autoEqlIsCheap(K));
}
pub fn AutoArrayHashMapUnmanaged(comptime K: type, comptime V: type) type {
- return ArrayHashMapUnmanaged(K, V, getAutoHashFn(K), getAutoEqlFn(K), autoEqlIsCheap(K));
+ return ArrayHashMapUnmanaged(K, V, getAutoHashFn(K), getAutoEqlFn(K), !autoEqlIsCheap(K));
}
/// Builtin hashmap for strings as keys.
@@ -1294,7 +1294,7 @@ test "reIndex" {
try al.append(std.testing.allocator, .{
.key = i,
.value = i * 10,
- .hash = hash(i),
+ .hash = {},
});
}
@@ -1321,7 +1321,7 @@ test "fromOwnedArrayList" {
try al.append(std.testing.allocator, .{
.key = i,
.value = i * 10,
- .hash = hash(i),
+ .hash = {},
});
}
@@ -1338,6 +1338,18 @@ test "fromOwnedArrayList" {
}
}
+test "auto store_hash" {
+ const HasCheapEql = AutoArrayHashMap(i32, i32);
+ const HasExpensiveEql = AutoArrayHashMap([32]i32, i32);
+ try testing.expect(meta.fieldInfo(HasCheapEql.Entry, .hash).field_type == void);
+ try testing.expect(meta.fieldInfo(HasExpensiveEql.Entry, .hash).field_type != void);
+
+ const HasCheapEqlUn = AutoArrayHashMapUnmanaged(i32, i32);
+ const HasExpensiveEqlUn = AutoArrayHashMapUnmanaged([32]i32, i32);
+ try testing.expect(meta.fieldInfo(HasCheapEqlUn.Entry, .hash).field_type == void);
+ try testing.expect(meta.fieldInfo(HasExpensiveEqlUn.Entry, .hash).field_type != void);
+}
+
pub fn getHashPtrAddrFn(comptime K: type) (fn (K) u32) {
return struct {
fn hash(key: K) u32 {