mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 04:25:06 +02:00
Add fast assoc by cdr
This commit is contained in:
parent
488b6e162c
commit
2cd96058eb
2 changed files with 17 additions and 0 deletions
|
@ -159,6 +159,7 @@ object memberp(void *data, object x, list l);
|
||||||
object memqp(void *data, object x, list l);
|
object memqp(void *data, object x, list l);
|
||||||
list assq(void *data, object x, list l);
|
list assq(void *data, object x, list l);
|
||||||
list assoc(void *data, object x, list l);
|
list assoc(void *data, object x, list l);
|
||||||
|
list assoc_cdr(void *data, object x, list l);
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
16
runtime.c
16
runtime.c
|
@ -1174,6 +1174,22 @@ list assoc(void *data, object x, list l)
|
||||||
}
|
}
|
||||||
return boolean_f;
|
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 */
|
/* END member and assoc */
|
||||||
|
|
||||||
// Internal function, do not use this anywhere outside the runtime
|
// Internal function, do not use this anywhere outside the runtime
|
||||||
|
|
Loading…
Add table
Reference in a new issue