Efficient nondestructive equality checking for trees and graphs

  • Authors:
  • Michael D. Adams;R. Kent Dybvig

  • Affiliations:
  • Indiana University, Bloomington, IN, USA;Indiana University, Bloomington, IN, USA

  • Venue:
  • Proceedings of the 13th ACM SIGPLAN international conference on Functional programming
  • Year:
  • 2008

Quantified Score

Hi-index 0.00

Visualization

Abstract

The Revised6 Report on Scheme requires its generic equivalence predicate, equal?, to terminate even on cyclic inputs. While the terminating equal? can be implemented via a DFA-equivalence or union-find algorithm, these algorithms usually require an additional pointer to be stored in each object, are not suitable for multithreaded code due to their destructive nature, and may be unacceptably slow for the small acyclic values that are the most likely inputs to the predicate. This paper presents a variant of the union-find algorithm for equal? that addresses these issues. It performs well on large and small, cyclic and acyclic inputs by interleaving a low-overhead algorithm that terminates only for acyclic inputs with a more general algorithm that handles cyclic inputs. The algorithm terminates for all inputs while never being more than a small factor slower than whichever of the acyclic or union-find algorithms would have been faster. Several intermediate algorithms are also presented, each of which might be suitable for use in a particular application, though only the final algorithm is suitable for use in a library procedure, like equal?, that must work acceptably well for all inputs.