public void TestStrLstPerformance() { var watch = new System.Diagnostics.Stopwatch(); watch.Start(); var sb = Lst.Empty<string>(); for (int i = 0; i < this.nAppends; i++) sb = Lst.Cons("Foo", sb); var strBuilderAppendTime = watch.ElapsedMilliseconds; var strBuilderResult = sb.Concat(); var strBuilderResultTime = watch.ElapsedMilliseconds; }
private Lst<FloorNum> StopAt(FloorNum floor, FloorNum now, Lst<FloorNum> stops) { return StopAt(floor, Lst<FloorNum>.nil, stops.Cons(now)).Tl(); //NB: we take the tail to avoid restopping at now. }
private Lst<FloorNum> StopAt(FloorNum floor, Lst<FloorNum> before, Lst<FloorNum> stops) { if (stops.Null()) { return before.Cons(floor).Reverse(); } if (floor == stops.Hd()) { return before.ReverseAppend(stops); } if (!stops.Tl().Null()) { FloorNum X = stops.Hd(); FloorNum Y = stops.Tl().Hd(); Lst<FloorNum> afterXY = stops.Tl().Tl(); if (X < floor && floor < Y) { return before.ReverseAppend(afterXY.Cons(Y).Cons(floor).Cons(X)); } if (Y < floor && floor < X) { return before.ReverseAppend(afterXY.Cons(Y).Cons(floor).Cons(X)); } } return StopAt(floor, before.Cons(stops.Hd()), stops.Tl()); }
private Lst<FloorNum> Insert(Dir dir, FloorNum floor, FloorNum now, Lst<FloorNum> before, Lst<FloorNum> stop) { if (stop.Null()) { return before.Cons(floor).Reverse(); } FloorNum next = stop.Hd(); Lst<FloorNum> after = stop.Tl(); if (floor == next) { return before.ReverseAppend(stop); } if (floor == now) { return before.ReverseAppend(stop); } if (dir == Dir.Up && now < floor && floor < next) { return before.ReverseAppend(stop.Cons(floor)); } if (dir == Dir.Down && next < floor && floor < now) { return before.ReverseAppend(stop.Cons(floor)); } return Insert(dir, floor, next, before.Cons(next), after); }