public CachedPostingListCounter rebuildCache() {
        MinMaxPriorityQueue<Entry> mostExpensive = MinMaxPriorityQueue.maximumSize(32).expectedSize(32).create();
        synchronized (this) {
            for (ObjectLongPair<int[]> p : frequency.keyValuesView()) {
                mostExpensive.add(new Entry(p.getOne(), p.getTwo()));
            }
        }
        ObjectIntHashMap<int[]> postingListMapping = new ObjectIntHashMap<>();
        int[] bitVector = new int[nDocuments];
        int length = mostExpensive.size();
        for (int i = 0; i < length; i++) {
            Entry e = mostExpensive.removeFirst();
            int[] docIds = e.docIds;
            postingListMapping.put(docIds, i);
            for (int docId : docIds) {
                bitVector[docId] |= (1 << i);
            }
        }
        return new CachedPostingListCounter(postingListMapping, bitVector);
    }
Counts the number of posting lists per document id.
Caches the most expensive posting list in a bit vector.

@author bjorncs
predicate-search/src/main/java/com/yahoo/search/predicate/index/CachedPostingListCounter.java