Calculating pattern hash