long int pair_ordinal(V p) { if (getType(p) != T_PAIR) { return 0; } int o1 = pair_ordinal(toFirst(p)); int o2 = pair_ordinal(toSecond(p)); return (o1 > o2 ? o1 : o2) + 1; }
bool persist_collect_(V original, HashMap *hm) { int type = getType(original); HashMap *hmv; Bucket *b; int i; if (type == T_SCOPE || type == T_FUNC || type == T_CFUNC) { return false; } if (get_hashmap(hm, original) != NULL) { return true; } set_hashmap(hm, original, intToV(-pair_ordinal(original)-1)); switch(type) { case T_STR: case T_IDENT: case T_NUM: case T_FRAC: break; case T_LIST: for (i = 0; i < toStack(original)->used; i++) { if (!persist_collect_(toStack(original)->nodes[i], hm)) { return false; } } break; case T_DICT: hmv = toHashMap(original); if (hmv->map != NULL) { for (i = 0; i < hmv->size; i++) { b = hmv->map[i]; while(b != NULL) { if (!persist_collect_(b->key, hm) ||!persist_collect_(b->value, hm)) { return false; } b = b->next; } } } break; case T_PAIR: if (!persist_collect_(toFirst(original), hm) || !persist_collect_(toSecond(original), hm)) return false; break; } return true; }