mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-06 04:36:36 +02:00
WIP - equalp with checks for circular lists
This commit is contained in:
parent
004c3c204b
commit
6794da5159
1 changed files with 37 additions and 0 deletions
37
runtime.c
37
runtime.c
|
@ -876,8 +876,18 @@ object memqp(void *data, object x, list l)
|
|||
return boolean_f;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
object equalp(object x, object y)
|
||||
{
|
||||
object slow_lis = x, fast_lis;
|
||||
int second_cycle = 0;
|
||||
|
||||
// if (Cyc_is_pair(x) == boolean_t &&
|
||||
// Cyc_is_pair(cdr(x)) == boolean_t){
|
||||
// fast_lis = cdr(x);
|
||||
// }
|
||||
|
||||
for (;; x = cdr(x), y = cdr(y)) {
|
||||
if (equal(x, y))
|
||||
return boolean_t;
|
||||
|
@ -885,8 +895,35 @@ object equalp(object x, object y)
|
|||
(x == NULL) || (y == NULL) ||
|
||||
type_of(x) != pair_tag || type_of(y) != pair_tag)
|
||||
return boolean_f;
|
||||
|
||||
// Both objects are lists at this point, compare cars
|
||||
if (boolean_f == equalp(car(x), car(y)))
|
||||
return boolean_f;
|
||||
|
||||
// // If there is no cycle, keep checking equality
|
||||
// if (fast_lis == NULL ||
|
||||
// Cyc_is_pair(fast_lis) == boolean_f ||
|
||||
// cdr(fast_lis) == NULL ||
|
||||
// Cyc_is_pair(cdr(fast_lis)) == boolean_f ||
|
||||
// cddr(fast_lis) == NULL){
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// // If there is a cycle, handle it
|
||||
// if (slow_lis == fast_lis) {
|
||||
// // if this is y, both lists have cycles and are equal, return #t
|
||||
// if (second_cycle)
|
||||
// return boolean_t;
|
||||
// // if this is x, keep going and check for a cycle in y
|
||||
// second_cycle = 1;
|
||||
// slow_lis = y;
|
||||
// if (Cyc_is_pair(y) == boolean_t) {
|
||||
// fast_lis = cdr(y);
|
||||
// }
|
||||
// continue;
|
||||
// }
|
||||
// slow_lis = cdr(slow_lis);
|
||||
// fast_lis = cddr(fast_lis);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue