diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-10-11 17:08:08 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-10-11 18:13:24 -0400 |
| commit | 30a555eed4d48b602b2c92a05c443e03c4660d48 (patch) | |
| tree | 00c94859ba91bd12419aa48b5bee66306d10070b /lib/std | |
| parent | 8aa20227ed45294da9606222d0b20eb922cecb2e (diff) | |
| download | zig-30a555eed4d48b602b2c92a05c443e03c4660d48.tar.gz zig-30a555eed4d48b602b2c92a05c443e03c4660d48.zip | |
merge dumps tool: merging ast nodes
-fgenerate-docs is replaced ith -femit-docs
-fno-emit-bin is added to prevent outputting binary
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/hash.zig | 2 | ||||
| -rw-r--r-- | lib/std/hash_map.zig | 10 | ||||
| -rw-r--r-- | lib/std/json/write_stream.zig | 15 |
3 files changed, 23 insertions, 4 deletions
diff --git a/lib/std/hash.zig b/lib/std/hash.zig index ab3a0ea8f3..c51353b328 100644 --- a/lib/std/hash.zig +++ b/lib/std/hash.zig @@ -3,6 +3,8 @@ pub const Adler32 = adler.Adler32; const auto_hash = @import("hash/auto_hash.zig"); pub const autoHash = auto_hash.autoHash; +pub const autoHashStrat = auto_hash.hash; +pub const Strategy = auto_hash.HashStrategy; // pub for polynomials + generic crc32 construction pub const crc = @import("hash/crc.zig"); diff --git a/lib/std/hash_map.zig b/lib/std/hash_map.zig index 4ffe88067b..677dfe4435 100644 --- a/lib/std/hash_map.zig +++ b/lib/std/hash_map.zig @@ -550,3 +550,13 @@ pub fn getAutoEqlFn(comptime K: type) (fn (K, K) bool) { } }.eql; } + +pub fn getAutoHashStratFn(comptime K: type, comptime strategy: std.hash.Strategy) (fn (K) u32) { + return struct { + fn hash(key: K) u32 { + var hasher = Wyhash.init(0); + std.hash.autoHashStrat(&hasher, key, strategy); + return @truncate(u32, hasher.final()); + } + }.hash; +} diff --git a/lib/std/json/write_stream.zig b/lib/std/json/write_stream.zig index 2bb79a017c..c30f8ba8d8 100644 --- a/lib/std/json/write_stream.zig +++ b/lib/std/json/write_stream.zig @@ -152,10 +152,17 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { ) !void { assert(self.state[self.state_index] == State.Value); switch (@typeInfo(@typeOf(value))) { - .Int => |info| if (info.bits < 53 or (value < 4503599627370496 and value > -4503599627370496)) { - try self.stream.print("{}", value); - self.popState(); - return; + .Int => |info| { + if (info.bits < 53) { + try self.stream.print("{}", value); + self.popState(); + return; + } + if (value < 4503599627370496 and (!info.is_signed or value > -4503599627370496)) { + try self.stream.print("{}", value); + self.popState(); + return; + } }, .Float => if (@floatCast(f64, value) == value) { try self.stream.print("{}", value); |
