Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arnav-kansal/SubSetIterator
Blazingly Fast iteration(lazy) over all subsets of the elements of a vector.
https://github.com/arnav-kansal/SubSetIterator
Last synced: 2 months ago
JSON representation
Blazingly Fast iteration(lazy) over all subsets of the elements of a vector.
- Host: GitHub
- URL: https://github.com/arnav-kansal/SubSetIterator
- Owner: arnav-kansal
- Created: 2018-09-16T04:35:09.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-06-14T06:19:16.000Z (over 5 years ago)
- Last Synced: 2024-08-02T05:12:04.649Z (6 months ago)
- Language: C++
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-blazingly-fast - SubSetIterator - Blazingly Fast iteration(lazy) over all subsets of the elements of a vector. (C++)
README
# SubSetIterator
Subset Iteration can be quite useful when you want to brute force explore an entire powerset.
There are many ways to go about it which involve recursion as well.This SubsetIterator was build using a gray code encoding scheme. This helps building the sets lazily.
And helps over iterating the standard binary encoding scheme by saving on allocations/ deallocations.I was able to iterate over a power-set of 27 strings (avg. length of such strings: 4.7), which would have $2^{27} = 134,217,728$ subsets in ~1.5 seconds. [2015 MBP running a 2.7GHZ processor, g++-8] which corresponds to about ~11 nano seconds per iteration. The checksum of the sum of lengths of strings of a subset was used for testing.
## Build
```
g++ -o testF.o -O3 -std=c++11 test.C && time ./testF.o
```To test the binary encoding scheme:
```
g++ -o test.o -O3 -std=c++11 -DTEST test.C && time ./test.o
```