You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2017/04/04 17:19:31 UTC
[25/62] [abbrv] [partial] lucenenet git commit: Renamed
Lucene.Net.Core folder Lucene.Net because the dotnet.exe pack command doesn't
allow creating a NuGet package with a different name than its folder. Working
around it with the script was much more co
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Index/AutomatonTermsEnum.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/AutomatonTermsEnum.cs b/src/Lucene.Net.Core/Index/AutomatonTermsEnum.cs
deleted file mode 100644
index e969235..0000000
--- a/src/Lucene.Net.Core/Index/AutomatonTermsEnum.cs
+++ /dev/null
@@ -1,379 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-
-namespace Lucene.Net.Index
-{
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- using ByteRunAutomaton = Lucene.Net.Util.Automaton.ByteRunAutomaton;
- using BytesRef = Lucene.Net.Util.BytesRef;
- using CompiledAutomaton = Lucene.Net.Util.Automaton.CompiledAutomaton;
- using Int32sRef = Lucene.Net.Util.Int32sRef;
- using StringHelper = Lucene.Net.Util.StringHelper;
- using Transition = Lucene.Net.Util.Automaton.Transition;
-
- /// <summary>
- /// A <see cref="FilteredTermsEnum"/> that enumerates terms based upon what is accepted by a
- /// DFA.
- /// <para/>
- /// The algorithm is such:
- /// <list type="number">
- /// <item>As long as matches are successful, keep reading sequentially.</item>
- /// <item>When a match fails, skip to the next string in lexicographic order that
- /// does not enter a reject state.</item>
- /// </list>
- /// <para>
- /// The algorithm does not attempt to actually skip to the next string that is
- /// completely accepted. this is not possible when the language accepted by the
- /// FSM is not finite (i.e. * operator).
- /// </para>
- /// @lucene.experimental
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- internal class AutomatonTermsEnum : FilteredTermsEnum
- {
- // a tableized array-based form of the DFA
- private readonly ByteRunAutomaton runAutomaton;
-
- // common suffix of the automaton
- private readonly BytesRef commonSuffixRef;
-
- // true if the automaton accepts a finite language
- private readonly bool? finite;
-
- // array of sorted transitions for each state, indexed by state number
- private readonly Transition[][] allTransitions;
-
- // for path tracking: each long records gen when we last
- // visited the state; we use gens to avoid having to clear
- private readonly long[] visited;
-
- private long curGen;
-
- // the reference used for seeking forwards through the term dictionary
- private readonly BytesRef seekBytesRef = new BytesRef(10);
-
- // true if we are enumerating an infinite portion of the DFA.
- // in this case it is faster to drive the query based on the terms dictionary.
- // when this is true, linearUpperBound indicate the end of range
- // of terms where we should simply do sequential reads instead.
- private bool linear = false;
-
- private readonly BytesRef linearUpperBound = new BytesRef(10);
- private readonly IComparer<BytesRef> termComp;
-
- /// <summary>
- /// Construct an enumerator based upon an automaton, enumerating the specified
- /// field, working on a supplied <see cref="TermsEnum"/>
- /// <para/>
- /// @lucene.experimental
- /// </summary>
- /// <param name="tenum"> TermsEnum </param>
- /// <param name="compiled"> CompiledAutomaton </param>
- public AutomatonTermsEnum(TermsEnum tenum, CompiledAutomaton compiled)
- : base(tenum)
- {
- this.finite = compiled.Finite;
- this.runAutomaton = compiled.RunAutomaton;
- Debug.Assert(this.runAutomaton != null);
- this.commonSuffixRef = compiled.CommonSuffixRef;
- this.allTransitions = compiled.SortedTransitions;
-
- // used for path tracking, where each bit is a numbered state.
- visited = new long[runAutomaton.Count];
-
- termComp = Comparer;
- }
-
- /// <summary>
- /// Returns <c>true</c> if the term matches the automaton. Also stashes away the term
- /// to assist with smart enumeration.
- /// </summary>
- protected override AcceptStatus Accept(BytesRef term)
- {
- if (commonSuffixRef == null || StringHelper.EndsWith(term, commonSuffixRef))
- {
- if (runAutomaton.Run(term.Bytes, term.Offset, term.Length))
- {
- return linear ? AcceptStatus.YES : AcceptStatus.YES_AND_SEEK;
- }
- else
- {
- return (linear && termComp.Compare(term, linearUpperBound) < 0) ? AcceptStatus.NO : AcceptStatus.NO_AND_SEEK;
- }
- }
- else
- {
- return (linear && termComp.Compare(term, linearUpperBound) < 0) ? AcceptStatus.NO : AcceptStatus.NO_AND_SEEK;
- }
- }
-
- protected override BytesRef NextSeekTerm(BytesRef term)
- {
- //System.out.println("ATE.nextSeekTerm term=" + term);
- if (term == null)
- {
- Debug.Assert(seekBytesRef.Length == 0);
- // return the empty term, as its valid
- if (runAutomaton.IsAccept(runAutomaton.InitialState))
- {
- return seekBytesRef;
- }
- }
- else
- {
- seekBytesRef.CopyBytes(term);
- }
-
- // seek to the next possible string;
- if (NextString())
- {
- return seekBytesRef; // reposition
- }
- else
- {
- return null; // no more possible strings can match
- }
- }
-
- /// <summary>
- /// Sets the enum to operate in linear fashion, as we have found
- /// a looping transition at position: we set an upper bound and
- /// act like a <see cref="Search.TermRangeQuery"/> for this portion of the term space.
- /// </summary>
- private void SetLinear(int position)
- {
- Debug.Assert(linear == false);
-
- int state = runAutomaton.InitialState;
- int maxInterval = 0xff;
- for (int i = 0; i < position; i++)
- {
- state = runAutomaton.Step(state, seekBytesRef.Bytes[i] & 0xff);
- Debug.Assert(state >= 0, "state=" + state);
- }
- for (int i = 0; i < allTransitions[state].Length; i++)
- {
- Transition t = allTransitions[state][i];
- if (t.Min <= (seekBytesRef.Bytes[position] & 0xff) && (seekBytesRef.Bytes[position] & 0xff) <= t.Max)
- {
- maxInterval = t.Max;
- break;
- }
- }
- // 0xff terms don't get the optimization... not worth the trouble.
- if (maxInterval != 0xff)
- {
- maxInterval++;
- }
- int length = position + 1; // value + maxTransition
- if (linearUpperBound.Bytes.Length < length)
- {
- linearUpperBound.Bytes = new byte[length];
- }
- Array.Copy(seekBytesRef.Bytes, 0, linearUpperBound.Bytes, 0, position);
- linearUpperBound.Bytes[position] = (byte)maxInterval;
- linearUpperBound.Length = length;
-
- linear = true;
- }
-
- private readonly Int32sRef savedStates = new Int32sRef(10);
-
- /// <summary>
- /// Increments the byte buffer to the next string in binary order after s that will not put
- /// the machine into a reject state. If such a string does not exist, returns
- /// <c>false</c>.
- /// <para/>
- /// The correctness of this method depends upon the automaton being deterministic,
- /// and having no transitions to dead states.
- /// </summary>
- /// <returns> <c>true</c> if more possible solutions exist for the DFA </returns>
- private bool NextString()
- {
- int state;
- int pos = 0;
- savedStates.Grow(seekBytesRef.Length + 1);
- int[] states = savedStates.Int32s;
- states[0] = runAutomaton.InitialState;
-
- while (true)
- {
- curGen++;
- linear = false;
- // walk the automaton until a character is rejected.
- for (state = states[pos]; pos < seekBytesRef.Length; pos++)
- {
- visited[state] = curGen;
- int nextState = runAutomaton.Step(state, seekBytesRef.Bytes[pos] & 0xff);
- if (nextState == -1)
- {
- break;
- }
- states[pos + 1] = nextState;
- // we found a loop, record it for faster enumeration
- if ((finite == false) && !linear && visited[nextState] == curGen)
- {
- SetLinear(pos);
- }
- state = nextState;
- }
-
- // take the useful portion, and the last non-reject state, and attempt to
- // append characters that will match.
- if (NextString(state, pos))
- {
- return true;
- } // no more solutions exist from this useful portion, backtrack
- else
- {
- if ((pos = Backtrack(pos)) < 0) // no more solutions at all
- {
- return false;
- }
- int newState = runAutomaton.Step(states[pos], seekBytesRef.Bytes[pos] & 0xff);
- if (newState >= 0 && runAutomaton.IsAccept(newState))
- /* String is good to go as-is */
- {
- return true;
- }
- /* else advance further */
- // TODO: paranoia? if we backtrack thru an infinite DFA, the loop detection is important!
- // for now, restart from scratch for all infinite DFAs
- if (finite == false)
- {
- pos = 0;
- }
- }
- }
- }
-
- /// <summary>
- /// Returns the next string in lexicographic order that will not put
- /// the machine into a reject state.
- /// <para/>
- /// This method traverses the DFA from the given position in the string,
- /// starting at the given state.
- /// <para/>
- /// If this cannot satisfy the machine, returns <c>false</c>. This method will
- /// walk the minimal path, in lexicographic order, as long as possible.
- /// <para/>
- /// If this method returns <c>false</c>, then there might still be more solutions,
- /// it is necessary to backtrack to find out.
- /// </summary>
- /// <param name="state"> current non-reject state </param>
- /// <param name="position"> useful portion of the string </param>
- /// <returns> <c>true</c> if more possible solutions exist for the DFA from this
- /// position </returns>
- private bool NextString(int state, int position)
- {
- /*
- * the next lexicographic character must be greater than the existing
- * character, if it exists.
- */
- int c = 0;
- if (position < seekBytesRef.Length)
- {
- c = seekBytesRef.Bytes[position] & 0xff;
- // if the next byte is 0xff and is not part of the useful portion,
- // then by definition it puts us in a reject state, and therefore this
- // path is dead. there cannot be any higher transitions. backtrack.
- if (c++ == 0xff)
- {
- return false;
- }
- }
-
- seekBytesRef.Length = position;
- visited[state] = curGen;
-
- Transition[] transitions = allTransitions[state];
-
- // find the minimal path (lexicographic order) that is >= c
-
- for (int i = 0; i < transitions.Length; i++)
- {
- Transition transition = transitions[i];
- if (transition.Max >= c)
- {
- int nextChar = Math.Max(c, transition.Min);
- // append either the next sequential char, or the minimum transition
- seekBytesRef.Grow(seekBytesRef.Length + 1);
- seekBytesRef.Length++;
- seekBytesRef.Bytes[seekBytesRef.Length - 1] = (byte)nextChar;
- state = transition.Dest.Number;
- /*
- * as long as is possible, continue down the minimal path in
- * lexicographic order. if a loop or accept state is encountered, stop.
- */
- while (visited[state] != curGen && !runAutomaton.IsAccept(state))
- {
- visited[state] = curGen;
- /*
- * Note: we work with a DFA with no transitions to dead states.
- * so the below is ok, if it is not an accept state,
- * then there MUST be at least one transition.
- */
- transition = allTransitions[state][0];
- state = transition.Dest.Number;
-
- // append the minimum transition
- seekBytesRef.Grow(seekBytesRef.Length + 1);
- seekBytesRef.Length++;
- seekBytesRef.Bytes[seekBytesRef.Length - 1] = (byte)transition.Min;
-
- // we found a loop, record it for faster enumeration
- if ((finite == false) && !linear && visited[state] == curGen)
- {
- SetLinear(seekBytesRef.Length - 1);
- }
- }
- return true;
- }
- }
- return false;
- }
-
- /// <summary>
- /// Attempts to backtrack thru the string after encountering a dead end
- /// at some given position. Returns <c>false</c> if no more possible strings
- /// can match.
- /// </summary>
- /// <param name="position"> current position in the input string </param>
- /// <returns> position >=0 if more possible solutions exist for the DFA </returns>
- private int Backtrack(int position)
- {
- while (position-- > 0)
- {
- int nextChar = seekBytesRef.Bytes[position] & 0xff;
- // if a character is 0xff its a dead-end too,
- // because there is no higher character in binary sort order.
- if (nextChar++ != 0xff)
- {
- seekBytesRef.Bytes[position] = (byte)nextChar;
- seekBytesRef.Length = position + 1;
- return position;
- }
- }
- return -1; // all solutions exhausted
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Index/BaseCompositeReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/BaseCompositeReader.cs b/src/Lucene.Net.Core/Index/BaseCompositeReader.cs
deleted file mode 100644
index b175cc5..0000000
--- a/src/Lucene.Net.Core/Index/BaseCompositeReader.cs
+++ /dev/null
@@ -1,231 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace Lucene.Net.Index
-{
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- /// <summary>
- /// Base class for implementing <see cref="CompositeReader"/>s based on an array
- /// of sub-readers. The implementing class has to add code for
- /// correctly refcounting and closing the sub-readers.
- ///
- /// <para/>User code will most likely use <see cref="MultiReader"/> to build a
- /// composite reader on a set of sub-readers (like several
- /// <see cref="DirectoryReader"/>s).
- ///
- /// <para/> For efficiency, in this API documents are often referred to via
- /// <i>document numbers</i>, non-negative integers which each name a unique
- /// document in the index. These document numbers are ephemeral -- they may change
- /// as documents are added to and deleted from an index. Clients should thus not
- /// rely on a given document having the same number between sessions.
- ///
- /// <para/><b>NOTE</b>:
- /// <see cref="IndexReader"/> instances are completely thread
- /// safe, meaning multiple threads can call any of its methods,
- /// concurrently. If your application requires external
- /// synchronization, you should <b>not</b> synchronize on the
- /// <see cref="IndexReader"/> instance; use your own
- /// (non-Lucene) objects instead.
- /// <para/>
- /// @lucene.internal
- /// </summary>
- /// <seealso cref="MultiReader"/>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public abstract class BaseCompositeReader<R> : CompositeReader
- where R : IndexReader
- {
- private readonly R[] subReaders;
- private readonly int[] starts; // 1st docno for each reader
- private readonly int maxDoc;
- private readonly int numDocs;
-
- /// <summary>
- /// List view solely for <see cref="GetSequentialSubReaders()"/>,
- /// for effectiveness the array is used internally.
- /// </summary>
- private readonly IList<R> subReadersList;
-
- /// <summary>
- /// Constructs a <see cref="BaseCompositeReader{R}"/> on the given <paramref name="subReaders"/>. </summary>
- /// <param name="subReaders"> the wrapped sub-readers. This array is returned by
- /// <see cref="GetSequentialSubReaders()"/> and used to resolve the correct
- /// subreader for docID-based methods. <b>Please note:</b> this array is <b>not</b>
- /// cloned and not protected for modification, the subclass is responsible
- /// to do this. </param>
- protected BaseCompositeReader(R[] subReaders)
- {
- this.subReaders = subReaders;
- this.subReadersList = subReaders.ToList();// Collections.unmodifiableList(Arrays.asList(subReaders));
- starts = new int[subReaders.Length + 1]; // build starts array
- int maxDoc = 0, numDocs = 0;
- for (int i = 0; i < subReaders.Length; i++)
- {
- starts[i] = maxDoc;
- IndexReader r = subReaders[i];
- maxDoc += r.MaxDoc; // compute maxDocs
- if (maxDoc < 0) // overflow
- {
- throw new ArgumentException("Too many documents, composite IndexReaders cannot exceed " + int.MaxValue);
- }
- numDocs += r.NumDocs; // compute numDocs
- r.RegisterParentReader(this);
- }
- starts[subReaders.Length] = maxDoc;
- this.maxDoc = maxDoc;
- this.numDocs = numDocs;
- }
-
- public override sealed Fields GetTermVectors(int docID)
- {
- EnsureOpen();
- int i = ReaderIndex(docID); // find subreader num
- return subReaders[i].GetTermVectors(docID - starts[i]); // dispatch to subreader
- }
-
- public override sealed int NumDocs
- {
- get
- {
- // Don't call ensureOpen() here (it could affect performance)
- return numDocs;
- }
- }
-
- public override sealed int MaxDoc
- {
- get
- {
- // Don't call ensureOpen() here (it could affect performance)
- return maxDoc;
- }
- }
-
- public override sealed void Document(int docID, StoredFieldVisitor visitor)
- {
- EnsureOpen();
- int i = ReaderIndex(docID); // find subreader num
- subReaders[i].Document(docID - starts[i], visitor); // dispatch to subreader
- }
-
- public override sealed int DocFreq(Term term)
- {
- EnsureOpen();
- int total = 0; // sum freqs in subreaders
- for (int i = 0; i < subReaders.Length; i++)
- {
- total += subReaders[i].DocFreq(term);
- }
- return total;
- }
-
- public override sealed long TotalTermFreq(Term term)
- {
- EnsureOpen();
- long total = 0; // sum freqs in subreaders
- for (int i = 0; i < subReaders.Length; i++)
- {
- long sub = subReaders[i].TotalTermFreq(term);
- if (sub == -1)
- {
- return -1;
- }
- total += sub;
- }
- return total;
- }
-
- public override sealed long GetSumDocFreq(string field)
- {
- EnsureOpen();
- long total = 0; // sum doc freqs in subreaders
- foreach (R reader in subReaders)
- {
- long sub = reader.GetSumDocFreq(field);
- if (sub == -1)
- {
- return -1; // if any of the subs doesn't support it, return -1
- }
- total += sub;
- }
- return total;
- }
-
- public override sealed int GetDocCount(string field)
- {
- EnsureOpen();
- int total = 0; // sum doc counts in subreaders
- foreach (R reader in subReaders)
- {
- int sub = reader.GetDocCount(field);
- if (sub == -1)
- {
- return -1; // if any of the subs doesn't support it, return -1
- }
- total += sub;
- }
- return total;
- }
-
- public override sealed long GetSumTotalTermFreq(string field)
- {
- EnsureOpen();
- long total = 0; // sum doc total term freqs in subreaders
- foreach (R reader in subReaders)
- {
- long sub = reader.GetSumTotalTermFreq(field);
- if (sub == -1)
- {
- return -1; // if any of the subs doesn't support it, return -1
- }
- total += sub;
- }
- return total;
- }
-
- /// <summary>
- /// Helper method for subclasses to get the corresponding reader for a doc ID </summary>
- protected internal int ReaderIndex(int docID)
- {
- if (docID < 0 || docID >= maxDoc)
- {
- throw new System.ArgumentException("docID must be >= 0 and < maxDoc=" + maxDoc + " (got docID=" + docID + ")");
- }
- return ReaderUtil.SubIndex(docID, this.starts);
- }
-
- /// <summary>
- /// Helper method for subclasses to get the docBase of the given sub-reader index. </summary>
- protected internal int ReaderBase(int readerIndex)
- {
- if (readerIndex < 0 || readerIndex >= subReaders.Length)
- {
- throw new System.ArgumentException("readerIndex must be >= 0 and < getSequentialSubReaders().size()");
- }
- return this.starts[readerIndex];
- }
-
- protected internal override sealed IList<IndexReader> GetSequentialSubReaders()
- {
- return subReadersList.Cast<IndexReader>().ToList();
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Index/BinaryDocValues.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/BinaryDocValues.cs b/src/Lucene.Net.Core/Index/BinaryDocValues.cs
deleted file mode 100644
index 0f48b4b..0000000
--- a/src/Lucene.Net.Core/Index/BinaryDocValues.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-using System;
-
-namespace Lucene.Net.Index
-{
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- using BytesRef = Lucene.Net.Util.BytesRef;
-
- /// <summary>
- /// A per-document <see cref="T:byte[]"/>
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public abstract class BinaryDocValues
- {
- /// <summary>
- /// Sole constructor. (For invocation by subclass
- /// constructors, typically implicit.)
- /// </summary>
- protected BinaryDocValues()
- {
- }
-
- /// <summary>
- /// Lookup the value for document. </summary>
- public abstract void Get(int docID, BytesRef result);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Index/BinaryDocValuesFieldUpdates.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/BinaryDocValuesFieldUpdates.cs b/src/Lucene.Net.Core/Index/BinaryDocValuesFieldUpdates.cs
deleted file mode 100644
index c53f9c5..0000000
--- a/src/Lucene.Net.Core/Index/BinaryDocValuesFieldUpdates.cs
+++ /dev/null
@@ -1,288 +0,0 @@
-using System;
-using Lucene.Net.Documents;
-
-namespace Lucene.Net.Index
-{
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- using BinaryDocValuesField = BinaryDocValuesField;
- using BinaryDocValuesUpdate = Lucene.Net.Index.DocValuesUpdate.BinaryDocValuesUpdate;
- using BytesRef = Lucene.Net.Util.BytesRef;
- using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator;
- using FixedBitSet = Lucene.Net.Util.FixedBitSet;
- using InPlaceMergeSorter = Lucene.Net.Util.InPlaceMergeSorter;
- using PackedInt32s = Lucene.Net.Util.Packed.PackedInt32s;
- using PagedGrowableWriter = Lucene.Net.Util.Packed.PagedGrowableWriter;
- using PagedMutable = Lucene.Net.Util.Packed.PagedMutable;
-
- /// <summary>
- /// A <see cref="DocValuesFieldUpdates"/> which holds updates of documents, of a single
- /// <see cref="BinaryDocValuesField"/>.
- /// <para/>
- /// @lucene.experimental
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- internal class BinaryDocValuesFieldUpdates : DocValuesFieldUpdates
- {
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- new internal sealed class Iterator : DocValuesFieldUpdates.Iterator
- {
- private readonly PagedGrowableWriter offsets;
- private readonly int size;
- private readonly PagedGrowableWriter lengths;
- private readonly PagedMutable docs;
- private readonly FixedBitSet docsWithField;
- private long idx = 0; // long so we don't overflow if size == Integer.MAX_VALUE
- private int doc = -1;
- private readonly BytesRef value;
- private int offset, length;
-
- internal Iterator(int size, PagedGrowableWriter offsets, PagedGrowableWriter lengths, PagedMutable docs, BytesRef values, FixedBitSet docsWithField)
- {
- this.offsets = offsets;
- this.size = size;
- this.lengths = lengths;
- this.docs = docs;
- this.docsWithField = docsWithField;
- value = (BytesRef)values.Clone();
- }
-
- public override object Value
- {
- get
- {
- if (offset == -1)
- {
- return null;
- }
- else
- {
- value.Offset = offset;
- value.Length = length;
- return value;
- }
- }
- }
-
- public override int NextDoc()
- {
- if (idx >= size)
- {
- offset = -1;
- return doc = DocIdSetIterator.NO_MORE_DOCS;
- }
- doc = (int)docs.Get(idx);
- ++idx;
- while (idx < size && docs.Get(idx) == doc)
- {
- ++idx;
- }
- // idx points to the "next" element
- long prevIdx = idx - 1;
- if (!docsWithField.Get((int)prevIdx))
- {
- offset = -1;
- }
- else
- {
- // cannot change 'value' here because nextDoc is called before the
- // value is used, and it's a waste to clone the BytesRef when we
- // obtain the value
- offset = (int)offsets.Get(prevIdx);
- length = (int)lengths.Get(prevIdx);
- }
- return doc;
- }
-
- public override int Doc
- {
- get { return doc; }
- }
-
- public override void Reset()
- {
- doc = -1;
- offset = -1;
- idx = 0;
- }
- }
-
- private FixedBitSet docsWithField;
- private PagedMutable docs;
- private PagedGrowableWriter offsets, lengths;
- private BytesRef values;
- private int size;
-
- public BinaryDocValuesFieldUpdates(string field, int maxDoc)
- : base(field, DocValuesFieldUpdatesType.BINARY)
- {
- docsWithField = new FixedBitSet(64);
- docs = new PagedMutable(1, 1024, PackedInt32s.BitsRequired(maxDoc - 1), PackedInt32s.COMPACT);
- offsets = new PagedGrowableWriter(1, 1024, 1, PackedInt32s.FAST);
- lengths = new PagedGrowableWriter(1, 1024, 1, PackedInt32s.FAST);
- values = new BytesRef(16); // start small
- size = 0;
- }
-
- public override void Add(int doc, object value)
- {
- // TODO: if the Sorter interface changes to take long indexes, we can remove that limitation
- if (size == int.MaxValue)
- {
- throw new InvalidOperationException("cannot support more than System.Int32.MaxValue doc/value entries");
- }
-
- BytesRef val = (BytesRef)value;
- if (val == null)
- {
- val = BinaryDocValuesUpdate.MISSING;
- }
-
- // grow the structures to have room for more elements
- if (docs.Count == size)
- {
- docs = docs.Grow(size + 1);
- offsets = offsets.Grow(size + 1);
- lengths = lengths.Grow(size + 1);
- docsWithField = FixedBitSet.EnsureCapacity(docsWithField, (int)docs.Count);
- }
-
- if (val != BinaryDocValuesUpdate.MISSING)
- {
- // only mark the document as having a value in that field if the value wasn't set to null (MISSING)
- docsWithField.Set(size);
- }
-
- docs.Set(size, doc);
- offsets.Set(size, values.Length);
- lengths.Set(size, val.Length);
- values.Append(val);
- ++size;
- }
-
- public override DocValuesFieldUpdates.Iterator GetIterator()
- {
- PagedMutable docs = this.docs;
- PagedGrowableWriter offsets = this.offsets;
- PagedGrowableWriter lengths = this.lengths;
- BytesRef values = this.values;
- FixedBitSet docsWithField = this.docsWithField;
- new InPlaceMergeSorterAnonymousInnerClassHelper(this, docs, offsets, lengths, docsWithField).Sort(0, size);
-
- return new Iterator(size, offsets, lengths, docs, values, docsWithField);
- }
-
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- private class InPlaceMergeSorterAnonymousInnerClassHelper : InPlaceMergeSorter
- {
- private readonly BinaryDocValuesFieldUpdates outerInstance;
-
- private PagedMutable docs;
- private PagedGrowableWriter offsets;
- private PagedGrowableWriter lengths;
- private FixedBitSet docsWithField;
-
- public InPlaceMergeSorterAnonymousInnerClassHelper(BinaryDocValuesFieldUpdates outerInstance, PagedMutable docs, PagedGrowableWriter offsets, PagedGrowableWriter lengths, FixedBitSet docsWithField)
- {
- this.outerInstance = outerInstance;
- this.docs = docs;
- this.offsets = offsets;
- this.lengths = lengths;
- this.docsWithField = docsWithField;
- }
-
- protected override void Swap(int i, int j)
- {
- long tmpDoc = docs.Get(j);
- docs.Set(j, docs.Get(i));
- docs.Set(i, tmpDoc);
-
- long tmpOffset = offsets.Get(j);
- offsets.Set(j, offsets.Get(i));
- offsets.Set(i, tmpOffset);
-
- long tmpLength = lengths.Get(j);
- lengths.Set(j, lengths.Get(i));
- lengths.Set(i, tmpLength);
-
- bool tmpBool = docsWithField.Get(j);
- if (docsWithField.Get(i))
- {
- docsWithField.Set(j);
- }
- else
- {
- docsWithField.Clear(j);
- }
- if (tmpBool)
- {
- docsWithField.Set(i);
- }
- else
- {
- docsWithField.Clear(i);
- }
- }
-
- protected override int Compare(int i, int j)
- {
- int x = (int)docs.Get(i);
- int y = (int)docs.Get(j);
- return (x < y) ? -1 : ((x == y) ? 0 : 1);
- }
- }
-
- public override void Merge(DocValuesFieldUpdates other)
- {
- BinaryDocValuesFieldUpdates otherUpdates = (BinaryDocValuesFieldUpdates)other;
- int newSize = size + otherUpdates.size;
- if (newSize > int.MaxValue)
- {
- throw new InvalidOperationException("cannot support more than System.Int32.MaxValue doc/value entries; size=" + size + " other.size=" + otherUpdates.size);
- }
- docs = docs.Grow(newSize);
- offsets = offsets.Grow(newSize);
- lengths = lengths.Grow(newSize);
- docsWithField = FixedBitSet.EnsureCapacity(docsWithField, (int)docs.Count);
- for (int i = 0; i < otherUpdates.size; i++)
- {
- int doc = (int)otherUpdates.docs.Get(i);
- if (otherUpdates.docsWithField.Get(i))
- {
- docsWithField.Set(size);
- }
- docs.Set(size, doc);
- offsets.Set(size, values.Length + otherUpdates.offsets.Get(i)); // correct relative offset
- lengths.Set(size, otherUpdates.lengths.Get(i));
- ++size;
- }
- values.Append(otherUpdates.values);
- }
-
- public override bool Any()
- {
- return size > 0;
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Index/BinaryDocValuesWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/BinaryDocValuesWriter.cs b/src/Lucene.Net.Core/Index/BinaryDocValuesWriter.cs
deleted file mode 100644
index bc86650..0000000
--- a/src/Lucene.Net.Core/Index/BinaryDocValuesWriter.cs
+++ /dev/null
@@ -1,178 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Lucene.Net.Index
-{
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- using AppendingDeltaPackedInt64Buffer = Lucene.Net.Util.Packed.AppendingDeltaPackedInt64Buffer;
- using ArrayUtil = Lucene.Net.Util.ArrayUtil;
- using BytesRef = Lucene.Net.Util.BytesRef;
- using Counter = Lucene.Net.Util.Counter;
- using DataInput = Lucene.Net.Store.DataInput;
- using DataOutput = Lucene.Net.Store.DataOutput;
- using DocValuesConsumer = Lucene.Net.Codecs.DocValuesConsumer;
- using FixedBitSet = Lucene.Net.Util.FixedBitSet;
- using PackedInt32s = Lucene.Net.Util.Packed.PackedInt32s;
- using PagedBytes = Lucene.Net.Util.PagedBytes;
- using RamUsageEstimator = Lucene.Net.Util.RamUsageEstimator;
-
- /// <summary>
- /// Buffers up pending <see cref="T:byte[]"/> per doc, then flushes when
- /// segment flushes.
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- internal class BinaryDocValuesWriter : DocValuesWriter
- {
- /// <summary>
- /// Maximum length for a binary field. </summary>
- private static readonly int MAX_LENGTH = ArrayUtil.MAX_ARRAY_LENGTH;
-
- // 32 KB block sizes for PagedBytes storage:
- private const int BLOCK_BITS = 15;
-
- private readonly PagedBytes bytes;
- private readonly DataOutput bytesOut;
-
- private readonly Counter iwBytesUsed;
- private readonly AppendingDeltaPackedInt64Buffer lengths;
- private FixedBitSet docsWithField;
- private readonly FieldInfo fieldInfo;
- private int addedValues;
- private long bytesUsed;
-
- public BinaryDocValuesWriter(FieldInfo fieldInfo, Counter iwBytesUsed)
- {
- this.fieldInfo = fieldInfo;
- this.bytes = new PagedBytes(BLOCK_BITS);
- this.bytesOut = bytes.GetDataOutput();
- this.lengths = new AppendingDeltaPackedInt64Buffer(PackedInt32s.COMPACT);
- this.iwBytesUsed = iwBytesUsed;
- this.docsWithField = new FixedBitSet(64);
- this.bytesUsed = DocsWithFieldBytesUsed();
- iwBytesUsed.AddAndGet(bytesUsed);
- }
-
- public virtual void AddValue(int docID, BytesRef value)
- {
- if (docID < addedValues)
- {
- throw new System.ArgumentException("DocValuesField \"" + fieldInfo.Name + "\" appears more than once in this document (only one value is allowed per field)");
- }
- if (value == null)
- {
- throw new System.ArgumentException("field=\"" + fieldInfo.Name + "\": null value not allowed");
- }
- if (value.Length > MAX_LENGTH)
- {
- throw new System.ArgumentException("DocValuesField \"" + fieldInfo.Name + "\" is too large, must be <= " + MAX_LENGTH);
- }
-
- // Fill in any holes:
- while (addedValues < docID)
- {
- addedValues++;
- lengths.Add(0);
- }
- addedValues++;
- lengths.Add(value.Length);
- try
- {
- bytesOut.WriteBytes(value.Bytes, value.Offset, value.Length);
- }
- catch (System.IO.IOException ioe)
- {
- // Should never happen!
- throw new Exception(ioe.ToString(), ioe);
- }
- docsWithField = FixedBitSet.EnsureCapacity(docsWithField, docID);
- docsWithField.Set(docID);
- UpdateBytesUsed();
- }
-
- private long DocsWithFieldBytesUsed()
- {
- // size of the long[] + some overhead
- return RamUsageEstimator.SizeOf(docsWithField.Bits) + 64;
- }
-
- private void UpdateBytesUsed()
- {
- long newBytesUsed = lengths.RamBytesUsed() + bytes.RamBytesUsed() + DocsWithFieldBytesUsed();
- iwBytesUsed.AddAndGet(newBytesUsed - bytesUsed);
- bytesUsed = newBytesUsed;
- }
-
- public override void Finish(int maxDoc)
- {
- }
-
- public override void Flush(SegmentWriteState state, DocValuesConsumer dvConsumer)
- {
- int maxDoc = state.SegmentInfo.DocCount;
- bytes.Freeze(false);
- dvConsumer.AddBinaryField(fieldInfo, GetBytesIterator(maxDoc));
- }
-
- public override void Abort()
- {
- }
-
- private IEnumerable<BytesRef> GetBytesIterator(int maxDocParam)
- {
- // Use yield return instead of ucsom IEnumerable
-
- AppendingDeltaPackedInt64Buffer.Iterator lengthsIterator = lengths.GetIterator();
- int size = (int)lengths.Count;
- DataInput bytesIterator = bytes.GetDataInput();
- int maxDoc = maxDocParam;
- int upto = 0;
-
- while (upto < maxDoc)
- {
- BytesRef v = null;
- if (upto < size)
- {
- int length = (int)lengthsIterator.Next();
- var value = new BytesRef();
- value.Grow(length);
- value.Length = length;
- try
- {
- bytesIterator.ReadBytes(value.Bytes, value.Offset, value.Length);
- }
- catch (System.IO.IOException ioe)
- {
- // Should never happen!
- throw new Exception(ioe.ToString(), ioe);
- }
-
- if (docsWithField.Get(upto))
- {
- v = value;
- }
- }
-
- upto++;
- yield return v;
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Index/BitsSlice.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/BitsSlice.cs b/src/Lucene.Net.Core/Index/BitsSlice.cs
deleted file mode 100644
index 3875e24..0000000
--- a/src/Lucene.Net.Core/Index/BitsSlice.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-using System;
-using System.Diagnostics;
-
-namespace Lucene.Net.Index
-{
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- using IBits = Lucene.Net.Util.IBits;
-
- /// <summary>
- /// Exposes a slice of an existing <see cref="IBits"/> as a new <see cref="IBits"/>.
- /// <para/>
- /// @lucene.internal
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- internal sealed class BitsSlice : IBits
- {
- private readonly IBits parent;
- private readonly int start;
- private readonly int length;
-
- // start is inclusive; end is exclusive (length = end-start)
- public BitsSlice(IBits parent, ReaderSlice slice)
- {
- this.parent = parent;
- this.start = slice.Start;
- this.length = slice.Length;
- Debug.Assert(length >= 0, "length=" + length);
- }
-
- public bool Get(int doc)
- {
- if (doc >= length)
- {
- throw new Exception("doc " + doc + " is out of bounds 0 .. " + (length - 1));
- }
- Debug.Assert(doc < length, "doc=" + doc + " length=" + length);
- return parent.Get(doc + start);
- }
-
- public int Length
- {
- get { return length; }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Index/BufferedUpdates.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/BufferedUpdates.cs b/src/Lucene.Net.Core/Index/BufferedUpdates.cs
deleted file mode 100644
index cc4cdb5..0000000
--- a/src/Lucene.Net.Core/Index/BufferedUpdates.cs
+++ /dev/null
@@ -1,341 +0,0 @@
-using Lucene.Net.Support;
-using System;
-using System.Collections.Generic;
-using System.Collections.Specialized;
-
-namespace Lucene.Net.Index
-{
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- using BinaryDocValuesUpdate = Lucene.Net.Index.DocValuesUpdate.BinaryDocValuesUpdate;
- using NumericDocValuesUpdate = Lucene.Net.Index.DocValuesUpdate.NumericDocValuesUpdate;
- using Query = Lucene.Net.Search.Query;
- using RamUsageEstimator = Lucene.Net.Util.RamUsageEstimator;
-
-
- /// <summary>
- /// Holds buffered deletes and updates, by docID, term or query for a
- /// single segment. this is used to hold buffered pending
- /// deletes and updates against the to-be-flushed segment. Once the
- /// deletes and updates are pushed (on flush in <see cref="DocumentsWriter"/>), they
- /// are converted to a FrozenDeletes instance.
- /// <para/>
- /// NOTE: instances of this class are accessed either via a private
- /// instance on <see cref="DocumentsWriterPerThread"/>, or via sync'd code by
- /// <see cref="DocumentsWriterDeleteQueue"/>
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public class BufferedUpdates // LUCENENET NOTE: Made public rather than internal because it is available through a public API
- {
- /* Rough logic: HashMap has an array[Entry] w/ varying
- load factor (say 2 * POINTER). Entry is object w/ Term
- key, Integer val, int hash, Entry next
- (OBJ_HEADER + 3*POINTER + INT). Term is object w/
- String field and String text (OBJ_HEADER + 2*POINTER).
- Term's field is String (OBJ_HEADER + 4*INT + POINTER +
- OBJ_HEADER + string.length*CHAR).
- Term's text is String (OBJ_HEADER + 4*INT + POINTER +
- OBJ_HEADER + string.length*CHAR). Integer is
- OBJ_HEADER + INT. */
- internal static readonly int BYTES_PER_DEL_TERM = 9 * RamUsageEstimator.NUM_BYTES_OBJECT_REF + 7 * RamUsageEstimator.NUM_BYTES_OBJECT_HEADER + 10 * RamUsageEstimator.NUM_BYTES_INT32;
-
- /* Rough logic: del docIDs are List<Integer>. Say list
- allocates ~2X size (2*POINTER). Integer is OBJ_HEADER
- + int */
- internal static readonly int BYTES_PER_DEL_DOCID = 2 * RamUsageEstimator.NUM_BYTES_OBJECT_REF + RamUsageEstimator.NUM_BYTES_OBJECT_HEADER + RamUsageEstimator.NUM_BYTES_INT32;
-
- /* Rough logic: HashMap has an array[Entry] w/ varying
- load factor (say 2 * POINTER). Entry is object w/
- Query key, Integer val, int hash, Entry next
- (OBJ_HEADER + 3*POINTER + INT). Query we often
- undercount (say 24 bytes). Integer is OBJ_HEADER + INT. */
- internal static readonly int BYTES_PER_DEL_QUERY = 5 * RamUsageEstimator.NUM_BYTES_OBJECT_REF + 2 * RamUsageEstimator.NUM_BYTES_OBJECT_HEADER + 2 * RamUsageEstimator.NUM_BYTES_INT32 + 24;
-
- /* Rough logic: NumericUpdate calculates its actual size,
- * including the update Term and DV field (String). The
- * per-field map holds a reference to the updated field, and
- * therefore we only account for the object reference and
- * map space itself. this is incremented when we first see
- * an updated field.
- *
- * HashMap has an array[Entry] w/ varying load
- * factor (say 2*POINTER). Entry is an object w/ String key,
- * LinkedHashMap val, int hash, Entry next (OBJ_HEADER + 3*POINTER + INT).
- *
- * LinkedHashMap (val) is counted as OBJ_HEADER, array[Entry] ref + header, 4*INT, 1*FLOAT,
- * Set (entrySet) (2*OBJ_HEADER + ARRAY_HEADER + 2*POINTER + 4*INT + FLOAT)
- */
- internal static readonly int BYTES_PER_NUMERIC_FIELD_ENTRY = 7 * RamUsageEstimator.NUM_BYTES_OBJECT_REF + 3 * RamUsageEstimator.NUM_BYTES_OBJECT_HEADER + RamUsageEstimator.NUM_BYTES_ARRAY_HEADER + 5 * RamUsageEstimator.NUM_BYTES_INT32 + RamUsageEstimator.NUM_BYTES_SINGLE;
-
- /* Rough logic: Incremented when we see another Term for an already updated
- * field.
- * LinkedHashMap has an array[Entry] w/ varying load factor
- * (say 2*POINTER). Entry is an object w/ Term key, NumericUpdate val,
- * int hash, Entry next, Entry before, Entry after (OBJ_HEADER + 5*POINTER + INT).
- *
- * Term (key) is counted only as POINTER.
- * NumericUpdate (val) counts its own size and isn't accounted for here.
- */
- internal static readonly int BYTES_PER_NUMERIC_UPDATE_ENTRY = 7 * RamUsageEstimator.NUM_BYTES_OBJECT_REF + RamUsageEstimator.NUM_BYTES_OBJECT_HEADER + RamUsageEstimator.NUM_BYTES_INT32;
-
- /* Rough logic: BinaryUpdate calculates its actual size,
- * including the update Term and DV field (String). The
- * per-field map holds a reference to the updated field, and
- * therefore we only account for the object reference and
- * map space itself. this is incremented when we first see
- * an updated field.
- *
- * HashMap has an array[Entry] w/ varying load
- * factor (say 2*POINTER). Entry is an object w/ String key,
- * LinkedHashMap val, int hash, Entry next (OBJ_HEADER + 3*POINTER + INT).
- *
- * LinkedHashMap (val) is counted as OBJ_HEADER, array[Entry] ref + header, 4*INT, 1*FLOAT,
- * Set (entrySet) (2*OBJ_HEADER + ARRAY_HEADER + 2*POINTER + 4*INT + FLOAT)
- */
- internal static readonly int BYTES_PER_BINARY_FIELD_ENTRY = 7 * RamUsageEstimator.NUM_BYTES_OBJECT_REF + 3 * RamUsageEstimator.NUM_BYTES_OBJECT_HEADER + RamUsageEstimator.NUM_BYTES_ARRAY_HEADER + 5 * RamUsageEstimator.NUM_BYTES_INT32 + RamUsageEstimator.NUM_BYTES_SINGLE;
-
- /* Rough logic: Incremented when we see another Term for an already updated
- * field.
- * LinkedHashMap has an array[Entry] w/ varying load factor
- * (say 2*POINTER). Entry is an object w/ Term key, BinaryUpdate val,
- * int hash, Entry next, Entry before, Entry after (OBJ_HEADER + 5*POINTER + INT).
- *
- * Term (key) is counted only as POINTER.
- * BinaryUpdate (val) counts its own size and isn't accounted for here.
- */
- internal static readonly int BYTES_PER_BINARY_UPDATE_ENTRY = 7 * RamUsageEstimator.NUM_BYTES_OBJECT_REF + RamUsageEstimator.NUM_BYTES_OBJECT_HEADER + RamUsageEstimator.NUM_BYTES_INT32;
-
- internal readonly AtomicInt32 numTermDeletes = new AtomicInt32();
- internal readonly AtomicInt32 numNumericUpdates = new AtomicInt32();
- internal readonly AtomicInt32 numBinaryUpdates = new AtomicInt32();
- internal readonly IDictionary<Term, int?> terms = new Dictionary<Term, int?>();
- internal readonly IDictionary<Query, int?> queries = new Dictionary<Query, int?>();
- internal readonly IList<int?> docIDs = new List<int?>();
-
-
- // Map<dvField,Map<updateTerm,NumericUpdate>>
- // For each field we keep an ordered list of NumericUpdates, key'd by the
- // update Term. LinkedHashMap guarantees we will later traverse the map in
- // insertion order (so that if two terms affect the same document, the last
- // one that came in wins), and helps us detect faster if the same Term is
- // used to update the same field multiple times (so we later traverse it
- // only once).
- internal readonly IDictionary<string, LinkedHashMap<Term, NumericDocValuesUpdate>> numericUpdates = new Dictionary<string, LinkedHashMap<Term, NumericDocValuesUpdate>>();
-
- // Map<dvField,Map<updateTerm,BinaryUpdate>>
- // For each field we keep an ordered list of BinaryUpdates, key'd by the
- // update Term. LinkedHashMap guarantees we will later traverse the map in
- // insertion order (so that if two terms affect the same document, the last
- // one that came in wins), and helps us detect faster if the same Term is
- // used to update the same field multiple times (so we later traverse it
- // only once).
- internal readonly IDictionary<string, LinkedHashMap<Term, BinaryDocValuesUpdate>> binaryUpdates = new Dictionary<string, LinkedHashMap<Term, BinaryDocValuesUpdate>>();
-
- /// <summary>
- /// NOTE: This was MAX_INT in Lucene
- /// </summary>
- public static readonly int MAX_INT32 = Convert.ToInt32(int.MaxValue);
-
- internal readonly AtomicInt64 bytesUsed;
-
- private static bool VERBOSE_DELETES = false;
-
- internal long gen;
-
- internal BufferedUpdates() // LUCENENET NOTE: Made internal rather than public, since this class is intended to be internal but couldn't be because it is exposed through a public API
- {
- this.bytesUsed = new AtomicInt64();
- }
-
- public override string ToString()
- {
- if (VERBOSE_DELETES)
- {
- return "gen=" + gen + " numTerms=" + numTermDeletes + ", terms=" + Arrays.ToString(terms)
- + ", queries=" + Arrays.ToString(queries) + ", docIDs=" + Arrays.ToString(docIDs)
- + ", numericUpdates=" + Arrays.ToString(numericUpdates)
- + ", binaryUpdates=" + Arrays.ToString(binaryUpdates) + ", bytesUsed=" + bytesUsed;
- }
- else
- {
- string s = "gen=" + gen;
- if (numTermDeletes.Get() != 0)
- {
- s += " " + numTermDeletes.Get() + " deleted terms (unique count=" + terms.Count + ")";
- }
- if (queries.Count != 0)
- {
- s += " " + queries.Count + " deleted queries";
- }
- if (docIDs.Count != 0)
- {
- s += " " + docIDs.Count + " deleted docIDs";
- }
- if (numNumericUpdates.Get() != 0)
- {
- s += " " + numNumericUpdates.Get() + " numeric updates (unique count=" + numericUpdates.Count + ")";
- }
- if (numBinaryUpdates.Get() != 0)
- {
- s += " " + numBinaryUpdates.Get() + " binary updates (unique count=" + binaryUpdates.Count + ")";
- }
- if (bytesUsed.Get() != 0)
- {
- s += " bytesUsed=" + bytesUsed.Get();
- }
-
- return s;
- }
- }
-
- public virtual void AddQuery(Query query, int docIDUpto)
- {
- int? prev;
- queries.TryGetValue(query, out prev);
- queries[query] = docIDUpto;
- // increment bytes used only if the query wasn't added so far.
- if (prev == null)
- {
- bytesUsed.AddAndGet(BYTES_PER_DEL_QUERY);
- }
- }
-
- public virtual void AddDocID(int docID)
- {
- docIDs.Add(Convert.ToInt32(docID));
- bytesUsed.AddAndGet(BYTES_PER_DEL_DOCID);
- }
-
- public virtual void AddTerm(Term term, int docIDUpto)
- {
- int? current;
- terms.TryGetValue(term, out current);
- if (current != null && docIDUpto < current)
- {
- // Only record the new number if it's greater than the
- // current one. this is important because if multiple
- // threads are replacing the same doc at nearly the
- // same time, it's possible that one thread that got a
- // higher docID is scheduled before the other
- // threads. If we blindly replace than we can
- // incorrectly get both docs indexed.
- return;
- }
-
- terms[term] = Convert.ToInt32(docIDUpto);
- // note that if current != null then it means there's already a buffered
- // delete on that term, therefore we seem to over-count. this over-counting
- // is done to respect IndexWriterConfig.setMaxBufferedDeleteTerms.
- numTermDeletes.IncrementAndGet();
- if (current == null)
- {
- bytesUsed.AddAndGet(BYTES_PER_DEL_TERM + term.Bytes.Length + (RamUsageEstimator.NUM_BYTES_CHAR * term.Field.Length));
- }
- }
-
- public virtual void AddNumericUpdate(NumericDocValuesUpdate update, int docIDUpto)
- {
- LinkedHashMap<Term, NumericDocValuesUpdate> fieldUpdates = null;
- if (!numericUpdates.TryGetValue(update.field, out fieldUpdates))
- {
- fieldUpdates = new LinkedHashMap<Term, NumericDocValuesUpdate>();
- numericUpdates[update.field] = fieldUpdates;
- bytesUsed.AddAndGet(BYTES_PER_NUMERIC_FIELD_ENTRY);
- }
-
- NumericDocValuesUpdate current;
- if (fieldUpdates.TryGetValue(update.term, out current) && current != null && docIDUpto < current.docIDUpto)
- {
- // Only record the new number if it's greater than or equal to the current
- // one. this is important because if multiple threads are replacing the
- // same doc at nearly the same time, it's possible that one thread that
- // got a higher docID is scheduled before the other threads.
- return;
- }
-
- update.docIDUpto = docIDUpto;
- // since it's an LinkedHashMap, we must first remove the Term entry so that
- // it's added last (we're interested in insertion-order).
- if (current != null)
- {
- fieldUpdates.Remove(update.term);
- }
- fieldUpdates[update.term] = update;
- numNumericUpdates.IncrementAndGet();
- if (current == null)
- {
- bytesUsed.AddAndGet(BYTES_PER_NUMERIC_UPDATE_ENTRY + update.GetSizeInBytes());
- }
- }
-
- public virtual void AddBinaryUpdate(BinaryDocValuesUpdate update, int docIDUpto)
- {
- LinkedHashMap<Term, BinaryDocValuesUpdate> fieldUpdates;
- if (!binaryUpdates.TryGetValue(update.field, out fieldUpdates))
- {
- fieldUpdates = new LinkedHashMap<Term, BinaryDocValuesUpdate>();
- binaryUpdates[update.field] = fieldUpdates;
- bytesUsed.AddAndGet(BYTES_PER_BINARY_FIELD_ENTRY);
- }
-
- BinaryDocValuesUpdate current;
- if (fieldUpdates.TryGetValue(update.term, out current) && current != null && docIDUpto < current.docIDUpto)
- {
- // Only record the new number if it's greater than or equal to the current
- // one. this is important because if multiple threads are replacing the
- // same doc at nearly the same time, it's possible that one thread that
- // got a higher docID is scheduled before the other threads.
- return;
- }
-
- update.docIDUpto = docIDUpto;
- // since it's an LinkedHashMap, we must first remove the Term entry so that
- // it's added last (we're interested in insertion-order).
- if (current != null)
- {
- fieldUpdates.Remove(update.term);
- }
- fieldUpdates[update.term] = update;
- numBinaryUpdates.IncrementAndGet();
- if (current == null)
- {
- bytesUsed.AddAndGet(BYTES_PER_BINARY_UPDATE_ENTRY + update.GetSizeInBytes());
- }
- }
-
- internal virtual void Clear()
- {
- terms.Clear();
- queries.Clear();
- docIDs.Clear();
- numericUpdates.Clear();
- binaryUpdates.Clear();
- numTermDeletes.Set(0);
- numNumericUpdates.Set(0);
- numBinaryUpdates.Set(0);
- bytesUsed.Set(0);
- }
-
- internal virtual bool Any()
- {
- return terms.Count > 0 || docIDs.Count > 0 || queries.Count > 0 || numericUpdates.Count > 0 || binaryUpdates.Count > 0;
- }
- }
-}
\ No newline at end of file