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

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


        for (int i = 0; i < values.length; i++) {
            iValues[i] = ThreadLocalRandom.current().nextInt();
        }

        stopWatch = new StopWatch().start();
        TIntIntHashMap intMap = new TIntIntHashMap();
        for (long iter = 0; iter < ITERATIONS; iter++) {
            if (REUSE) {
                intMap.clear();
            } else {
                intMap = new TIntIntHashMap();
            }
            for (long i = 0; i < PUT_OPERATIONS; i++) {
                int key = iValues[(int) (i % NUMBER_OF_KEYS)];
                intMap.adjustOrPutValue(key, 1, 1);
            }
        }
        stopWatch.stop();
        System.out.println("TIntIntHashMap: " + stopWatch.totalTime() + ", " + stopWatch.totalTime().millisFrac() / ITERATIONS + "ms");

        intMap.clear();
        intMap = null;

        // now test with THashMap
        stopWatch = new StopWatch().start();
        TIntObjectHashMap<IntEntry> tIntMap = new TIntObjectHashMap<IntEntry>();
View Full Code Here


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

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

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

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

TOP

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

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.