 ! Copyright (C) 2008 Eric Mertens.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays hints kernel locals math hashtables
-assocs fry sequences ;
+USING: accessors assocs fry hashtables kernel locals math
+sequences ;
 FROM: assocs => change-at ;
 IN: disjoint-sets
 


<PRIVATE

: count ( a disjoint-set -- n )
    counts>> at ; inline

: add-count ( p a disjoint-set -- )
    [ count [ + ] curry ] keep counts>> swap change-at ; inline

: parent ( a disjoint-set -- p )
    parents>> at ; inline

: set-parent ( p a disjoint-set -- )
    parents>> set-at ; inline


GENERIC: equiv-set-size ( a disjoint-set -- n )

M: disjoint-set equiv-set-size
    [ representative ] keep counts>> at ;

GENERIC: equiv? ( a b disjoint-set -- ? )

