/** Collect all unique non-stop word from a phrase. */ private void appendUniqueWords(IntStack words, IntStack offsets, PhraseCandidate p) { assert p.cluster.phrases.size() == 1; final int start = words.size(); final int[] phraseIndices = p.cluster.phrases.get(0); final short[] tokenTypes = context.allWords.type; for (int i = 0; i < phraseIndices.length; i += 2) { for (int j = phraseIndices[i]; j <= phraseIndices[i + 1]; j++) { final int termIndex = sb.input.get(j); if (!TokenTypeUtils.isCommon(tokenTypes[termIndex])) { words.push(termIndex); } } } // Sort words, we don't care about their order when counting subsets. Arrays.sort(words.buffer, start, words.size()); // Reorder to keep only unique words. int j = start; for (int i = start + 1; i < words.size(); i++) { if (words.buffer[j] != words.buffer[i]) { words.buffer[++j] = words.buffer[i]; } } words.elementsCount = j + 1; offsets.push(start, words.size() - start); }