java – Counting the number of unique IP addresses in a very large file. Follow-Up #1

It’s a follow-up question.
A previous version
of this code has been posted on Code Review about 2 weeks ago.

What was done after the last review

In fact, the entire application is rewritten from scratch. Here
is current version with tests and JavaDoc.

I tried to split the application into small classes that have only one responsibility and can be re-used and extended.

The main approach to solve a problem has not changed. I still put one value in accordance with each ip and set a bit with the corresponding index in the bit array. The required amount of memory remained the same about 550-600 MB. The speed has increased, now I am practically limited to the performance of my hard disk. It is still assumed that only valid IPs will be in the file.

I deleted all JavaDoc comments from code examples, because they occupy more space than the code itself.

FixedSizeBitVector

I wrote a simple implementation of the bit array that allows you to store N bits with indexes from 0 to N-1. There are
three operations are supported: set bit, examine bit’s value, and get the number of all the set bits.
getCapacity() method used for testing and may be useful in other cases.

I do not bring the BitVector interface due to its primitiveness and simplicity.

package chptr.one;

public class FixedSizeBitVector implements BitVector {

    public static final long MIN_CAPACITY = 1L;
    public static final long MAX_CAPACITY = 1L << 32;

    private final long capacity;
    private final int() intArray;
    private long cardinality;

    public FixedSizeBitVector(long capacity) {
        if (capacity < MIN_CAPACITY || capacity > MAX_CAPACITY) {
            throw new IllegalArgumentException("Capacity must be in range (1.." + MAX_CAPACITY + ").");
        }
        int arraySize = 1 + (int) ((capacity - 1) >> 5);
        this.intArray = new int(arraySize);
        this.capacity = capacity;
    }

    private void checkBounds(long bitIndex) {
        if (bitIndex < 0 || bitIndex >= capacity) {
            throw new IllegalArgumentException("Bit index must be in range (0.." + (capacity - 1) + ").");
        }
    }

    @Override
    public void setBit(long bitIndex) {
        checkBounds(bitIndex);
        int index = (int) (bitIndex >> 5);
        int bit = 1 << (bitIndex & 31);
        if ((intArray(index) & bit) == 0) {
            cardinality++;
            intArray(index) |= bit;
        }
    }

    @Override
    public boolean getBit(long bitIndex) {
        checkBounds(bitIndex);
        int index = (int) (bitIndex >> 5);
        int bit = 1 << (bitIndex & 31);
        return (intArray(index) & bit) != 0;
    }

    @Override
    public long getCapacity() {
        return capacity;
    }

    @Override
    public long getCardinality() {
        return cardinality;
    }
}

UniqueStringCounter

This class implements the counter of unique lines in the input Iterable<String> sequence. The counter uses BitVector
implementation. To work, it is required that the input sequence has a final number of possible string-values and this
amount did not exceed the maximum capacity of the bit vector used.

It also requires a hash function that puts a String and a long in an unambiguous match.

package chptr.one;

import javax.validation.constraints.NotNull;
import java.util.Objects;
import java.util.function.ToLongFunction;

public class UniqueStringCounter {

    private final Iterable<String> lines;
    private final ToLongFunction<String> hashFunction;
    private final BitVector bitVector;
    private long linesProcessed;

    public UniqueStringCounter(@NotNull Iterable<String> lines,
                               long capacity,
                               @NotNull ToLongFunction<String> hashFunction) {

        Objects.requireNonNull(lines);
        Objects.requireNonNull(hashFunction);
        this.lines = lines;
        this.hashFunction = hashFunction;
        this.bitVector = new FixedSizeBitVector(capacity);
    }

    public long count() {
        for (String line : lines) {
            long value = hashFunction.applyAsLong(line);
            bitVector.setBit(value);
            linesProcessed++;
        }
        return bitVector.getCardinality();
    }

    public long getLinesProcessed() {
        return linesProcessed;
    }
}

IpStringHashFunction

Hash function to convert a String to a long value. This function must generate a unique value for each unique line,
the collisions are not allowed.

I tested several options for the conversion of IP-String in the long-value and came to the conclusion that they all work around at the same speed that the InetAddress. I do not see the reasons to write my own implementation when the speed of the library function is completely satisfied.

The processing of exceptions really is not needed here, because according to the terms of the task, I am guaranteed that there will be only valid IP. I had to make this processing since otherwise I can’t use this function as a parameter for UniqueStringCounter.

package chptr.one;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.function.ToLongFunction;

public class IpStringHashFunction implements ToLongFunction<String> {

    @Override
    public long applyAsLong(String value) {
        long result = 0;
        try {
            for (byte b : InetAddress.getByName(value).getAddress())
                result = (result << 8) | (b & 255);
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
        return result;
    }
}

BufferedReaderIterable

A simple adapter that allows you to work with BufferedReader as with Iterable. I could not come up with a better way
to send the contents of the file in UniqueStringCounter, which expects to the Iterable<String> as parameter.

package chptr.one;

import javax.validation.constraints.NotNull;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Iterator;
import java.util.Objects;

public class BufferedReaderIterable implements Iterable<String> {

    private final Iterator<String> iterator;

    public BufferedReaderIterable(@NotNull BufferedReader bufferedReader) {
        Objects.requireNonNull(bufferedReader);
        iterator = new BufferedReaderIterator(bufferedReader);
    }

    public Iterator<String> iterator() {
        return iterator;
    }

    private static class BufferedReaderIterator implements Iterator<String> {

        private final BufferedReader bufferedReader;

        private BufferedReaderIterator(BufferedReader bufferedReader) {
            this.bufferedReader = bufferedReader;
        }

        @Override
        public boolean hasNext() {
            try {
                return bufferedReader.ready();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public String next() {
            String line;
            try {
                line = bufferedReader.readLine();
                if (line == null) {
                    try {
                        bufferedReader.close();
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }
    }
}

IpCounterApp

The main class of the application. Accepts the file name in the -file parameter.

package chptr.one;

import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;

public class IpCounterApp {

    private static String parseFileName(String() args) {
        Objects.requireNonNull(args, "No arguments found. Use -file file-name to processing file.");
        if (args.length == 2 || "-file".equals(args(0))) {
            return args(1);
        }
        return null;
    }

    public static void main(String() args) {
        String fileName = parseFileName(args);
        if (fileName == null) {
            System.err.println("Wrong arguments. Use -file file-name to processing file.");
            return;
        }

        Path filePath = Paths.get(fileName);
        if (!Files.exists(filePath)) {
            System.err.printf("File %s does not exists.n", filePath);
            return;
        }

        try {
            System.out.printf("Processing file: %sn", filePath);
            long startTime = System.nanoTime();
            BufferedReader bufferedReader = Files.newBufferedReader(filePath);
            Iterable<String> strings = new BufferedReaderIterable(bufferedReader);
            UniqueStringCounter counter = new UniqueStringCounter(strings, 1L << 32, new IpStringHashFunction());
            long numberOfUniqueIp = counter.count();
            long linesProcessed = counter.getLinesProcessed();
            long elapsedTime = System.nanoTime() - startTime;
            System.out.printf("Unique IP addresses: %d in total %d.n", numberOfUniqueIp, linesProcessed);
            System.out.printf("Total time: %d milliseconds.n", elapsedTime / 1_000_000);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Why do I ask the new Review?

In previous question
I received a few excellent answers and one excellent bug report. I tried to take into account so many comments as I
could. I also tried to reconsider my approach to the design of classes. I am interested in mostly three questions:

  • How are my new classes are suitable for re-use and extension? What other abstractions can be allocated here and should
    it be done?
  • What should I do with error processing? I know that now it is bad. I just try to fall as early as possible.
  • And most importantly. Do I move in the right direction? I am a newbie in programming and get an overview for my code is
    the only way to learn how to write a quality and understandable code.

Buy extream 2000+ web 2.0 pbn backlink with High DA/PA/TF/CF in your homepage with unique website for $180

Buy extream 2000+ web 2.0 pbn backlink with High DA/PA/TF/CF in your homepage with unique website

I Will Do 2000+ Permanent Blog Post on web 2.0s blogs for your

website/video/blog/page on High Quality, High Trust Flow / Citation

Flow, Domain Authority / Page Authority Homepage sites.

  • For just $200 you will get:-
  • }}}- 2000+ Permanent PBN
  • }}}- Trust Flow up to 55+
  • }}}- Citation Flow up to 65+
  • }}}- Domain Authority 72+
  • }}}- Page Authority 80+

We will manually post and provide you Dofollow PBN on High authority sites using Perfectly Natural Link Building Techniques.

Do-Follow backlinks will pass on the SEO benefits of the site where it is built from the hyperlinked site. These weblinks will enhance

especially your link profile and rectify your page rank.

After this work, your website will be improved and especially more popular. Furthermore, it will improve your SEO ranking.

For years, aggressive link building was the “secret sauce” of SEO that wasn’t so secret. Sites

wishing to rank simply made pages filled to the brim with spammy

backlinks to their main site. When social-based “web 2.0” emerged

starting around 2005, this tactic persisted under a new MO, this time

taking the form of socially-based web 2.0 backlinks pages rather than

custom-hosted ones.

How do bloggers get those backlinks? Here’s how our team secured links!Google caught on to the fact that people were

boosting the ranking of their sites in ways that were hurting the

average search user experience. Now, any site suspected of using such

tactics will have their ranking penalized, heavily.

What are the top SEO link building methods that get the best results? Check out our top effective whitehat SEO strategies.Yet, web

2.0 links still work when done right. Some forms should outright

beconsidered mandatory, while others require a lot of effort to be seen

as legitimate. In short, the web 2.0 linking game got a lot more strategic, with risk/reward dynamics affected by how much effort you are willing to put in.

High Authority SEO Backlinks is one of the powerful techniques to increase the rankings of your site in

popular search engines like Google, Yahoo, Bing etc.

With High-Quality Backlinks, your website can rank on the top. So considering the value of getting Rankings as well as

to increase the traffic we start this wonderful service for the welfare

of our valuable clients.

High DA Forum Backlinks is one of the most effective ways you can start

spreading the word about your website. That¡¯s a natural way of getting

organic, trustworthy backlinks and become an authority in your area of

expertise.

ADVANTAGES:

  • ()> ALL LINKS ARE DO-FOLLOW That Will INCREASE YOUR LINK POPULARITY WHICH DIRECTLY BOOST YOUR RANKINGS..
  • ()> ALL BACKLINKS ARE FROM PR2-PR7 or DA 50+ Websites.
  • ()> SUBMISSION FOR INDEXING FOR FREE USING Lindexed & Indexification.
  • ()> PERMANENT BACKLINK


Main Features:-

}}} 100% Do Follow & Permanent Links!

}}} 100% UNIQUE IPs!

}}} 100% full report!

}}} 100% money BACK Gurantee!

}}} 100% timely delivery!

}}} 100% Quality Guarantee!

}}} 100% Penguin and Panda Safe!

}}} 100% Unique GIG from zips work!

Requirement:

1 URL with at least 1-15 Keywords.

Industry Expertise

  1. Arts
  2. Business
  3. Crypto & Blockchain
  4. Cyber Security
  5. E-Commerce
  6. Education
  7. Environmental
  8. Financial Services/ Banking
  9. Games
  10. Government & Public Sector
  11. Health & Wellness
  12. Insurance
  13. Kids and Family
  14. Legal
  15. Media & Entertainment
  16. Medical & Pharmaceutical
  17. Music
  18. News
  19. Non-Profit
  20. Real Estate
  21. Retail & Wholesale
  22. Society and Culture
  23. Sports and Recreation
  24. Technology & Internet
  25. Transportation & Automotive
  26. Gambling
  27. Poker etc….

.(tagsToTranslate)seo(t)WEB2(t)0(t)DOFOLLOW(t)PBN(t)BACKLINK

Buy extream 1500+ web 2.0 pbn backlink with High DA/PA/TF/CF in your homepage with unique website for $150

Buy extream 1500+ web 2.0 pbn backlink with High DA/PA/TF/CF in your homepage with unique website

I Will Do 1500+ Permanent Blog Post on web 2.0s blogs for your

website/video/blog/page on High Quality, High Trust Flow / Citation

Flow, Domain Authority / Page Authority Homepage sites.

  • For just $150 you will get:-
  • }}}- 1500+ Permanent PBN
  • }}}- Trust Flow up to 55+
  • }}}- Citation Flow up to 65+
  • }}}- Domain Authority 72+
  • }}}- Page Authority 80+

We will manually post and provide you Dofollow PBN on High authority sites using Perfectly Natural Link Building Techniques.

Do-Follow backlinks will pass on the SEO benefits of the site where it is built from the hyperlinked site. These weblinks will enhance

especially your link profile and rectify your page rank.

After this work, your website will be improved and especially more popular. Furthermore, it will improve your SEO ranking.

For years, aggressive link building was the “secret sauce” of SEO that wasn’t so secret. Sites

wishing to rank simply made pages filled to the brim with spammy

backlinks to their main site. When social-based “web 2.0” emerged

starting around 2005, this tactic persisted under a new MO, this time

taking the form of socially-based web 2.0 backlinks pages rather than

custom-hosted ones.

How do bloggers get those backlinks? Here’s how our team secured links!Google caught on to the fact that people were

boosting the ranking of their sites in ways that were hurting the

average search user experience. Now, any site suspected of using such

tactics will have their ranking penalized, heavily.

What are the top SEO link building methods that get the best results? Check out our top effective whitehat SEO strategies.Yet, web

2.0 links still work when done right. Some forms should outright

beconsidered mandatory, while others require a lot of effort to be seen

as legitimate. In short, the web 2.0 linking game got a lot more strategic, with risk/reward dynamics affected by how much effort you are willing to put in.

High Authority SEO Backlinks is one of the powerful techniques to increase the rankings of your site in

popular search engines like Google, Yahoo, Bing etc.

With High-Quality Backlinks, your website can rank on the top. So considering the value of getting Rankings as well as

to increase the traffic we start this wonderful service for the welfare

of our valuable clients.

High DA Forum Backlinks is one of the most effective ways you can start

spreading the word about your website. That¡¯s a natural way of getting

organic, trustworthy backlinks and become an authority in your area of

expertise.

ADVANTAGES:

  • ()> ALL LINKS ARE DO-FOLLOW That Will INCREASE YOUR LINK POPULARITY WHICH DIRECTLY BOOST YOUR RANKINGS..
  • ()> ALL BACKLINKS ARE FROM PR2-PR7 or DA 50+ Websites.
  • ()> SUBMISSION FOR INDEXING FOR FREE USING Lindexed & Indexification.
  • ()> PERMANENT BACKLINK


Main Features:-

}}} 100% Do Follow & Permanent Links!

}}} 100% UNIQUE IPs!

}}} 100% full report!

}}} 100% money BACK Gurantee!

}}} 100% timely delivery!

}}} 100% Quality Guarantee!

}}} 100% Penguin and Panda Safe!

}}} 100% Unique GIG from zips work!

Requirement:

1 URL with at least 1-15 Keywords.

Industry Expertise

  1. Arts
  2. Business
  3. Crypto & Blockchain
  4. Cyber Security
  5. E-Commerce
  6. Education
  7. Environmental
  8. Financial Services/ Banking
  9. Games
  10. Government & Public Sector
  11. Health & Wellness
  12. Insurance
  13. Kids and Family
  14. Legal
  15. Media & Entertainment
  16. Medical & Pharmaceutical
  17. Music
  18. News
  19. Non-Profit
  20. Real Estate
  21. Retail & Wholesale
  22. Society and Culture
  23. Sports and Recreation
  24. Technology & Internet
  25. Transportation & Automotive
  26. Gambling
  27. Poker etc….

.(tagsToTranslate)WEB2(t)0(t)DOFOLLOW(t)PBN(t)BACKLINK(t)LINKBUILD

GET 30+ High PBN Backlink Rank your Google site. for $1

GET 30+ High PBN Backlink Rank your Google site.

GET 30+ High PBN Backlink Rank your Google site. We give you always a better solution. Get 30+ High authority PBN backlink for_$1.

+++++ WHY ORDER ME +++++

100% Ranking

100% Safe

100% Manual

100% Dofoolow

100% Copyscape
100% Granted

.

Google Analytics – Match URLs on Unique Number in Content Drilldown Using RegEx?

I am trying to track pageviews on Google Analytics for knowledge base articles (on Zendesk).
Each article has a unique number. However, the title of the page is sometimes appended to the URL, and GA tracks this as a separate page. If the title of the article changes, it generates a new URL.

For example, these would all be the same article, so I want to see a single pageviews count, but GA would show as 3 separate stats

/hc/en-us/articles/360039413394
/hc/en-us/articles/360039413394-How-To-Make-A-Sandwich
/hc/en-us/articles/360039413394-How-To-Make-A-Turkey-Sandwich

I want GA to roll up the articles matching on the unique number, and ignoring everything after that. Is there a built-in way to do this? Is there a way to do this with Regex? Where would I add the Regex for the Content Drilldown page? Help!

Thank you.

higher algebra – Is the rank of free module spectra unique?

$pi_0: Spto Ab$ is a direct sum preserving functor, and it sends $E_1$-ring spectra to rings, and modules over them to modules over them.

In particular you get a functor $pi_0: Mod_Rto Mod_{pi_0(R)}$. If $R^nsimeq R^m$ as $R$-modules, then $pi_0(R)^ncong pi_0(R)^m$ as $pi_0(R)$-modules. So if $pi_0(R)$ is commutative and nonzero (which is a much weaker hypothesis than $R$ having an $E_infty$-structure), this implies $n=m$.

More generally, it suffices that $pi_0(R)$ have the invariant basis property.

Note that conversely, if $pi_0(R)$ does not have the invariant basis property, we can find inverse nonsquare matrices $M,N$ with coefficients in $pi_0(R)$, and you can view them as elements of $pi_0map_R(R^n,R^m)$ ($pi_0map_R(R^m,R^n)$ respectively), and their matrix product corresponds to the composition up to homotopy, so that $R^nsimeq R^m$ as $R$-modules.

So it’s an “if and only if” situation with $pi_0(R)$.

A related claim is the fact that group-completion $K$-theory only sees $pi_0$, namely if $R$ is a ring spectrum, then the group-completion $K$-theory of projective $R$-modules (summands of $R^n$ for some finite $n$, no shifts) is the same as that of $tau_{geq 0}R$, which is the same as that of $pi_0(R)$.

write 1000 words seo friendly article on any topic for your website or blog for $6

write 1000 words seo friendly article on any topic for your website or blog

As a professional writer, I know how important great Articles to drive people to your website.

Working with me, you’ll come to know you’re working with an established

professional who understands the importance of a well-researched article to

reach your audience. I will craft a well-researched 1000 words article for the

subject of your choice. It will be fully edited and proofread and ready to

post.

What will you get?

  • High-quality post
  • Seo optimized content
  • 1000 words
  • Any topic
  • Researched with focus keywords
  • 100% plagiarism-free
  • Client satisfaction

Why hire me?

  • Experienced content writer
  • 5 years of experience
  • Cheap rates with high quality

Contact me for further details and satisfaction.
I am looking for your kind response.

.

I will rewrite your article into plagiarism free unique content for $5

I will rewrite your article into plagiarism free unique content

Are you looking for an article rewriting service that is both professional and affordable?

Avoid being conned by the Auto Article Spinners.

Hire this premium article rewriting gig to get professional content that has been manually written!

I am an experienced article rewriter who has produced many high-quality articles and blog posts for a variety of websites. In this gig, I will manually paraphrase and edit each sentence, making it engaging and readable (not spun) for you and your readers.

  • Excellent Quality Content
  • Manually Written
  • Not spun and 100% readable
  • Keyword research
  • FastDelivery
  • Plagiarism Report with your order
  • Delivered in any format, PDF, Doc etc
  • Please message me if you have any queries or special instructions
  • Basic gig price is up to 250 words

.(tagsToTranslate)rewrite(t)article(t)unique(t)paraphrase(t)articlerewriter

algebraic topology – Free Groups – representation of 1 by empty word is unique

I am studying Free Products of Groups from Munkres’ Topology book. The definition of free products is:

Let $G$ group, ${G_a}_{a in J}$ family of groups that generates $G$ and $G_a cap G_b$ consists of the idenity element alone whenever $a neq b$.
We say that $G$ is the free product of $G_a$, if for each $x in G$ there is only one reduced word that represents $x$.

After that it says and proves, that it suffices to know that the representation of $1$ by the empty word is unique.

What does exactly the latter means?
Isn’t the empty word unique and doesn’t always represents $1$?
By the previous argument it looks to me like the condition of the uniqueness of the reduced word to be redundant.

Cheapest daily website traffic for sale. 10000 unique visitors just needs $3.99

Why all visitors come from Internet Explorer , this is suspicious for me, 10k Unique Visitors could use more than just a browser, I Personally think you have a huge proxy list and make all these views inside a VB Program / Bot which uses Internet Explorer.

Sorry but this is my opinion

The visitors are over 12k, but the site sent me a bit over 10.000 so probably the firefox and other browsers come from my people
[​IMG]