Add fast assoc by cdr

This commit is contained in:
Justin Ethier 2018-02-14 13:00:43 -05:00
parent 488b6e162c
commit 2cd96058eb
2 changed files with 17 additions and 0 deletions

View file

@ -159,6 +159,7 @@ object memberp(void *data, object x, list l);
object memqp(void *data, object x, list l);
list assq(void *data, object x, list l);
list assoc(void *data, object x, list l);
list assoc_cdr(void *data, object x, list l);
/**@}*/
/**

View file

@ -1174,6 +1174,22 @@ list assoc(void *data, object x, list l)
}
return boolean_f;
}
/**
* Same as assoc but check the cdr of each item for equality
*/
list assoc_cdr(void *data, object x, list l)
{
if ((l == NULL) || is_value_type(l) || type_of(l) != pair_tag)
return boolean_f;
for (; (l != NULL); l = cdr(l)) {
list la = car(l);
Cyc_check_pair(data, la);
if (boolean_f != equalp(x, cdr(la)))
return la;
}
return boolean_f;
}
/* END member and assoc */
// Internal function, do not use this anywhere outside the runtime