subsets: Iterate over subsets of arbitrary supersets efficiently

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Please see the README on GitHub at https://github.com/felixlinker/subsets#readme


[Skip to Readme]

Properties

Versions 0.1.0.1
Change log ChangeLog.md
Dependencies base (>=4.7 && <5), containers (>=0.5.11.0) [details]
License MIT
Copyright 2019 Felix Linker
Author Felix Linker
Maintainer linkerfelix@gmail.com
Category Set Theory
Home page https://github.com/felixlinker/subsets#readme
Bug tracker https://github.com/felixlinker/subsets/issues
Source repo head: git clone https://github.com/felixlinker/subsets
Uploaded by felixlinker at 2019-03-01T15:34:47Z

Modules

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for subsets-0.1.0.1

[back to package description]

subsets

This package provides two modules that allow to efficiently iterate over all subsets of any list. Here is a quick code example:

>>> data T = A | B | C deriving (Show)
>>> subsetsAsc [A, B, C] 0 3
[[], [A], [B], [C], [A, B], [A, C], [B, C], [A, B, C]]
>>> subsetsDesc [A, B, C] 3 3
[[A,B,C],[B,C],[A,C],[A,B],[C],[B],[A],[]]

The idea of the Banker's sequence is used to achieve this. This concept in described in Loughry, van Hemert, Schoofs, 2002 although no implementation details suggested in the paper are being used.

This approach has the following upsides:

Subsets are generated by mapping index lists to some given list. The subset generation itself does not have any significant overhead and runs in O(2^n*n) (which corresponds to the number of elements in all subsets). Only the lookup adds performance overhead. Therefore the functions subsetsAsc and subsetsDesc run in O(2^n*n*log(n)).

If you want to implement custom mappers you can either use the index set returned by indexSetsAsc/indexSetsDesc or directly provide a mapper function to mapIndexSetsAsc/mapIndexSetsDesc. Confer the inline documentation for more details and type annotations.

Contributing

You use stack to build the library and run tests. I'm always happy to receive issues and/or pull requests.

References

Loughry, Joe & van Hemert, Jano & Schoofs, L. (2002).
Efficiently Enumerating the Subsets of a Set.
https://www.researchgate.net/publication/2526315_Efficiently_Enumerating_the_Subsets_of_a_Set