Skip to content

Commit

Permalink
Updated with changes to stdlib.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Jan 17, 2024
1 parent e103aad commit 9c364f2
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 39 deletions.
6 changes: 3 additions & 3 deletions day12.c3
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn WalkedMap* Map.create_temp_empty_walked_map(Map* map)
{
usz height = map.map.len();
usz width = map.map.get(0).len;
WalkedMap *w = mem::new_temp(WalkedMap);
WalkedMap *w = mem::temp_new(WalkedMap);
w.walked = tcalloc(int.sizeof * height * width);
w.size = { (int)width, (int)height };
return w;
Expand Down Expand Up @@ -67,8 +67,8 @@ fn Map* load_heightmap()
{
File f = file::open("heightmap.txt", "rb")!!;
defer (void)f.close();
Map* map = mem::new(Map);
map.map.init_new();
Map* map = mem::alloc(Map);
map.map.new_init();
while (!f.eof())
{
@pool()
Expand Down
31 changes: 15 additions & 16 deletions day13.c3
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ fn int parse_list(void* list1, String list_inner)
if (c < '0' || c > '9') break;
index++;
}
PacketElement* element = mem::new(PacketElement);
*element = { .is_subpacket = false, .value = list_inner[start..(index - 1)].to_int()!! };
PacketElement* element = mem::new(PacketElement, { .is_subpacket = false, .value = list_inner[start..(index - 1)].to_int()!! });
packet.append(element);
if (index == len) return len;
if (c == ']') return index + 1;
Expand All @@ -85,9 +84,9 @@ fn int parse_list(void* list1, String list_inner)
if (c == ']') return index + 1;
assert(c == '[');
index++;
PacketElement* element = mem::new(PacketElement);
Packet* inner_list = mem::new(Packet);
inner_list.init_new();
PacketElement* element = mem::alloc(PacketElement);
Packet* inner_list = mem::alloc(Packet);
inner_list.new_init();
index += parse_list(inner_list, list_inner[index..]);
*element = { .is_subpacket = true, .packet = inner_list };
packet.append(element);
Expand All @@ -103,17 +102,17 @@ fn int parse_list(void* list1, String list_inner)
fn Packet* packet_from_line(String line)
{
assert(line[0] == '[' && line[^1] == ']');
Packet* packet = mem::new(Packet);
packet.init_new();
Packet* packet = mem::alloc(Packet);
packet.new_init();
parse_list(packet, line[1..]);
return packet;
}
fn PacketPairs* load_packets()
{
File f = file::open("packets.txt", "rb")!!;
defer (void)f.close();
PacketPairs* packet = mem::new(PacketPairs);
packet.init_new();
PacketPairs* packet = mem::alloc(PacketPairs);
packet.new_init();
while (!f.eof())
{
@pool()
Expand Down Expand Up @@ -207,13 +206,13 @@ fn void insert_packet(PacketList* list, Packet* new_packet)

fn Packet* create_div(int value)
{
Packet* packet = mem::new(Packet);
packet.init_new();
PacketElement* element = mem::new(PacketElement);
Packet* inner_packet = mem::new(Packet);
Packet* packet = mem::alloc(Packet);
packet.new_init();
PacketElement* element = mem::alloc(PacketElement);
Packet* inner_packet = mem::alloc(Packet);
*element = { .is_subpacket = true, .packet = inner_packet };
inner_packet.init_new();
PacketElement* element_inner = mem::new(PacketElement);
inner_packet.new_init();
PacketElement* element_inner = mem::alloc(PacketElement);
*element_inner = { .value = value };
inner_packet.append(element_inner);
packet.append(element);
Expand All @@ -222,7 +221,7 @@ fn Packet* create_div(int value)
fn void part2(PacketPairs* packets)
{
PacketList queue;
queue.init_new();
queue.new_init();
foreach NEXT: (pair : *packets)
{
insert_packet(&queue, pair.p1);
Expand Down
4 changes: 2 additions & 2 deletions day15.c3
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn CoordPairList load_sensors()
File f = file::open("sensor.txt", "rb")!!;
defer (void)f.close();
CoordPairList list;
list.init_new();
list.new_init();
while (!f.eof())
{
@pool()
Expand Down Expand Up @@ -50,7 +50,7 @@ fn void part1(CoordPairList list)
if (i == 0 || max > max_x) max_x = max;
}
int width = max_x - min_x + 1;
bool[] array = mem::temp_zero_array(bool, width);
bool[] array = mem::temp_new_array(bool, width);
foreach (pair : list)
{
int[<2>] sensor_at = pair[0];
Expand Down
2 changes: 1 addition & 1 deletion day16.c3
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn void part2(Valve[] valves, int start)

fn void main()
{
v.init_new();
v.new_init();
int start = -1;
Valve[] valves = load_valves(&&Valve[100] {});
foreach (int i, valve : valves)
Expand Down
2 changes: 1 addition & 1 deletion day17.c3
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ fn void solve(String winds, long rocks)
isz wind_index = 0;
long offset = 0;
StateCacheMap map;
map.init_new(1024);
map.new_init(1024);
long max = rocks;
bool check_cache = true;
long desired_drops = rocks;
Expand Down
2 changes: 1 addition & 1 deletion day19.c3
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct GameState
fn void load_blueprints()
{
File f = file::open("blueprint.txt", "rb")!!;
blueprints.init_new();
blueprints.new_init();
defer (void)f.close();
while (!f.eof())
{
Expand Down
4 changes: 2 additions & 2 deletions day20.c3
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ fn void solve(int key, int mixes)
{
LongList list;
LongList pos;
list.init_new();
pos.init_new();
list.new_init();
pos.new_init();
defer pos.free();
defer list.free();
load_crypto(&list, &pos, key);
Expand Down
4 changes: 2 additions & 2 deletions day21.c3
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn void load_monkeys(MonkeyList* list, MonkeyId* root_index, MonkeyId *humn_inde
File f = file::open("monkeys.txt", "rb")!!;
defer (void)f.close();
NameMap map;
map.init_new();
map.new_init();
defer map.free();
MonkeyId index = 0;
while (!f.eof())
Expand Down Expand Up @@ -177,7 +177,7 @@ fn void part2(Monkey* root, Monkey* humn)
fn void main()
{
MonkeyList list;
list.init_new();
list.new_init();
MonkeyId root_index;
MonkeyId humn_index;
load_monkeys(&list, &root_index, &humn_index);
Expand Down
6 changes: 3 additions & 3 deletions day23.c3
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn void load_map(CharsArray* list)
list.append(line.tconcat((String)&spacing).copy());
};
}
String top_line = (String)mem::new_array(char, width + PADDING * 2);
String top_line = (String)mem::alloc_array(char, width + PADDING * 2);
top_line[..] = '.';
for (int i = 0; i < PADDING; i++)
{
Expand Down Expand Up @@ -187,7 +187,7 @@ fn void count_empty_tiles(CharsArray list)
fn void part1()
{
CharsArray list;
list.init_new();
list.new_init();
load_map(&list);
for (int i = 0; i < 10; i++)
{
Expand All @@ -199,7 +199,7 @@ fn void part1()
fn void part2()
{
CharsArray list;
list.init_new();
list.new_init();
load_map(&list);
for (int i = 0;; i++)
{
Expand Down
6 changes: 3 additions & 3 deletions day3.c3
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn void part1()
@pool()
{
CharSet set;
set.init_temp();
set.temp_init();
set.clear();
String line = io::treadline(&f)!!;
assert(line.len % 2 == 0 && line.len > 0);
Expand Down Expand Up @@ -56,8 +56,8 @@ fn void part2()
{
CharSet set;
CharSet set2;
set.init_temp();
set2.init_temp();
set.temp_init();
set2.temp_init();
String line1 = io::treadline(&f)!!;
String line2 = io::treadline(&f)!!;
String line3 = io::treadline(&f)!!;
Expand Down
2 changes: 1 addition & 1 deletion day5.c3
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const MAX_PILES = 20;

fn int init_piles(CharList[MAX_PILES]* piles, File* f)
{
foreach (CharList* &list : piles) list.init_new();
foreach (CharList* &list : piles) list.new_init();
int piles_used = 0;
while (!f.eof())
{
Expand Down
3 changes: 1 addition & 2 deletions day7.c3
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ fn void parse_dir(Directory *top)
}
if (line[0..2] == "dir")
{
Directory *new_dir = mem::new_temp(Directory);
*new_dir = { .name = line[4..], .parent_dir = current_dir };
Directory *new_dir = mem::temp_new(Directory, { .name = line[4..], .parent_dir = current_dir });
current_dir.other_dirs.append(new_dir);
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions day8.c3
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ fn Forest* parse_forest()
{
File f = file::open("forest.txt", "rb")!!;
defer (void)f.close();
Forest* forest = mem::new(Forest);
forest.init_new(512);
Forest* forest = mem::alloc(Forest);
forest.new_init(512);
while (!f.eof())
{
String line = io::treadline(&f)!!;
Expand Down

0 comments on commit 9c364f2

Please sign in to comment.