nbro / andz

Algorithms and data structures for educational, demonstrational and experimental purposes.
MIT License
60 stars 12 forks source link

Should the implementation details of DSForests be hidden from the clients? #50

Closed nbro closed 7 years ago

nbro commented 7 years ago

Currently, it seems that the implementation of DSForests assumes that the user knows about DSNode and thus can access its public fields. Is this a good thing in this case? My first intuition is that the user doesn't care about these implementations details and therefore they should be hidden. Note: if that's the case, we may need also to change the interface of certain methods, e.g. find, which instead of returning DSNode would return the original value stored in the corresponding representative.

For example, Kruskal's MST algorithm uses DSForests, but doesn't really care about implementation details, it only cares about the main functionalities and advantages that DSForests uses:

  1. Find if two elements belong to the same set in amortized constant time
  2. The nature of the DS, i.e. that you have a forest of disjoint sets and you can union them.
nbro commented 7 years ago

Solved this issue by