Int crc24 0x5d6dcb 0xd3b6ba 0xaeb6e5 0x864cfb

This preview shows 1 out of 3 pages.

// int[] CRC_24 = {0x5D6DCB, 0xD3B6BA, 0xAEB6E5, // 0x864CFB, 0xDF3261, 0xC3267D}; final int CRC_24 = 0x5D6DCB; // final int INV_CRC_24 = 0xD3B6BA; key = key.toLowerCase(); int key_length = key.length(); int index; int hashValue = 0; int feeder = 0; if (key_length > 0) { hashValue += key.charAt(0) << 16; } if (key_length > 1) {
Image of page 1

Subscribe to view the full document.

hashValue += key.charAt(1) << 8; } if (key_length > 2) { hashValue += key.charAt(2); } for ( index = 3; index < key_length; index++ ) { feeder = key.charAt(index); for ( int bit = 8; bit > 0; bit-- ) { hashValue <<= 1; feeder <<= 1; if ( (feeder & 0x100) != 0 ) { hashValue++; } if ( (hashValue & 0x1000000) != 0 ) { hashValue ^= CRC_24; } feeder &= 0xff; hashValue &= 0xffffff; // System.out.println(formatHex_24(hashValue)); } // System.out.println(formatHex_24(hashValue)); // System.out.println(" "); } for ( index = 0; index < 3; index++ ) { for ( int bit = 8; bit > 0; bit-- ) { hashValue <<= 1; if ( (hashValue & 0x1000000) != 0 ) { hashValue ^= CRC_24; } hashValue &= 0xffffff; // System.out.println(formatHex_24(hashValue)); } // System.out.println(formatHex_24(hashValue)); // System.out.println(" "); } // System.out.println(key + " " + formatHex_24(hashValue)); return hashValue; } public boolean checkKey(String key) { return (keys[hashKey(key)] != null); } public void put(String key) { int index = hashKey(key); if (keys[index] == null) { keys[index] = key; } else { if ( !key.equalsIgnoreCase(keys[index]) ) { System.out.print("!!! HASH TABLE COLLISION !!!"); System.out.println( key + " < ==== > " + keys[index]); } } counts[index]++; } public String[] getKeys() { return keys; }
Image of page 2
public int get(String key) { int index = hashKey(key); if (keys[index] != null) { return counts[index]; } else { return -1; } } }
Image of page 3
You've reached the end of this preview.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern