Пример #1
0
        public void CountNoReturn(int id, BigSegmentedArray count)
        {
            int[] page = m_list[id >> PAGEID_SHIFT];
            if (page == null)
            {
                count.Add(0, count.Get(0) + 1);
                return;
            }

            int val = page[id & SLOTID_MASK];

            if (val >= 0)
            {
                count.Add(val, count.Get(val) + 1);
                return;
            }
            else if (val != MISSING)
            {
                int idx = -(val >> VALIDX_SHIFT); // signed shift, remember val is a negative number
                int cnt = (val & COUNT_MASK);
                int end = idx + cnt;
                while (idx < end)
                {
                    count.Add(page[idx], count.Get(page[idx]) + 1);
                    idx++;
                }
                return;
            }
            count.Add(0, count.Get(0) + 1);
            return;
        }
Пример #2
0
 private static void CountUpTestHelper(BigSegmentedArray array)
 {
     Initialize(array);
     Assert.AreEqual(short.MaxValue * 2, array.Length);
     for (int i = 0; i < array.Length; i++)
     {
         Assert.AreEqual(i % array.MaxValue, array.Get(i));
     }
 }
 private static void CountUpTestHelper(BigSegmentedArray array)
 {
     Initialize(array);
     Assert.AreEqual(short.MaxValue * 2, array.Size());
     for (int i = 0; i < array.Size(); i++)
     {
         Assert.AreEqual(i % array.MaxValue, array.Get(i));
     }
 }
Пример #4
0
 public static int[] ToArray(BigSegmentedArray original)
 {
     int[] result = new int[original.Size()];
     for (int i = 0; i < original.Size(); i++)
     {
         result[i] = original.Get(i);
     }
     return(result);
 }
Пример #5
0
        public void CountNoReturnWithFilter(int id, BigSegmentedArray count, OpenBitSet filter)
        {
            int[] page = _list[id >> PAGEID_SHIFT];
            if (page == null)
            {
                count.Add(0, count.Get(0) + 1);
                return;
            }

            int val = page[id & SLOTID_MASK];

            if (val >= 0)
            {
                if (filter.FastGet(val))
                {
                    count.Add(val, count.Get(val) + 1);
                }
                return;
            }
            else if (val != MISSING)
            {
                int idx = -(val >> VALIDX_SHIFT); // signed shift, remember val is a negative number
                int cnt = (val & COUNT_MASK);
                int end = idx + cnt;
                while (idx < end)
                {
                    int value = page[idx++];
                    if (filter.FastGet(value))
                    {
                        count.Add(value, count.Get(value) + 1);
                    }
                }
                return;
            }
            count.Add(0, count.Get(0) + 1);
            return;
        }
Пример #6
0
        private static void FillTestHelper(BigSegmentedArray array)
        {
            int a = array.MaxValue / 4;
            int b = array.MaxValue / 2;
            int c = array.MaxValue - 1;

            Assert.AreEqual(0, array.Get(20000));

            array.Fill(a);
            Assert.AreEqual(a, array.Get(20000));

            array.Add(20000, b);
            Assert.AreEqual(b, array.Get(20000));
            Assert.AreEqual(a, array.Get(20001));

            Assert.AreEqual(20000, array.FindValue(b, 0, 21000));

            array.Fill(c);
            Assert.AreEqual(c, array.Get(20000));
            Assert.AreEqual(c, array.Get(40000));
            Assert.AreEqual(c, array.Get(0));
        }
Пример #7
0
 private static void EmptyArrayTestHelper(BigSegmentedArray array)
 {
     Assert.AreEqual(0, array.Get(0));
     Assert.AreEqual(0, array.Length);
 }
 private static void EmptyArrayTestHelper(BigSegmentedArray array)
 {
     Assert.AreEqual(0, array.Get(0));
     Assert.AreEqual(0, array.Size());
 }
        private static void FillTestHelper(BigSegmentedArray array)
        {
            int a = array.MaxValue / 4;
            int b = array.MaxValue / 2;
            int c = array.MaxValue - 1;

            Assert.AreEqual(0, array.Get(20000));

            array.Fill(a);
            Assert.AreEqual(a, array.Get(20000));

            array.Add(20000, b);
            Assert.AreEqual(b, array.Get(20000));
            Assert.AreEqual(a, array.Get(20001));

            Assert.AreEqual(20000, array.FindValue(b, 0, 21000));

            array.Fill(c);
            Assert.AreEqual(c, array.Get(20000));
            Assert.AreEqual(c, array.Get(40000));
            Assert.AreEqual(c, array.Get(0));
        }
        public static IEnumerable<BrowseFacet> GetFacets(FacetSpec ospec, BigSegmentedArray count, int countlength, ITermValueList valList)
        {
            if (ospec != null)
            {
                int minCount = ospec.MinHitCount;
                int max = ospec.MaxCount;
                if (max <= 0) max = countlength;

                LinkedList<BrowseFacet> facetColl;
                FacetSpec.FacetSortSpec sortspec = ospec.OrderBy;
                if (sortspec == FacetSpec.FacetSortSpec.OrderValueAsc)
                {
                    facetColl = new LinkedList<BrowseFacet>();
                    for (int i = 1; i < countlength; ++i) // exclude zero
                    {
                        int hits = count.Get(i);
                        if (hits >= minCount)
                        {
                            BrowseFacet facet = new BrowseFacet(valList.Get(i), hits);
                            facetColl.AddLast(facet);
                        }

                        if (facetColl.Count >= max)
                            break;
                    }
                }
                else //if (sortspec == FacetSortSpec.OrderHitsDesc)
                {
                    IComparatorFactory comparatorFactory;
                    if (sortspec == FacetSpec.FacetSortSpec.OrderHitsDesc)
                    {
                        comparatorFactory = new FacetHitcountComparatorFactory();
                    }
                    else
                    {
                        comparatorFactory = ospec.CustomComparatorFactory;
                    }

                    if (comparatorFactory == null)
                    {
                        throw new ArgumentException("facet comparator factory not specified");
                    }

                    IComparer<int> comparator = comparatorFactory.NewComparator(new DefaultFacetCountCollectorFieldAccessor(valList), count);
                    facetColl = new LinkedList<BrowseFacet>();
                    int forbidden = -1;
                    IntBoundedPriorityQueue pq = new IntBoundedPriorityQueue(comparator, max, forbidden);

                    for (int i = 1; i < countlength; ++i) // exclude zero
                    {
                        int hits = count.Get(i);
                        if (hits >= minCount)
                        {
                            pq.Offer(i);
                        }
                    }

                    int val;
                    while ((val = pq.Poll()) != forbidden)
                    {
                        BrowseFacet facet = new BrowseFacet(valList[val], count.Get(val));
                        facetColl.AddFirst(facet);
                    }
                }
                return facetColl;
            }
            else
            {
                return FacetCountCollector_Fields.EMPTY_FACET_LIST;
            }
        }
Пример #11
0
        public void CountNoReturn(int id, BigSegmentedArray count)
        {
            int[] page = _list[id >> PAGEID_SHIFT];
            if (page == null)
            {
                count.Add(0, count.Get(0) + 1);
                return;
            }

            int val = page[id & SLOTID_MASK];
            if (val >= 0)
            {
                count.Add(val, count.Get(val) + 1);
                return;
            }
            else if (val != MISSING)
            {
                int idx = -(val >> VALIDX_SHIFT); // signed shift, remember val is a negative number
                int cnt = (val & COUNT_MASK);
                int end = idx + cnt;
                while (idx < end)
                {
                    count.Add(page[idx], count.Get(page[idx]) + 1);
                    idx++;
                }
                return;
            }
            count.Add(0, count.Get(0) + 1);
            return;
        }
Пример #12
0
        public void CountNoReturnWithFilter(int id, BigSegmentedArray count, OpenBitSet filter)
        {
            int[] page = _list[id >> PAGEID_SHIFT];
            if (page == null)
            {
                count.Add(0, count.Get(0) + 1);
                return;
            }

            int val = page[id & SLOTID_MASK];
            if (val >= 0)
            {
                if (filter.FastGet(val))
                {
                    count.Add(val, count.Get(val) + 1);
                }
                return;
            }
            else if (val != MISSING)
            {
                int idx = -(val >> VALIDX_SHIFT); // signed shift, remember val is a negative number
                int cnt = (val & COUNT_MASK);
                int end = idx + cnt;
                while (idx < end)
                {
                    int value = page[idx++];
                    if (filter.FastGet(value))
                    {
                        count.Add(value, count.Get(value) + 1);
                    }
                }
                return;
            }
            count.Add(0, count.Get(0) + 1);
            return;
        }
Пример #13
0
 public static int[] ToArray(BigSegmentedArray original)
 {
     int[] result = new int[original.Size()];
     for (int i = 0; i < original.Size(); i++)
     {
         result[i] = original.Get(i);
     }
     return result;
 }