Update .len for subarray to not require ()

This commit is contained in:
Christoffer Lerno
2021-09-10 19:44:27 +02:00
parent 0aef2810c8
commit b7e423adc2
11 changed files with 23 additions and 34 deletions

View File

@@ -46,7 +46,7 @@ func void encode(char[] in, char *out)
{
int j = 0;
char c = LUT_ENC[1];
for (int i = 0; i < in.len(); i++)
for (int i = 0; i < in.len; i++)
{
switch (i % 3)
{
@@ -61,7 +61,7 @@ func void encode(char[] in, char *out)
}
// move back
usize last = in.len() - 1;
usize last = in.len - 1;
// check the last and add padding
switch (last % 3)
{
@@ -80,7 +80,7 @@ func int! decode(char[] in, char* out, int* invalid_char_index = null)
{
int j = 0;
for (int i = 0; i < in.len(); i++)
for (int i = 0; i < in.len; i++)
{
char value = in[i];
if (value == PAD) return j;
@@ -100,13 +100,13 @@ func int! decode(char[] in, char* out, int* invalid_char_index = null)
case 1:
out[j++] += c >> 4 & 0x3;
// if not last char with padding
if (i < (in.len() - 3) || in[(long)(in.len()) - 2] != PAD)
if (i < (in.len - 3) || in[(long)(in.len) - 2] != PAD)
{
out[j] = (c & 0xF) << 4;
}
case 2:
out[j++] += c >> 2 & 0xF;
if (i < (in.len() - 2) || in[(long)(in.len()) - 1] != PAD)
if (i < (in.len - 2) || in[(long)(in.len) - 1] != PAD)
{
out[j] = (c & 0x3) << 6;
}

View File

@@ -57,7 +57,7 @@ const LINELEN = 60;
// slowest character-at-a-time output
func void repeat_fasta(char[] seq, int n)
{
usize len = seq.len();
usize len = seq.len;
int i = void;
for (i = 0; i < n; i++)
{
@@ -69,8 +69,8 @@ func void repeat_fasta(char[] seq, int n)
func void random_fasta(char[] symb, double[] probability, int n)
{
assert(symb.len() == probability.len());
int len = (int)(probability.len());
assert(symb.len == probability.len);
int len = probability.len;
int i = void;
for (i = 0; i < n; i++)
{

View File

@@ -15,7 +15,7 @@ struct Planet
func void advance(Planet[] bodies) @noinline
{
usize nbodies = bodies.len();
usize nbodies = bodies.len;
foreach (i, Planet* &b : bodies)
{
for (usize j = i + 1; j < nbodies; j++)
@@ -45,7 +45,7 @@ func void advance(Planet[] bodies) @noinline
func double energy(Planet[] bodies)
{
double e;
usize nbodies = bodies.len();
usize nbodies = bodies.len;
foreach (i, Planet* &b : bodies)
{

View File

@@ -4,8 +4,8 @@ func int levenshtein(String s, String t)
{
// if either string is empty, difference is inserting all chars
// from the other
if (!s.len()) return t.len();
if (!t.len()) return s.len();
if (!s.len) return t.len;
if (!t.len) return s.len;
// if last letters are the same, the difference is whatever is
// required to edit the rest of the strings

View File

@@ -101,7 +101,7 @@ func void testArrays()
{
printf("index[%d]: %d\n", i, a);
}
printf("Length is a runtime value: %d\n", y.len());
printf("Length is a runtime value: %d\n", y.len);
puts("Getting a slice from the beginning to an offset of the end---");
y = x[..^2]; // Same as x[0..^2]
foreach (i, a : y)

View File

@@ -26,9 +26,9 @@ struct TopoList
public func void sort(InputPair[] pairs, uint elements)
{
printf(.x = "fe");
InputPair[] result = @array::make(InputPair, pairs.len());
InputPair[] result = @array::make(InputPair, pairs.len);
TopoList* top = mem::calloc(TopoList.sizeof, elements);
for (int i = 0; i < pairs.len(); i++)
for (int i = 0; i < pairs.len; i++)
{
InputPair pair = pairs[i];
assert(pair.value >= 0 && pair.value < elements);