Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reconsider the return type for set operations #26

Open
lonnen opened this issue Oct 31, 2020 · 2 comments
Open

reconsider the return type for set operations #26

lonnen opened this issue Oct 31, 2020 · 2 comments

Comments

@lonnen
Copy link
Owner

lonnen commented Oct 31, 2020

Matklad suggests intersection, union, and other set operations should return (&T, usize) instead of just &T.

de16931#diff-b1a35a68f14e696205874893c07fd24fdb88882b47c23cc0e0c80a30c7d53759R887

@lonnen
Copy link
Owner Author

lonnen commented Aug 16, 2021

Here's some prior art. I'm considering some popular and some interesting languages, libraries where there is no stdlib support. To my suprise, many implementations of multiset don't appear to implement set operations at all and instead actually implement counters, dictionaries, or maybe just is_subset.

Languages that return [&T] or similar:

languages that return (&t count) or similar:

  • go soniakeys lib is recommended in High Performance Go, but hasn't been updated in years. In a quick search, I couldn't find any other Go library that actually implemented set ops

languages that return Multiset:

languages thet implement subset, but not union, intersect, etc.:

  • r set6 mathematical multiset lib. There are several libs that implement bits of set functionality, and convention seems to expected a sorted iterable to ducktype as a multiset
  • swift implements counters

could not find:

  • c# or any .net
  • php

@lonnen
Copy link
Owner Author

lonnen commented Dec 30, 2021

A couple notes as I reconsider this --

  • Languages that return [&T] tend to be less-strongly-typed than rust.
  • Mathematical notation is not best understood as [&T] but as Multiset literals, making it closer to Haskell than the others
  • Haskell's implementation is tree backed while mset mirrors the rust stdlib collections and uses HashMap, which uses Hashbrown, which is a rust implementation of Swiss Tables
  • Haskell's implementation may be more sensible given Rust's type system, despite the popularity of other interfaces in other languages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant