perfect hashing implementation in java code example

Example: perfect hashing data structure in java

public int perfectHashFunction(String word) {
		int key = 0;
		
		switch (word) {
			case "a": key = 0; break;
			case "after": key = 1; break;
			case "all": key = 2; break;
			case "and": key = 3; break;
			case "because": key = 4; break;
			case "every": key = 5; break;
			case "for": key = 6; break;
			case "from": key = 7; break;
			case "had": key = 8; break;
			case "have": key = 9; break;
			case "in": key = 10; break;
			case "is": key = 11; break;
			case "it": key = 12; break;
			case "its": key = 13; break;
			case "now": key = 14; break;
			case "of": key = 15; break;
			case "on": key = 16; break;
			case "so": key = 17; break;
			case "that": key = 18; break;
			case "the": key = 19; break;
			case "their": key = 20; break;
			case "there": key = 21; break;
			case "to": key = 22; break;
			case "was": key = 23; break;
			case "were": key = 24; break;
			case "which": key = 25; break;
			case "with": key = 26; break;
		}
		return key;
	}

Tags:

Java Example