Skip to content

Commit

Permalink
Aor jet (#690)
Browse files Browse the repository at this point in the history
`++aor` jet. 10x speed up with this input:

```hoon
(aor 'aaaaaaaaaaaaaaaa' 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
```
  • Loading branch information
pkova authored Sep 25, 2024
2 parents 3761ed0 + d242217 commit ded901f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
69 changes: 69 additions & 0 deletions pkg/noun/jets/c/aor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/// @file

#include "jets/q.h"
#include "jets/w.h"

#include "noun.h"

u3_noun
u3qc_aor(u3_noun a,
u3_noun b)
{
while ( 1 ) {
if ( c3y == u3r_sing(a, b) ) return c3y;
if ( c3n == u3ud(a) ) {
if ( c3y == u3ud(b) ) return c3n;
if ( c3y == u3r_sing(u3h(a), u3h(b)) ) {
a = u3t(a);
b = u3t(b);
}
else {
a = u3h(a);
b = u3h(b);
}
}
else {
if ( c3n == u3ud(b) ) return c3y;
{
c3_w len_a_w = u3r_met(3, a);
c3_w len_b_w = u3r_met(3, b);;
c3_y *buf_a_y, *buf_b_y;
c3_y cut_a_y, cut_b_y;
if ( c3y == u3a_is_cat(a) ) {
buf_a_y = (c3_y*)&a;
}
else {
u3a_atom* a_u = u3a_to_ptr(a);
buf_a_y = (c3_y*)(a_u->buf_w);
}
if ( c3y == u3a_is_cat(b) ) {
buf_b_y = (c3_y*)&b;
}
else {
u3a_atom* b_u = u3a_to_ptr(b);
buf_b_y = (c3_y*)(b_u->buf_w);
}
c3_w len_min_w = c3_min(len_a_w, len_b_w);
for (c3_w i_w = 0; i_w < len_min_w; i_w++) {
cut_a_y = buf_a_y[i_w];
cut_b_y = buf_b_y[i_w];
if ( cut_a_y != cut_b_y ) return __(cut_a_y < cut_b_y);
}
return __(len_a_w < len_b_w);
}
}
}
}

u3_noun
u3wc_aor(u3_noun cor)
{
u3_noun a, b;

if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ) {
return u3m_bail(c3__exit);
} else {
return u3qc_aor(a, b);
}
}

1 change: 1 addition & 0 deletions pkg/noun/jets/q.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

/** Tier 3.
**/
u3_noun u3qc_aor(u3_atom, u3_atom);
u3_noun u3qc_bex(u3_atom);
u3_noun u3qc_xeb(u3_atom);
u3_noun u3qc_can(u3_atom, u3_noun);
Expand Down
3 changes: 3 additions & 0 deletions pkg/noun/jets/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -2463,6 +2463,8 @@ static u3j_core _138_two__by_d[] =

static u3j_harm _138_two_mate_a[] = {{".2", u3wb_mate, c3y}, {}};

static u3j_harm _138_two_aor_a[] = {{".2", u3wc_aor, c3y}, {}};

static u3j_core _138_two_d[] =
{ { "tri", 3, 0, _138_tri_d, no_hashes, _140_tri_ho },

Expand All @@ -2489,6 +2491,7 @@ static u3j_core _138_two_d[] =
{ "welp", 7, _140_two_welp_a, 0, no_hashes },
{ "zing", 7, _140_two_zing_a, 0, no_hashes },

{ "aor", 7, _138_two_aor_a, 0, no_hashes },
{ "bex", 7, _140_two_bex_a, 0, no_hashes },
{ "cat", 7, _140_two_cat_a, 0, no_hashes },
{ "can", 7, _140_two_can_a, 0, no_hashes },
Expand Down
1 change: 1 addition & 0 deletions pkg/noun/jets/w.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

/** Tier 3.
**/
u3_noun u3wc_aor(u3_noun);
u3_noun u3wc_bex(u3_noun);
u3_noun u3wc_xeb(u3_noun);
u3_noun u3wc_can(u3_noun);
Expand Down

0 comments on commit ded901f

Please sign in to comment.