Package org.elasticsearch.common.trove.map.hash

Examples of org.elasticsearch.common.trove.map.hash.TLongIntHashMap


    @Override protected void doCollect(int doc) throws IOException {
        fieldData.forEachValueInDoc(doc, aggregator);
    }

    @Override public Facet facet() {
        TLongIntHashMap facets = aggregator.facets();
        if (facets.isEmpty()) {
            CacheRecycler.pushLongIntMap(facets);
            return new InternalIpTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalIpTermsFacet.LongEntry>of(), aggregator.missing(), aggregator.total());
        } else {
            if (size < EntryPriorityQueue.LIMIT) {
                EntryPriorityQueue ordered = new EntryPriorityQueue(size, comparatorType.comparator());
                for (TLongIntIterator it = facets.iterator(); it.hasNext(); ) {
                    it.advance();
                    ordered.insertWithOverflow(new InternalIpTermsFacet.LongEntry(it.key(), it.value()));
                }
                InternalIpTermsFacet.LongEntry[] list = new InternalIpTermsFacet.LongEntry[ordered.size()];
                for (int i = ordered.size() - 1; i >= 0; i--) {
                    list[i] = (InternalIpTermsFacet.LongEntry) ordered.pop();
                }
                CacheRecycler.pushLongIntMap(facets);
                return new InternalIpTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing(), aggregator.total());
            } else {
                BoundedTreeSet<InternalIpTermsFacet.LongEntry> ordered = new BoundedTreeSet<InternalIpTermsFacet.LongEntry>(comparatorType.comparator(), size);
                for (TLongIntIterator it = facets.iterator(); it.hasNext(); ) {
                    it.advance();
                    ordered.add(new InternalIpTermsFacet.LongEntry(it.key(), it.value()));
                }
                CacheRecycler.pushLongIntMap(facets);
                return new InternalIpTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing(), aggregator.total());
View Full Code Here


    @Override protected void doCollect(int doc) throws IOException {
        fieldData.forEachValueInDoc(doc, aggregator);
    }

    @Override public Facet facet() {
        TLongIntHashMap facets = aggregator.facets();
        if (facets.isEmpty()) {
            CacheRecycler.pushLongIntMap(facets);
            return new InternalLongTermsFacet(facetName, comparatorType, size, ImmutableList.<InternalLongTermsFacet.LongEntry>of(), aggregator.missing(), aggregator.total());
        } else {
            if (size < EntryPriorityQueue.LIMIT) {
                EntryPriorityQueue ordered = new EntryPriorityQueue(size, comparatorType.comparator());
                for (TLongIntIterator it = facets.iterator(); it.hasNext(); ) {
                    it.advance();
                    ordered.insertWithOverflow(new InternalLongTermsFacet.LongEntry(it.key(), it.value()));
                }
                InternalLongTermsFacet.LongEntry[] list = new InternalLongTermsFacet.LongEntry[ordered.size()];
                for (int i = ordered.size() - 1; i >= 0; i--) {
                    list[i] = (InternalLongTermsFacet.LongEntry) ordered.pop();
                }
                CacheRecycler.pushLongIntMap(facets);
                return new InternalLongTermsFacet(facetName, comparatorType, size, Arrays.asList(list), aggregator.missing(), aggregator.total());
            } else {
                BoundedTreeSet<InternalLongTermsFacet.LongEntry> ordered = new BoundedTreeSet<InternalLongTermsFacet.LongEntry>(comparatorType.comparator(), size);
                for (TLongIntIterator it = facets.iterator(); it.hasNext(); ) {
                    it.advance();
                    ordered.add(new InternalLongTermsFacet.LongEntry(it.key(), it.value()));
                }
                CacheRecycler.pushLongIntMap(facets);
                return new InternalLongTermsFacet(facetName, comparatorType, size, ordered, aggregator.missing(), aggregator.total());
View Full Code Here

    @Override public Facet reduce(String name, List<Facet> facets) {
        if (facets.size() == 1) {
            return facets.get(0);
        }
        InternalIpTermsFacet first = (InternalIpTermsFacet) facets.get(0);
        TLongIntHashMap aggregated = CacheRecycler.popLongIntMap();
        long missing = 0;
        long total = 0;
        for (Facet facet : facets) {
            InternalIpTermsFacet mFacet = (InternalIpTermsFacet) facet;
            missing += mFacet.missingCount();
            total += mFacet.totalCount();
            for (LongEntry entry : mFacet.entries) {
                aggregated.adjustOrPutValue(entry.term, entry.count(), entry.count());
            }
        }

        BoundedTreeSet<LongEntry> ordered = new BoundedTreeSet<LongEntry>(first.comparatorType.comparator(), first.requiredSize);
        for (TLongIntIterator it = aggregated.iterator(); it.hasNext(); ) {
            it.advance();
            ordered.add(new LongEntry(it.key(), it.value()));
        }
        first.entries = ordered;
        first.missing = missing;
View Full Code Here

    @Override public Facet reduce(String name, List<Facet> facets) {
        if (facets.size() == 1) {
            return facets.get(0);
        }
        InternalLongTermsFacet first = (InternalLongTermsFacet) facets.get(0);
        TLongIntHashMap aggregated = CacheRecycler.popLongIntMap();
        long missing = 0;
        long total = 0;
        for (Facet facet : facets) {
            InternalLongTermsFacet mFacet = (InternalLongTermsFacet) facet;
            missing += mFacet.missingCount();
            total += mFacet.totalCount();
            for (LongEntry entry : mFacet.entries) {
                aggregated.adjustOrPutValue(entry.term, entry.count(), entry.count());
            }
        }

        BoundedTreeSet<LongEntry> ordered = new BoundedTreeSet<LongEntry>(first.comparatorType.comparator(), first.requiredSize);
        for (TLongIntIterator it = aggregated.iterator(); it.hasNext(); ) {
            it.advance();
            ordered.add(new LongEntry(it.key(), it.value()));
        }
        first.entries = ordered;
        first.missing = missing;
View Full Code Here

public class SerializationTest {

    @Test
    public void testSerializingEmptyCountingFacet() throws Exception {
        final TLongIntHashMap counts = CacheRecycler.popLongIntMap();
        testSerializingCountingFacet(counts);
    }
View Full Code Here

        testSerializingCountingFacet(counts);
    }

    @Test
    public void testSerializingNonEmptyCountingFacet() throws Exception {
        final TLongIntHashMap counts = CacheRecycler.popLongIntMap();
        counts.put(1, 2);
        counts.put(11, 22);
        testSerializingCountingFacet(counts);
    }
View Full Code Here

        counts.put(11, 22);
        testSerializingCountingFacet(counts);
    }

    private void testSerializingCountingFacet(final TLongIntHashMap counts) throws Exception {
        final TLongIntHashMap sentCounts = new TLongIntHashMap(counts);
        final InternalCountingFacet toSend = new InternalCountingFacet("foo", sentCounts);
        final InternalCountingFacet toReceive = new InternalCountingFacet();
        serializeAndDeserialize(toSend, toReceive);
        final TLongIntHashMap receivedCounts = new TLongIntHashMap(toReceive.peekCounts());
        // Check against original counts as sentCounts may have been recycled
        compareCounts(counts, receivedCounts);
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.common.trove.map.hash.TLongIntHashMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.