/// <summary> /// Computes the old-to-new permutation over the given comparator. /// </summary> private static Sorter.DocMap Sort(int maxDoc, DocComparator comparator) { // check if the index is sorted bool sorted = true; for (int i = 1; i < maxDoc; ++i) { if (comparator.Compare(i - 1, i) > 0) { sorted = false; break; } } if (sorted) { return(null); } // sort doc IDs int[] docs = new int[maxDoc]; for (int i = 0; i < maxDoc; i++) { docs[i] = i; } DocValueSorter sorter = new DocValueSorter(docs, comparator); // It can be common to sort a reader, add docs, sort it again, ... and in // that case timSort can save a lot of time sorter.Sort(0, docs.Length); // docs is now the newToOld mapping // The reason why we use MonotonicAppendingLongBuffer here is that it // wastes very little memory if the index is in random order but can save // a lot of memory if the index is already "almost" sorted MonotonicAppendingLongBuffer newToOld = new MonotonicAppendingLongBuffer(); for (int i = 0; i < maxDoc; ++i) { newToOld.Add(docs[i]); } newToOld.Freeze(); for (int i = 0; i < maxDoc; ++i) { docs[(int)newToOld.Get(i)] = i; } // docs is now the oldToNew mapping MonotonicAppendingLongBuffer oldToNew = new MonotonicAppendingLongBuffer(); for (int i = 0; i < maxDoc; ++i) { oldToNew.Add(docs[i]); } oldToNew.Freeze(); return(new DocMapAnonymousInnerClassHelper(maxDoc, newToOld, oldToNew)); }
/// <summary> /// Computes the old-to-new permutation over the given comparator. </summary> //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: private static Sorter.DocMap sort(final int maxDoc, DocComparator comparator) private static Sorter.DocMap sort(int maxDoc, DocComparator comparator) { // check if the index is sorted bool sorted = true; for (int i = 1; i < maxDoc; ++i) { if (comparator.compare(i - 1, i) > 0) { sorted = false; break; } } if (sorted) { return(null); } // sort doc IDs //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int[] docs = new int[maxDoc]; int[] docs = new int[maxDoc]; for (int i = 0; i < maxDoc; i++) { docs[i] = i; } DocValueSorter sorter = new DocValueSorter(docs, comparator); // It can be common to sort a reader, add docs, sort it again, ... and in // that case timSort can save a lot of time sorter.sort(0, docs.Length); // docs is now the newToOld mapping // The reason why we use MonotonicAppendingLongBuffer here is that it // wastes very little memory if the index is in random order but can save // a lot of memory if the index is already "almost" sorted //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.apache.lucene.util.packed.MonotonicAppendingLongBuffer newToOld = new org.apache.lucene.util.packed.MonotonicAppendingLongBuffer(); MonotonicAppendingLongBuffer newToOld = new MonotonicAppendingLongBuffer(); for (int i = 0; i < maxDoc; ++i) { newToOld.add(docs[i]); } newToOld.freeze(); for (int i = 0; i < maxDoc; ++i) { docs[(int)newToOld.get(i)] = i; } // docs is now the oldToNew mapping //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.apache.lucene.util.packed.MonotonicAppendingLongBuffer oldToNew = new org.apache.lucene.util.packed.MonotonicAppendingLongBuffer(); MonotonicAppendingLongBuffer oldToNew = new MonotonicAppendingLongBuffer(); for (int i = 0; i < maxDoc; ++i) { oldToNew.add(docs[i]); } oldToNew.freeze(); return(new DocMapAnonymousInnerClassHelper(maxDoc, newToOld, oldToNew)); }