// Processed by NMI's Java Code Viewer 4.8.2 © 1997-2000 B. Lemaire // Website: http://njcv.htmlplanet.com E-mail: info@njcv.htmlplanet.com // Copy registered to Evaluation Copy // Source File Name: CheckDictionary.java import java.io.*; class CheckDictionary { private RandomAccessFile dictionary; private long pointers[] = { 0L, 31484L, 60934L, 0x1c917L, 0x2613cL, 0x2c13aL, 0x31d2bL, 0x35d78L, 0x3a2a3L, 0x41292L, 0x4233fL, 0x42efaL, 0x46acbL, 0x4d98bL, 0x4fdb6L, 0x539c1L, 0x5faf7L, 0x60713L, 0x68904L, 0x78c8cL, 0x7fa30L, 0x83e47L, 0x85eb6L, 0x89214L, 0x89236L, 0x896c8L, 0x898f7L }; public CheckDictionary() { try { dictionary = new RandomAccessFile(Scrabble.gameDirectory + "Dictionary" + File.separator + "dictionary.dat", "r"); return; } catch(IOException _ex) { return; } } public boolean searchWord(String s) { if(s.length() == 1) return false; String s1 = new String(""); long l1 = pointers[s.charAt(0) - 97]; long l2 = pointers[(s.charAt(0) - 97) + 1]; try { while(l2 - l1 > 1L) { long l = (l1 + l2) / 2L; dictionary.seek(l); dictionary.readLine(); String s2 = dictionary.readLine(); s2.toLowerCase(); if(s2.equals(s)) return true; if(beforeOrAfter(s, s2) == 0) l1 = l; else l2 = l; } return false; } catch(IOException _ex) { return false; } } private int beforeOrAfter(String s, String s1) { if(s.length() < s1.length()) { for(int i = 0; i < s.length(); i++) { if(s.charAt(i) - s1.charAt(i) > 0) return 0; if(s.charAt(i) - s1.charAt(i) < 0) return 1; } return 1; } for(int j = 0; j < s1.length(); j++) { if(s.charAt(j) - s1.charAt(j) > 0) return 0; if(s.charAt(j) - s1.charAt(j) < 0) return 1; } return s.length() != s1.length() ? 0 : 2; } public void closeDictionary() { try { dictionary.close(); return; } catch(IOException _ex) { return; } } }