| ... | ... | @@ -18,11 +18,11 @@ const builtin = @import("builtin"); |
| 18 | 18 | const hash_map = @This(); |
| 19 | 19 | |
| 20 | 20 | pub fn AutoArrayHashMap(comptime K: type, comptime V: type) type { |
| 21 | | return ArrayHashMap(K, V, getAutoHashFn(K), getAutoEqlFn(K), autoEqlIsCheap(K)); |
| 21 | return ArrayHashMap(K, V, getAutoHashFn(K), getAutoEqlFn(K), !autoEqlIsCheap(K)); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | pub fn AutoArrayHashMapUnmanaged(comptime K: type, comptime V: type) type { |
| 25 | | return ArrayHashMapUnmanaged(K, V, getAutoHashFn(K), getAutoEqlFn(K), autoEqlIsCheap(K)); |
| 25 | return ArrayHashMapUnmanaged(K, V, getAutoHashFn(K), getAutoEqlFn(K), !autoEqlIsCheap(K)); |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /// Builtin hashmap for strings as keys. |
| ... | ... | @@ -1294,7 +1294,7 @@ test "reIndex" { |
| 1294 | 1294 | try al.append(std.testing.allocator, .{ |
| 1295 | 1295 | .key = i, |
| 1296 | 1296 | .value = i * 10, |
| 1297 | | .hash = hash(i), |
| 1297 | .hash = {}, |
| 1298 | 1298 | }); |
| 1299 | 1299 | } |
| 1300 | 1300 | |
| ... | ... | @@ -1321,7 +1321,7 @@ test "fromOwnedArrayList" { |
| 1321 | 1321 | try al.append(std.testing.allocator, .{ |
| 1322 | 1322 | .key = i, |
| 1323 | 1323 | .value = i * 10, |
| 1324 | | .hash = hash(i), |
| 1324 | .hash = {}, |
| 1325 | 1325 | }); |
| 1326 | 1326 | } |
| 1327 | 1327 | |
| ... | ... | @@ -1338,6 +1338,18 @@ test "fromOwnedArrayList" { |
| 1338 | 1338 | } |
| 1339 | 1339 | } |
| 1340 | 1340 | |
| 1341 | test "auto store_hash" { |
| 1342 | const HasCheapEql = AutoArrayHashMap(i32, i32); |
| 1343 | const HasExpensiveEql = AutoArrayHashMap([32]i32, i32); |
| 1344 | try testing.expect(meta.fieldInfo(HasCheapEql.Entry, .hash).field_type == void); |
| 1345 | try testing.expect(meta.fieldInfo(HasExpensiveEql.Entry, .hash).field_type != void); |
| 1346 | |
| 1347 | const HasCheapEqlUn = AutoArrayHashMapUnmanaged(i32, i32); |
| 1348 | const HasExpensiveEqlUn = AutoArrayHashMapUnmanaged([32]i32, i32); |
| 1349 | try testing.expect(meta.fieldInfo(HasCheapEqlUn.Entry, .hash).field_type == void); |
| 1350 | try testing.expect(meta.fieldInfo(HasExpensiveEqlUn.Entry, .hash).field_type != void); |
| 1351 | } |
| 1352 | |
| 1341 | 1353 | pub fn getHashPtrAddrFn(comptime K: type) (fn (K) u32) { |
| 1342 | 1354 | return struct { |
| 1343 | 1355 | fn hash(key: K) u32 { |