Merge pull request #1104 from urbit/jet-del-by

Add a jet for +del:by
This commit is contained in:
Elliot Glaysher 2018-12-13 11:41:07 -08:00 committed by GitHub
commit 16f346809a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 117 additions and 1 deletions

View File

@ -1 +1 @@
6a1f32bb1984fa9329c072de09ba67b212c8dbed
00c79de3df4ecae9f499053990471d420f0e79a0

View File

@ -79,6 +79,7 @@
/** Tier 4.
**/
u3_noun u3wdb_bif(u3_noun);
u3_noun u3wdb_del(u3_noun);
u3_noun u3wdb_dif(u3_noun);
u3_noun u3wdb_gas(u3_noun);
u3_noun u3wdb_get(u3_noun);

111
jets/d/by_del.c Normal file
View File

@ -0,0 +1,111 @@
/* j/4/by_del.c
**
*/
#include "all.h"
/* functions
*/
static u3_noun
_rebalance(u3_noun a)
{
u3_noun l_a, n_a, r_a;
if ( c3n == u3r_trel(a, &n_a, &l_a, &r_a) ) {
return u3m_bail(c3__exit);
}
else {
if ( u3_nul == l_a) {
return u3k(r_a);
}
else if ( u3_nul == r_a) {
return u3k(l_a);
}
else {
u3_noun n_l_a, l_l_a, r_l_a;
u3_noun n_r_a, l_r_a, r_r_a;
if ( (c3n == u3r_trel(l_a, &n_l_a, &l_l_a, &r_l_a) ) ||
(c3n == u3r_trel(r_a, &n_r_a, &l_r_a, &r_r_a) ) ||
(c3n == u3du(n_l_a)) ||
(c3n == u3du(n_r_a)) ) {
return u3m_bail(c3__exit);
}
else {
if ( c3y == u3qc_vor(u3h(n_l_a), u3h(n_r_a)) ) {
u3_noun new_right = u3nt(u3k(n_a),
u3k(r_l_a),
u3k(r_a));
u3_noun ret = u3nt(u3k(n_l_a),
u3k(l_l_a),
_rebalance(new_right));
u3z(new_right);
return ret;
}
else {
u3_noun new_left = u3nt(u3k(n_a),
u3k(l_a),
u3k(l_r_a));
u3_noun ret = u3nt(u3k(n_r_a),
_rebalance(new_left),
u3k(r_r_a));
u3z(new_left);
return ret;
}
}
}
}
}
u3_noun
u3qdb_del(u3_noun a,
u3_noun b)
{
if ( u3_nul == a ) {
return u3_nul;
}
else {
u3_noun l_a, n_a, r_a, pn_a, qn_a;
if ( (c3n == u3r_trel(a, &n_a, &l_a, &r_a)) ||
(c3n == u3r_cell(n_a, &pn_a, &qn_a)) )
{
return u3m_bail(c3__exit);
}
else if ( c3n == u3r_sing(pn_a, b) ) {
if ( c3y == u3qc_gor(b, pn_a) ) {
return u3nt(u3k(n_a),
u3qdb_del(l_a, b),
u3k(r_a));
}
else {
return u3nt(u3k(n_a),
u3k(l_a),
u3qdb_del(r_a, b));
}
}
else {
return _rebalance(a);
}
}
}
u3_noun
u3wdb_del(u3_noun cor)
{
u3_noun a, b;
if ( c3n == u3r_mean(cor, u3x_sam, &b,
u3x_con_sam, &a, 0) ) {
return u3m_bail(c3__exit);
}
else {
u3_noun n = u3qdb_del(a, b);
return n;
}
}

View File

@ -892,6 +892,8 @@ static c3_c* _141_two__in_ha[] = {0};
static u3j_harm _141_two__by_bif_a[] = {{".2", u3wdb_bif, c3y}, {}};
static c3_c* _141_two__by_bif_ha[] = {0};
static u3j_harm _141_two__by_del_a[] = {{".2", u3wdb_del, c3y}, {}};
static c3_c* _141_two__by_del_ha[] = {0};
static u3j_harm _141_two__by_dif_a[] = {{".2", u3wdb_dif, c3y}, {}};
static c3_c* _141_two__by_dif_ha[] = {0};
static u3j_harm _141_two__by_gas_a[] = {{".2", u3wdb_gas, c3y}, {}};
@ -918,6 +920,7 @@ static c3_c* _141_two__in_ha[] = {0};
static u3j_core _141_two__by_d[] =
{ { "bif", 7, _141_two__by_bif_a, 0, _141_two__by_bif_ha },
{ "del", 7, _141_two__by_del_a, 0, _141_two__by_del_ha },
{ "dif", 7, _141_two__by_dif_a, 0, _141_two__by_dif_ha },
{ "gas", 7, _141_two__by_gas_a, 0, _141_two__by_gas_ha },
{ "get", 7, _141_two__by_get_a, 0, _141_two__by_get_ha },

View File

@ -90,6 +90,7 @@ jets_d_src = [
'jets/d/in_wyt.c',
'jets/d/in_bif.c',
'jets/d/in_dif.c',
'jets/d/by_del.c',
'jets/d/by_gas.c',
'jets/d/by_get.c',
'jets/d/by_has.c',