Question

1 Objective Build a hashing algorithm that is suitable for use in a Bloom Filter. Please note that while a cryptographic hash

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.io.*;
import java.util.*;

class Hw03
{

public static int xram(String input, int length)
   {
int rand1 = 0xbcde98ef;
int rand2 = 0x7890face;
int hashValue = 0xfa01bc96;
int roundedEnd = (length & 0xfffffffc);
int tmpData = 0; //how do i initialize?

int[] data = new int[length];
for(int i=0; i<length; i++)
       {
data[i] = (int)input.charAt(i);
}

for(int i=0; i<roundedEnd; i+=4)
       {
tmpData = (data[i] & 0xff)|((data[i+ 1] & 0xff)<<8)|((data[i+ 2] & 0xff)<<16)|(data[i+ 3]<<24);
tmpData *= rand1;
tmpData = Integer.rotateLeft(tmpData,12);
tmpData *= rand2;
hashValue = hashValue ^ tmpData;
hashValue = Integer.rotateLeft(hashValue,13);
hashValue = (hashValue * 5) + 0x46b6456e;
}
tmpData = 0;

if((length & 0x03) == 3)
       {
tmpData = (data[roundedEnd + 2] & 0xff) << 16;
length -= 1;
}
if((length & 0x03) == 2)
       {
  
tmpData |= (data[roundedEnd + 1] & 0xff) << 8;
length -= 1;
}
if((length & 0x03) == 1)
       {
tmpData = tmpData | (data[roundedEnd] & 0xff);
tmpData = tmpData * rand1;
tmpData = Integer.rotateLeft(tmpData,14);
tmpData = tmpData * rand2;
hashValue = hashValue ^ tmpData;
}

hashValue = hashValue ^ length;
hashValue = hashValue & 0xb6acbe58;
hashValue = hashValue ^ hashValue >>> 13;
hashValue = hashValue * 0x53ea2b2c;
hashValue = hashValue ^ hashValue >>> 16;

System.out.format("%10x:%s\n",hashValue, input);

return hashValue;
}

public static void complexityIndicator()
   {
System.err.println("al144291;4;4");
}
  
public static void main(String[] args) throws Exception
{
complexityIndicator();

String infile = args[0];
Scanner scnr = new Scanner(new File(infile));

while(scnr.hasNext())
       {
String line = scnr.nextLine();
int length = line.length();
xram(line, length);
}
System.out.println("Input file processed");
}
}

Add a comment
Know the answer?
Add Answer to:
1 Objective Build a hashing algorithm that is suitable for use in a Bloom Filter. Please...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C code: hash program (use the Fowler-Noll-Vo (FNV) hash algorithm) This is a simple program that...

    C code: hash program (use the Fowler-Noll-Vo (FNV) hash algorithm) This is a simple program that you will use in the second part of the assignment. Details of this program is as follows. A hashing algorithm is simply an algorithm that maps data of an arbitrary size into a hash value of a fixed size. On your VM, you should have a program called ”md5sum”, which computes the MD5 hash of a file (or bytes taken from standard input). One...

  • 1 Objective The rules for a new type of programming contest provides a list of problems,...

    1 Objective The rules for a new type of programming contest provides a list of problems, their respective score in integer points, and a statistically valid estimate of the time it takes to solve the problem. This duration or time is expressed in integer hours. To help with a solution strategy the contest organizers reveal there is a dynamic programming solution enabling all the contestants to maximize their score - and stay within the time limits for the contest. One...

  • For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...

    For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...

  • TASK Your task is to build a palindrome from an input string. A palindrome is a...

    TASK Your task is to build a palindrome from an input string. A palindrome is a word that reads the same backward or forward. Your code will take the first 5 characters of the user input, and create a 9- character palindrome from it. Words shorter than 5 characters will result in a runtime error when you run your code. This is acceptable for this exercise – we will cover input validation in a later class. Some examples of input...

  • C++ Lab 1. Read in the contents of a text file up to a maximum of...

    C++ Lab 1. Read in the contents of a text file up to a maximum of 1024 words – you create your own input. When reading the file contents, you can discard words that are single characters to avoid symbols, special characters, etc. 2. Sort the words read in ascending order in an array (you are not allowed to use Vectors) using the Selection Sort algorithm implemented in its own function. 3. Search any item input by user in your...

  • hey please answer in python 3 This is the test for these questions. it has to...

    hey please answer in python 3 This is the test for these questions. it has to be exactly the same as the Expected output. notice my code is very close to getting it but im always off by 0.01 or 0.02. Thank you for the help! In this exercise, you will build a program to process files containing paragraphs. The aim of the program is to simply count the number of words and compute their length. The file, however, may...

  • In this project, you will work on the algorithm (discussed in Module 1) to determine the...

    In this project, you will work on the algorithm (discussed in Module 1) to determine the length of the longest sub sequence of consecutive integers in an array You will implement the algorithm using Hash tables. You are provided with sample code (in C++ and Java) representing the linked list-based implementation of Hash tables (as an array of Linked Lists). You could go through the code to understand the implementation of a Hash table and the functions that can be...

  • You are given a set of ABC cubes for kids (like the one shown below) and a word. On each side of ...

    You are given a set of ABC cubes for kids (like the one shown below) and a word. On each side of each cube a letter is written 7 FI 0 You need to find out, whether it it possible to form a given word by the cubes For example, suppose that you have 5 cubes: B1: MXTUAS B2:OQATGE ВЗ: REwMNA B4: MBDFAC В5: IJKGDE (here for each cube the list of letters written on its sides is given) You...

  • Capitalization JAVA In this program, you will read a file line-by-line. For each line of data...

    Capitalization JAVA In this program, you will read a file line-by-line. For each line of data (a string), you will process the words (or tokens) of that line one at a time. Your program will capitalize each word and print them to the screen separated by a single space. You will then print a single linefeed (i.e., newline character) after processing each line – thus your program will maintain the same line breaks as the input file. Your program should...

  • Newmultiply.Java // NewMultiply.java - This program prints the numbers 0 through 10 along // with these...

    Newmultiply.Java // NewMultiply.java - This program prints the numbers 0 through 10 along // with these values multiplied by 2 and by 10. // Input: None. // Output: Prints the numbers 0 through 10 along with their values multiplied by 2 and by 10. public class NewMultiply {    public static void main(String args[])    {               String head1 = "Number: ";        String head2 = "Multiplied by 2: ";        String head3 = "Multiplied...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT