Comments (5)
Hi @lewismj , I was about to open the a PR with the functionality for disjoint sets when I found yours. I wanted to bring into dogs the implementation I published at
https://github.com/pfcoperez/algorithmaday/tree/master/src/main/scala/org/pfcoperez/dailyalgorithm/datastructures/sets
Which is a pure functional version of the structure described at CLRS. I implemented it in Python in 2012 and provided an small summary of the structure described by Thomas Cormen.
Few days ago I adapted it to a pure functional implementation.
In fact I also provided a state monad set of operation thus making it able to be used using for
notation in such a way that the state propagation is transparent for the user:
The point is that I was reviewing your implementation and I see it's simple, it implements union by rank heuristic as well. However it seems to lack the path compression heuristic. That is OK for most cases but it can lead to degraded states where lookups can be as slow as O(n), n = max depth. Check the how the tree depth increases in this example where the path compression is not being applied:
I hope you don't mind if open a PR with my version so we can discuss the differences.
from cats-collections.
Looks good, I thought about implementing the path compression (I mentioned it in the code comment), but decided not to in the end. It was partly because I wanted to avoid bringing in a dependency like Cats or roll my own Monad. I wan't sure about bringing in a dependency on Cats of if dogs had to be standalone... I couldn't decide in the end if it was worth doing or not (edit: I think in the end, and it was personal, it was better to keep a slightly simpler codebase)
from cats-collections.
Hi @lewismj , the implementation at https://github.com/pfcoperez/algorithmaday/blob/master/src/main/scala/org/pfcoperez/dailyalgorithm/datastructures/sets/DisjointSets.scala doesn't use Cats, it follows a standalone approach as you suggested, it is curious that we share the same criteria in that regards
It has a wrapper to make it "Cats friendly": https://github.com/pfcoperez/algorithmaday/blob/master/src/main/scala/org/pfcoperez/dailyalgorithm/datastructures/sets/MonadicDisjointSets.scala
Not implementing one of the heuristics might be enough, there are some corner cases leading to the need of path compression. Nevertheless, I fear that path compression is required to keep time complexity bounds.
I've already created a PR (#90) with an implementation including path compression.
Nice relatively unknown data structure, isn't it?
from cats-collections.
This has been already merged.
from cats-collections.
Thanks!
from cats-collections.
Related Issues (20)
- 1.0 HOT 11
- remove Discrete typeclass in favor of one of the cats Enumerable typeclasses HOT 6
- Publish artifacts for Scala.js 1 HOT 2
- Migrate from tut to mdoc HOT 1
- Dotty support
- AvlMap alter doesn't remove mapping
- Migrate to sbt-github-actions HOT 3
- Integrate mdoc with sbt-microsites HOT 2
- typelevel.org/cats-collections/ leads to 404 HOT 1
- A flaky test `cats.collections.tests.TreeListSpec`
- Remove Gitter link HOT 1
- Bring back code coverage per PR HOT 2
- 0.9.4 as intermediate release HOT 2
- Migrate to sbt-typelevel HOT 2
- Fix the warnings and enable fatal warnings in CI HOT 1
- Get benchmarks compiling on Scala 3
- Setup for CI release HOT 1
- Build for Scala Native
- Add CHAMP HashMap and HashSet to microsite
- Inconsistent Range behavior when dealing with reverse ranges HOT 19
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cats-collections.