public Chunk loadChunk(int cx, int cy) { Chunk c = getChunk(cx, cy); if (c == null) { c = new Chunk(this, cx, cy); chunks.put(c.chunkIndex, c); } return c; }
public void addLetter(byte letter) { if (sinceStart < 2) { buffer[sinceStart] = letter; sinceStart++; } else { int trigram = trigramToInt(buffer[0], buffer[1], letter); buffer[0] = buffer[1]; buffer[1] = letter; if (!suggestions.containsKey(trigram)) { suggestions.put(trigram, new TreeSet<Integer>()); } TreeSet<Integer> s = suggestions.get(trigram); s.add(sinceStart - 2); suggestions.put(trigram, s); sinceStart++; if (sinceStart > sizeLimit) { discarded++; } } }
public int[] getIndexSuggestions(byte... trigram) { Integer tg = trigramToInt(trigram); if (!suggestions.containsKey(tg) || suggestions.get(tg).isEmpty()) { return new int[0]; } TreeSet<Integer> sugs = (TreeSet<Integer>) suggestions.get(tg).tailSet(discarded); Object[] suggest = sugs.toArray(); int[] ss = new int[suggest.length]; for (int i = 0; i < suggest.length; i++) { ss[i] = (int) suggest[i] - discarded; } suggestions.put(tg, sugs); return ss; }