Example usage for com.google.common.collect MinMaxPriorityQueue orderedBy

List of usage examples for com.google.common.collect MinMaxPriorityQueue orderedBy

Introduction

In this page you can find the example usage for com.google.common.collect MinMaxPriorityQueue orderedBy.

Prototype

public static <B> Builder<B> orderedBy(Comparator<B> comparator) 

Source Link

Document

Creates and returns a new builder, configured to build MinMaxPriorityQueue instances that use comparator to determine the least and greatest elements.

Usage

From source file:it.uniroma3.mat.extendedset.intset.ImmutableConciseSet.java

public static ImmutableConciseSet doIntersection(Iterator<ImmutableConciseSet> sets) {
    IntList retVal = new IntList();

    // lhs = current word position, rhs = the iterator
    // Comparison is first by index, then zero fills > literals > one fills
    // zero fills are sorted by length (longer zero fills have priority)
    // similarily, shorter one fills have priority
    MinMaxPriorityQueue<WordHolder> theQ = MinMaxPriorityQueue.orderedBy(new Comparator<WordHolder>() {
        @Override/*from w  w w .j  av a  2s . c o  m*/
        public int compare(WordHolder h1, WordHolder h2) {
            int w1 = h1.getWord();
            int w2 = h2.getWord();
            int s1 = h1.getIterator().startIndex;
            int s2 = h2.getIterator().startIndex;

            if (s1 != s2) {
                return compareInts(s1, s2);
            }

            if (ConciseSetUtils.isZeroSequence(w1)) {
                if (ConciseSetUtils.isZeroSequence(w2)) {
                    return -compareInts(ConciseSetUtils.getSequenceNumWords(w1),
                            ConciseSetUtils.getSequenceNumWords(w2));
                }
                return -1;
            } else if (ConciseSetUtils.isLiteral(w1)) {
                if (ConciseSetUtils.isZeroSequence(w2)) {
                    return 1;
                } else if (ConciseSetUtils.isLiteral(w2)) {
                    return 0;
                }
                return -1;
            } else {
                if (!ConciseSetUtils.isOneSequence(w2)) {
                    return 1;
                }
                return compareInts(ConciseSetUtils.getSequenceNumWords(w1),
                        ConciseSetUtils.getSequenceNumWords(w2));
            }
        }
    }).create();

    // populate priority queue
    while (sets.hasNext()) {
        ImmutableConciseSet set = sets.next();

        if (set == null || set.isEmpty()) {
            return new ImmutableConciseSet();
        }

        WordIterator itr = set.newWordIterator();
        theQ.add(new WordHolder(itr.next(), itr));
    }

    int currIndex = 0;
    int wordsWalkedAtSequenceEnd = Integer.MAX_VALUE;

    while (!theQ.isEmpty()) {
        // create a temp list to hold everything that will get pushed back into the priority queue after each run
        List<WordHolder> wordsToAdd = Lists.newArrayList();

        // grab the top element from the priority queue
        WordHolder curr = theQ.poll();
        int word = curr.getWord();
        WordIterator itr = curr.getIterator();

        // if a sequence has ended, we can break out because of Boolean logic
        if (itr.startIndex >= wordsWalkedAtSequenceEnd) {
            break;
        }

        // if the next word in the queue starts at a different point than where we ended off we need to create a one gap
        // to fill the space
        if (currIndex < itr.startIndex) {
            // number of 31 bit blocks that compromise the fill minus one
            addAndCompact(retVal, (ConciseSetUtils.SEQUENCE_BIT | (itr.startIndex - currIndex - 1)));
            currIndex = itr.startIndex;
        }

        if (ConciseSetUtils.isZeroSequence(word)) {
            // extract a literal from the flip bits of the zero sequence
            int flipBitLiteral = ConciseSetUtils.getLiteralFromZeroSeqFlipBit(word);

            // advance everything past the longest zero sequence
            WordHolder nextVal = theQ.peek();
            while (nextVal != null && nextVal.getIterator().startIndex < itr.wordsWalked) {
                WordHolder entry = theQ.poll();
                int w = entry.getWord();
                WordIterator i = entry.getIterator();

                if (i.startIndex == itr.startIndex) {
                    // if a literal was created from a flip bit, AND it with other literals or literals from flip bits in the same
                    // position
                    if (ConciseSetUtils.isZeroSequence(w)) {
                        flipBitLiteral &= ConciseSetUtils.getLiteralFromZeroSeqFlipBit(w);
                    } else if (ConciseSetUtils.isLiteral(w)) {
                        flipBitLiteral &= w;
                    } else {
                        flipBitLiteral &= ConciseSetUtils.getLiteralFromOneSeqFlipBit(w);
                    }
                }

                i.advanceTo(itr.wordsWalked);
                if (i.hasNext()) {
                    wordsToAdd.add(new WordHolder(i.next(), i));
                } else {
                    wordsWalkedAtSequenceEnd = Math.min(i.wordsWalked, wordsWalkedAtSequenceEnd);
                }
                nextVal = theQ.peek();
            }

            // advance longest zero literal forward and push result back to priority queue
            // if a flip bit is still needed, put it in the correct position
            int newWord = word & 0xC1FFFFFF;
            if (flipBitLiteral != ConciseSetUtils.ALL_ZEROS_LITERAL) {
                int position = Integer.numberOfTrailingZeros(flipBitLiteral) + 1;
                newWord = (word & 0xC1FFFFFF) | (position << 25);
            }
            addAndCompact(retVal, newWord);
            currIndex = itr.wordsWalked;

            if (itr.hasNext()) {
                wordsToAdd.add(new WordHolder(itr.next(), itr));
            } else {
                wordsWalkedAtSequenceEnd = Math.min(itr.wordsWalked, wordsWalkedAtSequenceEnd);
            }
        } else if (ConciseSetUtils.isLiteral(word)) {
            // advance all other literals
            WordHolder nextVal = theQ.peek();
            while (nextVal != null && nextVal.getIterator().startIndex == itr.startIndex) {

                WordHolder entry = theQ.poll();
                int w = entry.getWord();
                WordIterator i = entry.getIterator();

                // if we still have one fills with flipped bits, AND them here
                if (ConciseSetUtils.isLiteral(w)) {
                    word &= w;
                } else {
                    int flipBitLiteral = ConciseSetUtils.getLiteralFromOneSeqFlipBit(w);
                    if (flipBitLiteral != ConciseSetUtils.ALL_ONES_LITERAL) {
                        word &= flipBitLiteral;
                        i.advanceTo(itr.wordsWalked);
                    }
                }

                if (i.hasNext()) {
                    wordsToAdd.add(new WordHolder(i.next(), i));
                } else {
                    wordsWalkedAtSequenceEnd = Math.min(i.wordsWalked, wordsWalkedAtSequenceEnd);
                }

                nextVal = theQ.peek();
            }

            // advance the set with the current literal forward and push result back to priority queue
            addAndCompact(retVal, word);
            currIndex++;

            if (itr.hasNext()) {
                wordsToAdd.add(new WordHolder(itr.next(), itr));
            } else {
                wordsWalkedAtSequenceEnd = Math.min(itr.wordsWalked, wordsWalkedAtSequenceEnd);
            }
        } else { // one fills
            int flipBitLiteral;
            WordHolder nextVal = theQ.peek();

            while (nextVal != null && nextVal.getIterator().startIndex == itr.startIndex) {
                // check if literal can be created flip bits of other one sequences
                WordHolder entry = theQ.poll();
                int w = entry.getWord();
                WordIterator i = entry.getIterator();

                flipBitLiteral = ConciseSetUtils.getLiteralFromOneSeqFlipBit(w);
                if (flipBitLiteral != ConciseSetUtils.ALL_ONES_LITERAL) {
                    wordsToAdd.add(new WordHolder(flipBitLiteral, i));
                } else if (i.hasNext()) {
                    wordsToAdd.add(new WordHolder(i.next(), i));
                } else {
                    wordsWalkedAtSequenceEnd = Math.min(i.wordsWalked, wordsWalkedAtSequenceEnd);
                }

                nextVal = theQ.peek();
            }

            // check if a literal needs to be created from the flipped bits of this sequence
            flipBitLiteral = ConciseSetUtils.getLiteralFromOneSeqFlipBit(word);
            if (flipBitLiteral != ConciseSetUtils.ALL_ONES_LITERAL) {
                wordsToAdd.add(new WordHolder(flipBitLiteral, itr));
            } else if (itr.hasNext()) {
                wordsToAdd.add(new WordHolder(itr.next(), itr));
            } else {
                wordsWalkedAtSequenceEnd = Math.min(itr.wordsWalked, wordsWalkedAtSequenceEnd);
            }
        }

        theQ.addAll(wordsToAdd);
    }

    // fill in any missing one sequences
    if (currIndex < wordsWalkedAtSequenceEnd) {
        addAndCompact(retVal, (ConciseSetUtils.SEQUENCE_BIT | (wordsWalkedAtSequenceEnd - currIndex - 1)));
    }

    if (retVal.isEmpty()) {
        return new ImmutableConciseSet();
    }
    return new ImmutableConciseSet(IntBuffer.wrap(retVal.toArray()));
}

From source file:it.uniroma3.mat.extendedset.intset.ImmutableSecompaxSet.java

private static ImmutableSecompaxSet doUnion(Iterator<ImmutableSecompaxSet> iterator) {
    IntList retVal = new IntList();

    // lhs = current word position, rhs = the iterator
    // Comparison is first by index, then one fills > literals > zero fills
    // one fills are sorted by length (longer one fills have priority)
    // similarily, shorter zero fills have priority
    MinMaxPriorityQueue<WordHolder> theQ = MinMaxPriorityQueue.orderedBy(new Comparator<WordHolder>() {
        @Override//  w w w.  jav  a2s . c  o  m
        public int compare(WordHolder h1, WordHolder h2) {
            int w1 = h1.getWord();
            int w2 = h2.getWord();
            int s1 = h1.getIterator().startIndex;
            int s2 = h2.getIterator().startIndex;

            if (s1 != s2) {
                return compareInts(s1, s2);
            }

            if (ConciseSetUtils.is1_fill(w1)) {
                if (ConciseSetUtils.is1_fill(w2)) {
                    return -compareInts(ConciseSetUtils.getSequenceNumWords(w1),
                            ConciseSetUtils.getSequenceNumWords(w2));
                }
                return -1;
            } else if (ConciseSetUtils.isLiteral(w1)) {
                if (ConciseSetUtils.is1_fill(w2)) {
                    return 1;
                } else if (ConciseSetUtils.isLiteral(w2)) {
                    return 0;
                }
                return -1;
            } else {
                if (!ConciseSetUtils.is0_fill(w2)) {
                    return 1;
                }
                return compareInts(ConciseSetUtils.getSequenceNumWords(w1),
                        ConciseSetUtils.getSequenceNumWords(w2));
            }
        }
    }).create();

    // populate priority queue
    while (iterator.hasNext()) {
        ImmutableSecompaxSet set = iterator.next();

        if (set != null && !set.isEmpty()) {
            WordIterator itr = set.newWordIterator();
            theQ.add(new WordHolder(itr.next(), itr));
        }
    }

    int currIndex = 0;

    while (!theQ.isEmpty()) {
        // create a temp list to hold everything that will get pushed back into the priority queue after each run
        List<WordHolder> wordsToAdd = Lists.newArrayList();

        // grab the top element from the priority queue
        WordHolder curr = theQ.poll();
        int word = curr.getWord();
        WordIterator itr = curr.getIterator();

        // if the next word in the queue starts at a different point than where we ended off we need to create a zero gap
        // to fill the space
        if (currIndex < itr.startIndex) {
            addAndCompact(retVal, itr.startIndex - currIndex);
            currIndex = itr.startIndex;
        }

        if (ConciseSetUtils.is1_fill(word)) {
            // extract a literal from the flip bits of the one sequence
            //int flipBitLiteral = ConciseSetUtils.getLiteralFromOneSeqFlipBit(word);

            // advance everything past the longest ones sequence
            WordHolder nextVal = theQ.peek();
            while (nextVal != null && nextVal.getIterator().startIndex < itr.wordsWalked) {
                WordHolder entry = theQ.poll();
                int w = entry.getWord();
                WordIterator i = entry.getIterator();

                /*if (i.startIndex == itr.startIndex) {
                  // if a literal was created from a flip bit, OR it with other literals or literals from flip bits in the same
                  // position
                  if (ConciseSetUtils.isOneSequence(w)) {
                    flipBitLiteral |= ConciseSetUtils.getLiteralFromOneSeqFlipBit(w);
                  } else if (ConciseSetUtils.isLiteral(w)) {
                    flipBitLiteral |= w;
                  } else {
                    flipBitLiteral |= ConciseSetUtils.getLiteralFromZeroSeqFlipBit(w);
                  }
                }*/

                i.advanceTo(itr.wordsWalked);
                if (i.hasNext()) {
                    wordsToAdd.add(new WordHolder(i.next(), i));
                }
                nextVal = theQ.peek();
            }

            // advance longest one literal forward and push result back to priority queue
            // if a flip bit is still needed, put it in the correct position
            /*int newWord = word & 0xC1FFFFFF;
            if (flipBitLiteral != ConciseSetUtils.ALL_ONES_LITERAL) {
              flipBitLiteral ^= ConciseSetUtils.ALL_ONES_LITERAL;
              int position = Integer.numberOfTrailingZeros(flipBitLiteral) + 1;
              newWord |= (position << 25);
            }*/
            addAndCompact(retVal, word);
            currIndex = itr.wordsWalked;

            if (itr.hasNext()) {
                wordsToAdd.add(new WordHolder(itr.next(), itr));
            }
        } else if (ConciseSetUtils.isLiteral(word)) {
            // advance all other literals
            WordHolder nextVal = theQ.peek();
            while (nextVal != null && nextVal.getIterator().startIndex == itr.startIndex) {

                WordHolder entry = theQ.poll();
                int w = entry.getWord();
                WordIterator i = entry.getIterator();

                // if we still have zero fills with flipped bits, OR them here
                if (ConciseSetUtils.isLiteral(w)) {
                    word |= w;
                    if (word == 0xffffffff)
                        word = 0x10000001;
                } else {
                    /*int flipBitLiteral = ConciseSetUtils.getLiteralFromZeroSeqFlipBit(w);
                    if (flipBitLiteral != ConciseSetUtils.ALL_ZEROS_LITERAL) {
                      word |= flipBitLiteral;
                      i.advanceTo(itr.wordsWalked);
                    }*/
                    if (ConciseSetUtils.is1_fill(w)) {
                        word = 0x10000001;
                        i.advanceTo(itr.wordsWalked);
                    }
                }

                if (i.hasNext()) {
                    wordsToAdd.add(new WordHolder(i.next(), i));
                }

                nextVal = theQ.peek();
            }

            // advance the set with the current literal forward and push result back to priority queue
            addAndCompact(retVal, word);
            currIndex++;

            if (itr.hasNext()) {
                wordsToAdd.add(new WordHolder(itr.next(), itr));
            }
        } else { // zero fills
            WordHolder nextVal = theQ.peek();

            while (nextVal != null && nextVal.getIterator().startIndex == itr.startIndex) {
                // check if literal can be created flip bits of other zero sequences
                WordHolder entry = theQ.poll();
                int w = entry.getWord();
                WordIterator i = entry.getIterator();

                if (i.hasNext()) {
                    wordsToAdd.add(new WordHolder(i.next(), i));
                }
                nextVal = theQ.peek();
            }

            // check if a literal needs to be created from the flipped bits of this sequence
            if (itr.hasNext()) {
                wordsToAdd.add(new WordHolder(itr.next(), itr));
            }

        }

        theQ.addAll(wordsToAdd);
    }

    if (retVal.isEmpty()) {
        return new ImmutableSecompaxSet();
    }
    return new ImmutableSecompaxSet(IntBuffer.wrap(retVal.toArray()));
}

From source file:com.linkedin.pinot.core.query.aggregation.groupby.AggregationGroupByOperatorService.java

/**
 * Returns a MinMaxPriorityQueue with the given size limit, and ordering.
 * Will return null if the value to be inserted is not an instance of comparable.
 *
 * @param sampleObject To determine if the object is Comparable.
 * @param maxSize The max size for the heap.
 * @param reverseOrder True if sorting order to be reversed.
 * @return//from   w w w .j av  a 2 s .  co m
 */
private static MinMaxPriorityQueue<ImmutablePair<Serializable, String>> getMinMaxPriorityQueue(
        Serializable sampleObject, int maxSize, boolean reverseOrder) {
    if (!(sampleObject instanceof Comparable)) {
        return null;
    }

    Comparator<ImmutablePair<Serializable, String>> comparator = new GroupByResultComparator<ImmutablePair<Serializable, String>>()
            .newComparator(reverseOrder);

    MinMaxPriorityQueue.Builder<ImmutablePair<Serializable, String>> minMaxPriorityQueueBuilder = MinMaxPriorityQueue
            .orderedBy(comparator).maximumSize(maxSize);

    return minMaxPriorityQueueBuilder.create();
}

From source file:it.uniroma3.mat.extendedset.intset.ImmutableSecompaxSet.java

public static ImmutableSecompaxSet doIntersection(Iterator<ImmutableSecompaxSet> sets) {
    IntList retVal = new IntList();

    // lhs = current word position, rhs = the iterator
    // Comparison is first by index, then zero fills > literals > one fills
    // zero fills are sorted by length (longer zero fills have priority)
    // similarily, shorter one fills have priority
    MinMaxPriorityQueue<WordHolder> theQ = MinMaxPriorityQueue.orderedBy(new Comparator<WordHolder>() {
        @Override/*from  www .j  a  v  a  2s .  c  o  m*/
        public int compare(WordHolder h1, WordHolder h2) {
            int w1 = h1.getWord();
            int w2 = h2.getWord();
            int s1 = h1.getIterator().startIndex;
            int s2 = h2.getIterator().startIndex;

            if (s1 != s2) {
                return compareInts(s1, s2);
            }

            if (ConciseSetUtils.is0_fill(w1)) {
                if (ConciseSetUtils.is0_fill(w2)) {
                    return -compareInts(ConciseSetUtils.getSequenceNumWords(w1),
                            ConciseSetUtils.getSequenceNumWords(w2));
                }
                return -1;
            } else if (ConciseSetUtils.isLiteral(w1)) {
                if (ConciseSetUtils.is0_fill(w2)) {
                    return 1;
                } else if (ConciseSetUtils.isLiteral(w2)) {
                    return 0;
                }
                return -1;
            } else {
                if (!ConciseSetUtils.is1_fill(w2)) {
                    return 1;
                }
                return compareInts(ConciseSetUtils.getSequenceNumWords(w1),
                        ConciseSetUtils.getSequenceNumWords(w2));
            }
        }
    }).create();

    // populate priority queue
    while (sets.hasNext()) {
        ImmutableSecompaxSet set = sets.next();

        if (set == null || set.isEmpty()) {
            return new ImmutableSecompaxSet();
        }

        WordIterator itr = set.newWordIterator();
        theQ.add(new WordHolder(itr.next(), itr));
    }

    int currIndex = 0;
    int wordsWalkedAtSequenceEnd = Integer.MAX_VALUE;

    while (!theQ.isEmpty()) {
        // create a temp list to hold everything that will get pushed back into the priority queue after each run
        List<WordHolder> wordsToAdd = Lists.newArrayList();

        // grab the top element from the priority queue
        WordHolder curr = theQ.poll();
        int word = curr.getWord();
        WordIterator itr = curr.getIterator();

        // if a sequence has ended, we can break out because of Boolean logic
        if (itr.startIndex >= wordsWalkedAtSequenceEnd) {
            break;
        }

        // if the next word in the queue starts at a different point than where we ended off we need to create a one gap
        // to fill the space
        if (currIndex < itr.startIndex) {
            // number of 31 bit blocks that compromise the fill minus one
            addAndCompact(retVal, (0x10000000 | (itr.startIndex - currIndex)));
            currIndex = itr.startIndex;
        }

        if (ConciseSetUtils.is0_fill(word)) {
            // extract a literal from the flip bits of the zero sequence
            //int flipBitLiteral = ConciseSetUtils.getLiteralFromZeroSeqFlipBit(word);

            // advance everything past the longest zero sequence
            WordHolder nextVal = theQ.peek();
            while (nextVal != null && nextVal.getIterator().startIndex < itr.wordsWalked) {
                WordHolder entry = theQ.poll();
                int w = entry.getWord();
                WordIterator i = entry.getIterator();

                /*if (i.startIndex == itr.startIndex) {
                  // if a literal was created from a flip bit, AND it with other literals or literals from flip bits in the same
                  // position
                  if (ConciseSetUtils.isZeroSequence(w)) {
                    flipBitLiteral &= ConciseSetUtils.getLiteralFromZeroSeqFlipBit(w);
                  } else if (ConciseSetUtils.isLiteral(w)) {
                    flipBitLiteral &= w;
                  } else {
                    flipBitLiteral &= ConciseSetUtils.getLiteralFromOneSeqFlipBit(w);
                  }
                }*/

                i.advanceTo(itr.wordsWalked);
                if (i.hasNext()) {
                    wordsToAdd.add(new WordHolder(i.next(), i));
                } else {
                    wordsWalkedAtSequenceEnd = Math.min(i.wordsWalked, wordsWalkedAtSequenceEnd);
                }
                nextVal = theQ.peek();
            }

            // advance longest zero literal forward and push result back to priority queue
            // if a flip bit is still needed, put it in the correct position
            //int newWord = word & 0xC1FFFFFF;
            /*if (flipBitLiteral != ConciseSetUtils.ALL_ZEROS_LITERAL) {
              int position = Integer.numberOfTrailingZeros(flipBitLiteral) + 1;
              newWord = (word & 0xC1FFFFFF) | (position << 25);
            }*/
            addAndCompact(retVal, word);
            currIndex = itr.wordsWalked;

            if (itr.hasNext()) {
                wordsToAdd.add(new WordHolder(itr.next(), itr));
            } else {
                wordsWalkedAtSequenceEnd = Math.min(itr.wordsWalked, wordsWalkedAtSequenceEnd);
            }
        } else if (ConciseSetUtils.isLiteral(word)) {
            // advance all other literals
            WordHolder nextVal = theQ.peek();
            while (nextVal != null && nextVal.getIterator().startIndex == itr.startIndex) {

                WordHolder entry = theQ.poll();
                int w = entry.getWord();
                WordIterator i = entry.getIterator();

                // if we still have one fills with flipped bits, AND them here
                if (ConciseSetUtils.isLiteral(w)) {
                    word &= w;
                } else {
                    /*int flipBitLiteral = ConciseSetUtils.getLiteralFromOneSeqFlipBit(w);
                    if (flipBitLiteral != ConciseSetUtils.ALL_ONES_LITERAL) {
                      word &= flipBitLiteral;
                      i.advanceTo(itr.wordsWalked);
                    }*/
                    if (ConciseSetUtils.is0_fill(w)) {
                        word = 0x00000001;
                        i.advanceTo(itr.wordsWalked);
                    } else {
                        i.advanceTo(itr.wordsWalked);
                    }
                }

                if (i.hasNext()) {
                    wordsToAdd.add(new WordHolder(i.next(), i));
                } else {
                    wordsWalkedAtSequenceEnd = Math.min(i.wordsWalked, wordsWalkedAtSequenceEnd);
                }

                nextVal = theQ.peek();
            }

            // advance the set with the current literal forward and push result back to priority queue
            addAndCompact(retVal, word);
            currIndex++;

            if (itr.hasNext()) {
                wordsToAdd.add(new WordHolder(itr.next(), itr));
            } else {
                wordsWalkedAtSequenceEnd = Math.min(itr.wordsWalked, wordsWalkedAtSequenceEnd);
            }
        } else { // one fills
            //int flipBitLiteral;
            WordHolder nextVal = theQ.peek();

            while (nextVal != null && nextVal.getIterator().startIndex == itr.startIndex) {
                // check if literal can be created flip bits of other one sequences
                WordHolder entry = theQ.poll();
                int w = entry.getWord();
                WordIterator i = entry.getIterator();
                i.advanceTo(itr.wordsWalked);
                /*flipBitLiteral = ConciseSetUtils.getLiteralFromOneSeqFlipBit(w);
                if (flipBitLiteral != ConciseSetUtils.ALL_ONES_LITERAL) {
                  wordsToAdd.add(new WordHolder(flipBitLiteral, i));
                } else */if (i.hasNext()) {
                    wordsToAdd.add(new WordHolder(i.next(), i));
                } else {
                    wordsWalkedAtSequenceEnd = Math.min(i.wordsWalked, wordsWalkedAtSequenceEnd);
                }

                nextVal = theQ.peek();
            }

            // check if a literal needs to be created from the flipped bits of this sequence
            //flipBitLiteral = ConciseSetUtils.getLiteralFromOneSeqFlipBit(word);
            /*if (flipBitLiteral != ConciseSetUtils.ALL_ONES_LITERAL) {
              wordsToAdd.add(new WordHolder(flipBitLiteral, itr));
            } else */if (itr.hasNext()) {
                wordsToAdd.add(new WordHolder(itr.next(), itr));
            } else {
                wordsWalkedAtSequenceEnd = Math.min(itr.wordsWalked, wordsWalkedAtSequenceEnd);
            }
        }

        theQ.addAll(wordsToAdd);
    }

    // fill in any missing one sequences
    if (currIndex < wordsWalkedAtSequenceEnd) {
        addAndCompact(retVal, (0x10000000 | (wordsWalkedAtSequenceEnd - currIndex)));
    }

    if (retVal.isEmpty()) {
        return new ImmutableSecompaxSet();
    }
    return new ImmutableSecompaxSet(IntBuffer.wrap(retVal.toArray()));
}