Skip to content

Conversation

@arithmeticmean
Copy link

@arithmeticmean arithmeticmean commented Dec 11, 2025

fixes: #835
This PR adds full support for using multiple port ranges in a single command, using a simple comma-separated format for range like:

RustScan -a 127.0.0.1/24 -r 1-100,200-300,5000-5100

Random Mode

All provided ranges are merged together, automatically handling overlaps and neighboring ranges so users don't have to worry about cleanup.
These merged ranges are then fed into an extended LCG-based iterator—building on the original design but now able to handle complex inputs.

Most importantly, the behavior you expect is preserved:

  • every port is visited exactly once,
  • no duplicates,
  • a clean, uniform randomized walk through the entire set.

Serial Mode

Ranges are scanned in natural order, nice and straightforward.
A tiny BitSet takes care of any overlapping ranges so the output stays clean.
This avoids the heavier logic used in randomized mode, keeping the serial path fast and predictable.

Added detailed internal docs explaining:

  • how ranges are merged,
  • how prefix mapping works,
  • how the LCG step is chosen,
  • how duplicate ports are avoided in serial mode.

Expanded the test suite to properly cover all multi-range behaviors.

I ended up removing the earlier Fenwick+BitSet prototype—it was interesting, but ultimately added complexity without giving meaningful performance wins. This new approach is about 80–120 µs slower in single range case form previous -range implementation, but in exchange it stays simple, readable, and true to the spirit of the original iterator while finally supporting multi-range inputs properly.

Happy to adjust anything — feedback, suggestions, or changes of any kind are always welcome.

arithmeticmean and others added 2 commits December 11, 2025 21:28
Add full support for inputs like 1-100,200-300,5000-5100 by merging
overlapping/adjacent ranges and feeding them into an extended LCG-based
iterator. This keeps the original permutation guarantees while allowing
arbitrary multi-range definitions.

Also adds a serial mode for serial ordering. updates docs/tests.
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

Successfully merging this pull request may close these issues.

Hope to support port string and range combination parameters

1 participant