Hash, generally translated as "hash", is also directly transliterated as "hash", which means converting inputs of any length (also called pre-image) into fixed-length output through hashing algorithms, and the output is the hash value. This conversion is a compression map, that is, the space of the hash value is usually much smaller than the space of the input, and different inputs may have hashed into the same output, so it is impossible to uniquely determine the input value from the hash value. Simply put, it is a function that compresses messages of any length into a message digest of a fixed length.
If there are large data files (such as url, ip or word, etc. per behavior), they are in units of G, and they need to be divided first when processing. The ordinary slicing method directly segments according to the number of data strips, and each file obtained is similar in size.
But sometimes it is necessary to put the same data into the same file. You can use hash slicing method.
public class Test { static int HASHLEN = 1000; public static void main(String[] args) { // TODO Auto-generated method stub String words [] = {"yes" ,"an" ,"go"}; for(String word:words){ int temp = hash(word.toCharArray()); System.out.println(temp); } } public static int hash(char[] word) { int index = 0; int i=0; while(i<word.length) { index += index * 31 + word[i]; i++; } return index % HASHLEN; } }Summarize
The above is all about Java programming implementation using hash method to cut files. I hope it will be helpful to everyone. Interested friends can continue to refer to other related topics on this site. If there are any shortcomings, please leave a message to point it out.