From 0947abe4f45074fac4dbff49d6f33e1ff9dc5d69 Mon Sep 17 00:00:00 2001 From: Martin Wickham Date: Tue, 23 Nov 2021 23:08:22 -0600 Subject: [PATCH] Add shared util.zig file --- src/day01.zig | 4 ++-- src/day02.zig | 4 ++-- src/day03.zig | 4 ++-- src/day04.zig | 4 ++-- src/day05.zig | 4 ++-- src/day06.zig | 4 ++-- src/day07.zig | 4 ++-- src/day08.zig | 4 ++-- src/day09.zig | 4 ++-- src/day10.zig | 4 ++-- src/day11.zig | 4 ++-- src/day12.zig | 4 ++-- src/day13.zig | 4 ++-- src/day14.zig | 4 ++-- src/day15.zig | 4 ++-- src/day16.zig | 4 ++-- src/day17.zig | 4 ++-- src/day18.zig | 4 ++-- src/day19.zig | 4 ++-- src/day20.zig | 4 ++-- src/day21.zig | 4 ++-- src/day22.zig | 4 ++-- src/day23.zig | 4 ++-- src/day24.zig | 4 ++-- src/day25.zig | 4 ++-- src/util.zig | 13 +++++++++++++ 26 files changed, 63 insertions(+), 50 deletions(-) create mode 100644 src/util.zig diff --git a/src/day01.zig b/src/day01.zig index 80e89e2..ba223e9 100644 --- a/src/day01.zig +++ b/src/day01.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day01.txt"); diff --git a/src/day02.zig b/src/day02.zig index 9e7b6ed..0b9592a 100644 --- a/src/day02.zig +++ b/src/day02.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day02.txt"); diff --git a/src/day03.zig b/src/day03.zig index 84310cc..63d18c0 100644 --- a/src/day03.zig +++ b/src/day03.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day03.txt"); diff --git a/src/day04.zig b/src/day04.zig index e944570..09eb9cb 100644 --- a/src/day04.zig +++ b/src/day04.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day04.txt"); diff --git a/src/day05.zig b/src/day05.zig index 809f9d2..c140c3a 100644 --- a/src/day05.zig +++ b/src/day05.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day05.txt"); diff --git a/src/day06.zig b/src/day06.zig index 308a012..1850184 100644 --- a/src/day06.zig +++ b/src/day06.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day06.txt"); diff --git a/src/day07.zig b/src/day07.zig index 9598e17..35ae37a 100644 --- a/src/day07.zig +++ b/src/day07.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day07.txt"); diff --git a/src/day08.zig b/src/day08.zig index ab2869c..b3ad817 100644 --- a/src/day08.zig +++ b/src/day08.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day08.txt"); diff --git a/src/day09.zig b/src/day09.zig index 6b78080..ac6d11e 100644 --- a/src/day09.zig +++ b/src/day09.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day09.txt"); diff --git a/src/day10.zig b/src/day10.zig index c501b71..550f889 100644 --- a/src/day10.zig +++ b/src/day10.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day10.txt"); diff --git a/src/day11.zig b/src/day11.zig index 913ae0c..5939986 100644 --- a/src/day11.zig +++ b/src/day11.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day11.txt"); diff --git a/src/day12.zig b/src/day12.zig index 9ee965f..4754a18 100644 --- a/src/day12.zig +++ b/src/day12.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day12.txt"); diff --git a/src/day13.zig b/src/day13.zig index 7309e9b..b6c3459 100644 --- a/src/day13.zig +++ b/src/day13.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day13.txt"); diff --git a/src/day14.zig b/src/day14.zig index 194bfdd..719a6ac 100644 --- a/src/day14.zig +++ b/src/day14.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day14.txt"); diff --git a/src/day15.zig b/src/day15.zig index 0ee0434..255896c 100644 --- a/src/day15.zig +++ b/src/day15.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day15.txt"); diff --git a/src/day16.zig b/src/day16.zig index f67c08f..92642b7 100644 --- a/src/day16.zig +++ b/src/day16.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day16.txt"); diff --git a/src/day17.zig b/src/day17.zig index 57fcdb8..1cb647d 100644 --- a/src/day17.zig +++ b/src/day17.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day17.txt"); diff --git a/src/day18.zig b/src/day18.zig index ea6a8a3..aac11d7 100644 --- a/src/day18.zig +++ b/src/day18.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day18.txt"); diff --git a/src/day19.zig b/src/day19.zig index 38ba985..90d7d75 100644 --- a/src/day19.zig +++ b/src/day19.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day19.txt"); diff --git a/src/day20.zig b/src/day20.zig index 245feea..c0e7e11 100644 --- a/src/day20.zig +++ b/src/day20.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day20.txt"); diff --git a/src/day21.zig b/src/day21.zig index 53c24af..0241c6e 100644 --- a/src/day21.zig +++ b/src/day21.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day21.txt"); diff --git a/src/day22.zig b/src/day22.zig index 0dfe19b..820d4c8 100644 --- a/src/day22.zig +++ b/src/day22.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day22.txt"); diff --git a/src/day23.zig b/src/day23.zig index dfffed4..59cf2a9 100644 --- a/src/day23.zig +++ b/src/day23.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day23.txt"); diff --git a/src/day24.zig b/src/day24.zig index 75a0a00..b74efb3 100644 --- a/src/day24.zig +++ b/src/day24.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day24.txt"); diff --git a/src/day25.zig b/src/day25.zig index 09cd674..3343eb0 100644 --- a/src/day25.zig +++ b/src/day25.zig @@ -7,8 +7,8 @@ const HashMap = std.AutoHashMap; const StringHashMap = std.StringHashMap; const BitSet = std.DynamicBitSet; -var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; -const gpa = &gpa_impl.allocator; +const util = @import("util.zig"); +const gpa = util.gpa; const data = @embedFile("../data/day25.txt"); diff --git a/src/util.zig b/src/util.zig new file mode 100644 index 0000000..09534fa --- /dev/null +++ b/src/util.zig @@ -0,0 +1,13 @@ +const std = @import("std"); +const Allocator = std.mem.Allocator; +const assert = std.debug.assert; +const print = std.debug.print; +const ArrayList = std.ArrayList; +const HashMap = std.AutoHashMap; +const StringHashMap = std.StringHashMap; +const BitSet = std.DynamicBitSet; + +var gpa_impl = std.heap.GeneralPurposeAllocator(.{}){}; +pub const gpa = &gpa_impl.allocator; + +// Add utility functions here