This Java project efficiently counts the number of unique IPv4 addresses from a large input file using low memory and high performance techniques. It's built to scale to files containing tens or hundreds of gigabytes of IP data.
- Processes unlimited size files line-by-line using Java Streams
- Custom IP address to
intconverter (IPToIntConvertor) - Efficient deduplication using a memory-optimized
BitSetContainer - Uses only Java standard library (no external dependencies)
- IP addresses are stored as 32-bit signed integers (
int) - Supports reading input file from classpath via ClassLoader
src
βββ main
βββ java
βΒ Β βββ com
βΒ Β βββ guseyn
βΒ Β βββ App.java # Entry point: counts unique IPv4 addresses using classloader
βΒ Β βββ BitSetContainer.java # Efficient int container using BitSet array for deduplication
βΒ Β βββ IntContainer.java # Interface for custom integer containers
βΒ Β βββ IpWriter.java # Fast, memory-efficient converter from IPv4 string to int
βΒ Β βββ IPToIntConverter.java
βββ resources
βββ ips.txt # Input file containing IPv4 addresses, one per line- Run
IpWriterto generate your list of IPv4 addresses in the file: src/main/resources/ips.txt (One IP address per line, e.g., 192.168.1.1) or place your file. - Run
Appto get unique number of IP addresses.
Main principals are learnt from the article written by Jegors Δemisovs: https://jc.id.lv/posts/counting-unique-ipv4-addresses/