Skip to content

Commit

Permalink
Remove appends.
Browse files Browse the repository at this point in the history
  • Loading branch information
q-uint committed Mar 3, 2022
1 parent c6b8a59 commit be7f60e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-set.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ let Package = { name : Text, version : Text, repo : Text, dependencies : List Te
let additions = [
{ name = "io"
, repo = "https://github.com/aviate-labs/io.mo"
, version = "v0.3.0"
, dependencies = ["base"]
, version = "v0.3.1"
, dependencies = [ "base" ]
}
] : List Package

Expand Down
10 changes: 5 additions & 5 deletions src/LFSR.mo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Array "mo:base/Array";
import Buffer "mo:base/Buffer";
import Int "mo:base/Int";
import IO "mo:io/IO";
import Iter "mo:base/Iter";
Expand Down Expand Up @@ -94,14 +94,14 @@ module {
let lfsr = feed;
var restarted = false;
public func read(n : Nat) : IO.Result<[T]> {
var ts : [T] = [];
let ts = Buffer.Buffer<T>(n);
for (i in Iter.range(0, n-1)) {
if (restarted) return #eof(ts);
if (restarted) return #eof(ts.toArray());
let (v, r) = lfsr.next();
restarted := r;
ts := Array.append<T>(ts, [v]);
ts.add(v);
};
#ok(ts);
#ok(ts.toArray());
};
};

Expand Down
9 changes: 4 additions & 5 deletions src/XorShift.mo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Array "mo:base/Array";
import Binary "mo:encoding/Binary";
import Buffer "mo:base/Buffer";
import Int "mo:base/Int";
Expand Down Expand Up @@ -40,7 +39,7 @@ module {
let xors = gen;
let bs = Buffer.Buffer<Nat8>(8);
public func read(n : Nat) : IO.Result<[Nat8]> {
var ts : [Nat8] = [];
let ts = Buffer.Buffer<Nat8>(n);
for (_ in Iter.range(0, n-1)) {
if (bs.size() == 0) {
for (b in Binary.BigEndian.fromNat64(gen.next()).vals()) {
Expand All @@ -49,12 +48,12 @@ module {
};
switch (bs.removeLast()) {
case (? v) {
ts := Array.append<Nat8>(ts, [v]);
ts.add(v);
};
case (null) return #eof(ts);
case (null) return #eof(ts.toArray());
};
};
#ok(ts);
#ok(ts.toArray());
};
};
};

0 comments on commit be7f60e

Please sign in to comment.