nominolo / union-find

Efficient union and equivalence testing of sets.
Other
30 stars 12 forks source link

can you derive ord for point? #12

Open MarisaKirisame opened 5 years ago

MarisaKirisame commented 5 years ago

I need to use point as key for a map.

Javran commented 4 years ago

Same question here. Not sure whether it's doable though since STRef and IORef doesn't have Ord instance. For now my workaround relies on Ord instance of the descriptor:

cluster :: Ord a => [(UF.Point s a, b)] -> ST s (M.Map a [b])
cluster pairs =
  (M.map ($ []) . M.fromListWith (flip (.)))
    <$> mapM
      ( \(uf, c) -> do
          cRep <- UF.descriptor =<< UF.repr uf
          pure (cRep, (c :))
      )
      pairs

in which pairs is the list of Points, zipped with data you want to attach to those points respectively.