@@ -71,14 +71,14 @@ pub fn McfGraph(comptime Cap: type, comptime Cost: type) type {
7171 pub fn init (allocator : Allocator , n : usize ) Self {
7272 return Self {
7373 .allocator = allocator ,
74- .edges = .init ( allocator ) ,
74+ .edges = .empty ,
7575 .n = n ,
7676 };
7777 }
7878
7979 /// Release all allocated memory.
8080 pub fn deinit (self : * Self ) void {
81- self .edges .deinit ();
81+ self .edges .deinit (self . allocator );
8282 }
8383
8484 /// Adds an edge oriented from `from` to `to` with capacity `cap` and cost `cost`.
@@ -105,7 +105,7 @@ pub fn McfGraph(comptime Cap: type, comptime Cost: type) type {
105105 assert (0 <= cap );
106106 assert (0 <= cost );
107107 const m = self .edges .items .len ;
108- try self .edges .append (Edge {
108+ try self .edges .append (self . allocator , Edge {
109109 .from = from ,
110110 .to = to ,
111111 .cap = cap ,
@@ -264,7 +264,7 @@ pub fn McfGraph(comptime Cap: type, comptime Cost: type) type {
264264 defer allocator .free (redge_idx );
265265
266266 var elist = try ArrayList (struct { usize , InsideEdge }).initCapacity (allocator , 2 * m );
267- defer elist .deinit ();
267+ defer elist .deinit (self . allocator );
268268 for (0.. m ) | i | {
269269 const e = self .edges .items [i ];
270270 edge_idx [i ] = degree [e .from ];
@@ -290,7 +290,7 @@ pub fn McfGraph(comptime Cap: type, comptime Cost: type) type {
290290 },
291291 });
292292 }
293- var g = try internal .Csr (InsideEdge ).init (allocator , n , elist , .zero );
293+ var g = try internal .Csr (InsideEdge ).init (allocator , n , elist . items , .zero );
294294 for (0.. m ) | i | {
295295 const e = self .edges .items [i ];
296296 edge_idx [i ] += g .start [e .from ];
@@ -315,8 +315,8 @@ pub fn McfGraph(comptime Cap: type, comptime Cost: type) type {
315315 var flow_current : Cap = 0 ;
316316 var cost_current : Cost = 0 ;
317317 var prev_cost_per_flow : Cost = -1 ;
318- var result = ArrayList (CapCostPair ). init ( allocator ) ;
319- try result .append (CapCostPair { 0 , 0 });
318+ var result : ArrayList (CapCostPair ) = .empty ;
319+ try result .append (self . allocator , CapCostPair { 0 , 0 });
320320 while (flow_current < flow_limit ) {
321321 if (! try self .refineDual (s , t , g , dual_dist , vis , prev_e )) {
322322 break ;
@@ -338,11 +338,11 @@ pub fn McfGraph(comptime Cap: type, comptime Cost: type) type {
338338 if (prev_cost_per_flow == d ) {
339339 _ = result .pop ();
340340 }
341- try result .append (CapCostPair { flow_current , cost_current });
341+ try result .append (self . allocator , CapCostPair { flow_current , cost_current });
342342 prev_cost_per_flow = d ;
343343 }
344344
345- break :blk try result .toOwnedSlice ();
345+ break :blk try result .toOwnedSlice (self . allocator );
346346 };
347347
348348 for (0.. m ) | i | {
@@ -390,13 +390,13 @@ pub fn McfGraph(comptime Cap: type, comptime Cost: type) type {
390390 return math .order (a .key , b .key );
391391 }
392392 };
393- var que_min = ArrayList (usize ). init ( allocator ) ;
394- defer que_min .deinit ();
393+ var que_min : ArrayList (usize ) = .empty ;
394+ defer que_min .deinit (self . allocator );
395395 var que = std .PriorityQueue (Q , void , Q .lessThan ).init (allocator , {});
396396 defer que .deinit ();
397397
398398 dual [s ].@"1" = 0 ;
399- try que_min .append (s );
399+ try que_min .append (self . allocator , s );
400400 while (que .count () > 0 or que_min .items .len > 0 ) {
401401 const v = que_min .pop () orelse que .remove ().to ;
402402 if (vis [v ]) {
@@ -418,7 +418,7 @@ pub fn McfGraph(comptime Cap: type, comptime Cost: type) type {
418418 dual [e .to ].@"1" = dist_to ;
419419 prev_e [e .to ] = e .rev ;
420420 if (dist_to == dist_v ) {
421- try que_min .append (e .to );
421+ try que_min .append (self . allocator , e .to );
422422 } else {
423423 try que .add (Q { .key = dist_to , .to = e .to });
424424 }
0 commit comments