authorgravatar for sahnvour@pm.meSahnvour <sahnvour@pm.me> 2019-09-03 23:53:05+02:00
committergravatar for sahnvour@pm.meSahnvour <sahnvour@pm.me> 2019-09-03 23:53:05+02:00
logf08c6e4fe6ad63145ef69377f36f34e9f04cadec
tree64f59c057ae4c964ab8343d1723612cccd5151bd
parentbe17a4b6c1be11eb4b75db1972a38fc50875ebed

changing occurrences of HashMap with []const u8 as keys for StringHashMap


12 files changed, 31 insertions(+), 44 deletions(-)

doc/docgen.zig+2-2
......@@ -307,7 +307,7 @@ const Node = union(enum) {
307307const Toc = struct {
308308 nodes: []Node,
309309 toc: []u8,
310 urls: std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8),
310 urls: std.StringHashMap(Token),
311311};
312312
313313const Action = enum {
......@@ -316,7 +316,7 @@ const Action = enum {
316316};
317317
318318fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
319 var urls = std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8).init(allocator);
319 var urls = std.StringHashMap(Token).init(allocator);
320320 errdefer urls.deinit();
321321
322322 var header_stack_size: usize = 0;
src-self-hosted/arg.zig+2-2
......@@ -5,7 +5,7 @@ const mem = std.mem;
55
66const Allocator = mem.Allocator;
77const ArrayList = std.ArrayList;
8const HashMap = std.HashMap;
8const StringHashMap = std.StringHashMap;
99
1010fn trimStart(slice: []const u8, ch: u8) []const u8 {
1111 var i: usize = 0;
......@@ -73,7 +73,7 @@ fn readFlagArguments(allocator: *Allocator, args: []const []const u8, required:
7373 }
7474}
7575
76const HashMapFlags = HashMap([]const u8, FlagArg, std.hash.Fnv1a_32.hash, mem.eql_slice_u8);
76const HashMapFlags = StringHashMap(FlagArg);
7777
7878// A store for querying found flags and positional arguments.
7979pub const Args = struct {
src-self-hosted/compilation.zig+1-1
......@@ -249,7 +249,7 @@ pub const Compilation = struct {
249249 const ArrayTypeTable = std.HashMap(*const Type.Array.Key, *Type.Array, Type.Array.Key.hash, Type.Array.Key.eql);
250250 const PtrTypeTable = std.HashMap(*const Type.Pointer.Key, *Type.Pointer, Type.Pointer.Key.hash, Type.Pointer.Key.eql);
251251 const FnTypeTable = std.HashMap(*const Type.Fn.Key, *Type.Fn, Type.Fn.Key.hash, Type.Fn.Key.eql);
252 const TypeTable = std.HashMap([]const u8, *Type, mem.hash_slice_u8, mem.eql_slice_u8);
252 const TypeTable = std.StringHashMap(*Type);
253253
254254 const CompileErrList = std.ArrayList(*Msg);
255255
src-self-hosted/decl.zig+1-1
......@@ -20,7 +20,7 @@ pub const Decl = struct {
2020 // TODO when we destroy the decl, deref the tree scope
2121 tree_scope: *Scope.AstTree,
2222
23 pub const Table = std.HashMap([]const u8, *Decl, mem.hash_slice_u8, mem.eql_slice_u8);
23 pub const Table = std.StringHashMap(*Decl);
2424
2525 pub fn cast(base: *Decl, comptime T: type) ?*T {
2626 if (base.id != @field(Id, @typeName(T))) return null;
src-self-hosted/main.zig+1-1
......@@ -541,7 +541,7 @@ const Fmt = struct {
541541 color: errmsg.Color,
542542 loop: *event.Loop,
543543
544 const SeenMap = std.HashMap([]const u8, void, mem.hash_slice_u8, mem.eql_slice_u8);
544 const SeenMap = std.StringHashMap(void);
545545};
546546
547547fn parseLibcPaths(allocator: *Allocator, libc: *LibCInstallation, libc_paths_file: []const u8) void {
src-self-hosted/package.zig+1-1
......@@ -10,7 +10,7 @@ pub const Package = struct {
1010 /// relative to root_src_dir
1111 table: Table,
1212
13 pub const Table = std.HashMap([]const u8, *Package, mem.hash_slice_u8, mem.eql_slice_u8);
13 pub const Table = std.StringHashMap(*Package);
1414
1515 /// makes internal copies of root_src_dir and root_src_path
1616 /// allocator should be an arena allocator because Package never frees anything
src-self-hosted/stage1.zig+2-2
......@@ -343,7 +343,7 @@ const Fmt = struct {
343343 color: errmsg.Color,
344344 allocator: *mem.Allocator,
345345
346 const SeenMap = std.HashMap([]const u8, void, mem.hash_slice_u8, mem.eql_slice_u8);
346 const SeenMap = std.StringHashMap(void);
347347};
348348
349349fn printErrMsgToFile(
......@@ -376,7 +376,7 @@ fn printErrMsgToFile(
376376 const text = text_buf.toOwnedSlice();
377377
378378 const stream = &file.outStream().stream;
379 try stream.print( "{}:{}:{}: error: {}\n", path, start_loc.line + 1, start_loc.column + 1, text);
379 try stream.print("{}:{}:{}: error: {}\n", path, start_loc.line + 1, start_loc.column + 1, text);
380380
381381 if (!color_on) return;
382382
std/buf_map.zig+2-2
......@@ -1,5 +1,5 @@
11const std = @import("std.zig");
2const HashMap = std.HashMap;
2const StringHashMap = std.StringHashMap;
33const mem = std.mem;
44const Allocator = mem.Allocator;
55const testing = std.testing;
......@@ -9,7 +9,7 @@ const testing = std.testing;
99pub const BufMap = struct {
1010 hash_map: BufMapHashMap,
1111
12 const BufMapHashMap = HashMap([]const u8, []const u8, mem.hash_slice_u8, mem.eql_slice_u8);
12 const BufMapHashMap = StringHashMap([]const u8);
1313
1414 pub fn init(allocator: *Allocator) BufMap {
1515 var self = BufMap{ .hash_map = BufMapHashMap.init(allocator) };
std/buf_set.zig+2-2
......@@ -1,5 +1,5 @@
11const std = @import("std.zig");
2const HashMap = @import("hash_map.zig").HashMap;
2const StringHashMap = std.StringHashMap;
33const mem = @import("mem.zig");
44const Allocator = mem.Allocator;
55const testing = std.testing;
......@@ -7,7 +7,7 @@ const testing = std.testing;
77pub const BufSet = struct {
88 hash_map: BufSetHashMap,
99
10 const BufSetHashMap = HashMap([]const u8, void, mem.hash_slice_u8, mem.eql_slice_u8);
10 const BufSetHashMap = StringHashMap(void);
1111
1212 pub fn init(a: *Allocator) BufSet {
1313 var self = BufSet{ .hash_map = BufSetHashMap.init(a) };
std/build.zig+3-3
......@@ -7,7 +7,7 @@ const debug = std.debug;
77const assert = debug.assert;
88const warn = std.debug.warn;
99const ArrayList = std.ArrayList;
10const HashMap = std.HashMap;
10const StringHashMap = std.StringHashMap;
1111const Allocator = mem.Allocator;
1212const process = std.process;
1313const BufSet = std.BufSet;
......@@ -60,8 +60,8 @@ pub const Builder = struct {
6060 C11,
6161 };
6262
63 const UserInputOptionsMap = HashMap([]const u8, UserInputOption, mem.hash_slice_u8, mem.eql_slice_u8);
64 const AvailableOptionsMap = HashMap([]const u8, AvailableOption, mem.hash_slice_u8, mem.eql_slice_u8);
63 const UserInputOptionsMap = StringHashMap(UserInputOption);
64 const AvailableOptionsMap = StringHashMap(AvailableOption);
6565
6666 const AvailableOption = struct {
6767 name: []const u8,
std/json.zig+2-2
......@@ -989,7 +989,7 @@ test "json.validate" {
989989const Allocator = std.mem.Allocator;
990990const ArenaAllocator = std.heap.ArenaAllocator;
991991const ArrayList = std.ArrayList;
992const HashMap = std.HashMap;
992const StringHashMap = std.StringHashMap;
993993
994994pub const ValueTree = struct {
995995 arena: ArenaAllocator,
......@@ -1000,7 +1000,7 @@ pub const ValueTree = struct {
10001000 }
10011001};
10021002
1003pub const ObjectMap = HashMap([]const u8, Value, mem.hash_slice_u8, mem.eql_slice_u8);
1003pub const ObjectMap = StringHashMap(Value);
10041004
10051005pub const Value = union(enum) {
10061006 Null,
std/mem.zig+12-25
......@@ -738,47 +738,34 @@ test "writeIntBig and writeIntLittle" {
738738 var buf9: [9]u8 = undefined;
739739
740740 writeIntBig(u0, &buf0, 0x0);
741 testing.expect(eql_slice_u8(buf0[0..], [_]u8{}));
741 testing.expect(eql(u8, buf0[0..], [_]u8{}));
742742 writeIntLittle(u0, &buf0, 0x0);
743 testing.expect(eql_slice_u8(buf0[0..], [_]u8{}));
743 testing.expect(eql(u8, buf0[0..], [_]u8{}));
744744
745745 writeIntBig(u8, &buf1, 0x12);
746 testing.expect(eql_slice_u8(buf1[0..], [_]u8{0x12}));
746 testing.expect(eql(u8, buf1[0..], [_]u8{0x12}));
747747 writeIntLittle(u8, &buf1, 0x34);
748 testing.expect(eql_slice_u8(buf1[0..], [_]u8{0x34}));
748 testing.expect(eql(u8, buf1[0..], [_]u8{0x34}));
749749
750750 writeIntBig(u16, &buf2, 0x1234);
751 testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0x12, 0x34 }));
751 testing.expect(eql(u8, buf2[0..], [_]u8{ 0x12, 0x34 }));
752752 writeIntLittle(u16, &buf2, 0x5678);
753 testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0x78, 0x56 }));
753 testing.expect(eql(u8, buf2[0..], [_]u8{ 0x78, 0x56 }));
754754
755755 writeIntBig(u72, &buf9, 0x123456789abcdef024);
756 testing.expect(eql_slice_u8(buf9[0..], [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
756 testing.expect(eql(u8, buf9[0..], [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
757757 writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);
758 testing.expect(eql_slice_u8(buf9[0..], [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
758 testing.expect(eql(u8, buf9[0..], [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
759759
760760 writeIntBig(i8, &buf1, -1);
761 testing.expect(eql_slice_u8(buf1[0..], [_]u8{0xff}));
761 testing.expect(eql(u8, buf1[0..], [_]u8{0xff}));
762762 writeIntLittle(i8, &buf1, -2);
763 testing.expect(eql_slice_u8(buf1[0..], [_]u8{0xfe}));
763 testing.expect(eql(u8, buf1[0..], [_]u8{0xfe}));
764764
765765 writeIntBig(i16, &buf2, -3);
766 testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0xff, 0xfd }));
766 testing.expect(eql(u8, buf2[0..], [_]u8{ 0xff, 0xfd }));
767767 writeIntLittle(i16, &buf2, -4);
768 testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0xfc, 0xff }));
769}
770
771pub fn hash_slice_u8(k: []const u8) u32 {
772 // FNV 32-bit hash
773 var h: u32 = 2166136261;
774 for (k) |b| {
775 h = (h ^ b) *% 16777619;
776 }
777 return h;
778}
779
780pub fn eql_slice_u8(a: []const u8, b: []const u8) bool {
781 return eql(u8, a, b);
768 testing.expect(eql(u8, buf2[0..], [_]u8{ 0xfc, 0xff }));
782769}
783770
784771/// Returns an iterator that iterates over the slices of `buffer` that are not