Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/astynax/assessment-kotlin
Solution wor the "IPv4 address counter" task
https://github.com/astynax/assessment-kotlin
Last synced: 19 days ago
JSON representation
Solution wor the "IPv4 address counter" task
- Host: GitHub
- URL: https://github.com/astynax/assessment-kotlin
- Owner: astynax
- Created: 2024-08-26T17:38:25.000Z (5 months ago)
- Default Branch: master
- Last Pushed: 2024-09-16T10:05:15.000Z (4 months ago)
- Last Synced: 2024-09-16T11:43:23.339Z (4 months ago)
- Language: Kotlin
- Size: 65.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### IPv4 Address Counter
Here is my solution for [this problem](https://github.com/Ecwid/new-job/blob/c3189567685c3f63604f5c34d8f8270656b832fc/IP-Addr-Counter.md).
#### Rationale
Since the task didn't specify that I can only *roughly* count unique addresses, I decided to count each one precisely instead of using something like Bloom filter or HyperLogLog.
I thought that if I'll
1. use bit sets to store the last two bytes of the address
2. keep these sets in a `Map` using the first pair of bytes as a keythen I'll get a pretty decent overall storage density (~1 bit per unique address) and possibly will save some space because of the `Map`'s sparseness if some address ranges won't appear.
#### Results
I have my code tested with the mentioned inf the task sample file (120 GB). The program counted exactly 1 billion unique addresses using ~1.2 GB of heap on average.