What is the best way to compare two HTML pages with same data but different markup?
In this article, we will be learning about the best way to compare two HTML pages with the same data but different markup. At first, we need to know how to compare two HTML pages. Now, the most efficient way to check both the pages is to use the hash code of both the page contents and compare it for equality.
Now, hash code is generally formed by the following implementation.
s*31^(n-1) + s*31^(n-2) + ... + s[n-1]
The line that contains (hashValue << 5) is same as (hashValue * 31 + char). So (hashValue <<5) is hashValue * 32 and ((hashValue << 5)-hashValue) is hashValue *31. Writing it in this format just makes it faster and increases its efficiency.
If the contents are different, then a different output will be shown. In the second example, the faster approach is used.