From 107238d13e523f9a4fb41f5c37afb0d1279a2ffe Mon Sep 17 00:00:00 2001 From: Laimonas Simutis Date: Tue, 3 Feb 2015 06:09:46 -0500 Subject: [PATCH 1/2] fix empty if statement --- src/Lucene.Net.Core/Index/BufferedUpdates.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Lucene.Net.Core/Index/BufferedUpdates.cs b/src/Lucene.Net.Core/Index/BufferedUpdates.cs index 2d507d327e..9bfe4f2a1f 100644 --- a/src/Lucene.Net.Core/Index/BufferedUpdates.cs +++ b/src/Lucene.Net.Core/Index/BufferedUpdates.cs @@ -282,7 +282,7 @@ public virtual void AddBinaryUpdate(BinaryDocValuesUpdate update, int docIDUpto) { /*Linked*/ HashMap fieldUpdates; - if (!BinaryUpdates.TryGetValue(update.Field, out fieldUpdates)) ; + if (!BinaryUpdates.TryGetValue(update.Field, out fieldUpdates)) { fieldUpdates = new /*Linked*/HashMap(); BinaryUpdates[update.Field] = fieldUpdates; From 0275b4dafa908b301870bdb19b19b06ee76ee789 Mon Sep 17 00:00:00 2001 From: Laimonas Simutis Date: Tue, 3 Feb 2015 16:34:13 -0500 Subject: [PATCH 2/2] use OrderedDictionary to preserve insertion order --- src/Lucene.Net.Core/Index/BufferedUpdates.cs | 42 ++++++++++++------- .../Index/FrozenBufferedUpdates.cs | 4 +- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/Lucene.Net.Core/Index/BufferedUpdates.cs b/src/Lucene.Net.Core/Index/BufferedUpdates.cs index 9bfe4f2a1f..a043e871e9 100644 --- a/src/Lucene.Net.Core/Index/BufferedUpdates.cs +++ b/src/Lucene.Net.Core/Index/BufferedUpdates.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.Specialized; namespace Lucene.Net.Index { @@ -126,21 +127,21 @@ load factor (say 2 * POINTER). Entry is object w/ // Map> // 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 + // update Term. OrderedDictionary 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> NumericUpdates = new Dictionary>(); + internal readonly IDictionary NumericUpdates = new Dictionary(); // Map> // 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 + // update Term. OrderedDictionary 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> BinaryUpdates = new Dictionary>(); + internal readonly IDictionary BinaryUpdates = new Dictionary(); public static readonly int MAX_INT = Convert.ToInt32(int.MaxValue); @@ -246,15 +247,21 @@ public virtual void AddTerm(Term term, int docIDUpto) public virtual void AddNumericUpdate(NumericDocValuesUpdate update, int docIDUpto) { - /*Linked*/HashMap fieldUpdates; + OrderedDictionary fieldUpdates = null; if (!NumericUpdates.TryGetValue(update.Field, out fieldUpdates)) { - fieldUpdates = new /*Linked*/HashMap(); + fieldUpdates = new OrderedDictionary(); NumericUpdates[update.Field] = fieldUpdates; BytesUsed.AddAndGet(BYTES_PER_NUMERIC_FIELD_ENTRY); } - NumericDocValuesUpdate current; - if (fieldUpdates.TryGetValue(update.Term, out current) && docIDUpto < current.DocIDUpto) + + NumericDocValuesUpdate current = null; + if (fieldUpdates.Contains(update.Term)) + { + current = fieldUpdates[update.Term] as NumericDocValuesUpdate; + } + + if (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 @@ -264,7 +271,7 @@ public virtual void AddNumericUpdate(NumericDocValuesUpdate update, int docIDUpt } update.DocIDUpto = docIDUpto; - // since it's a LinkedHashMap, we must first remove the Term entry so that + // since it's an OrderedDictionary, we must first remove the Term entry so that // it's added last (we're interested in insertion-order). if (current != null) { @@ -280,16 +287,21 @@ public virtual void AddNumericUpdate(NumericDocValuesUpdate update, int docIDUpt public virtual void AddBinaryUpdate(BinaryDocValuesUpdate update, int docIDUpto) { - /*Linked*/ - HashMap fieldUpdates; + OrderedDictionary fieldUpdates; if (!BinaryUpdates.TryGetValue(update.Field, out fieldUpdates)) { - fieldUpdates = new /*Linked*/HashMap(); + fieldUpdates = new OrderedDictionary(); BinaryUpdates[update.Field] = fieldUpdates; BytesUsed.AddAndGet(BYTES_PER_BINARY_FIELD_ENTRY); } - BinaryDocValuesUpdate current; - if (fieldUpdates.TryGetValue(update.Term, out current) && docIDUpto < current.DocIDUpto) + + BinaryDocValuesUpdate current = null; + if (fieldUpdates.Contains(update.Term)) + { + current = fieldUpdates[update.Term] as BinaryDocValuesUpdate; + } + + if (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 @@ -299,7 +311,7 @@ public virtual void AddBinaryUpdate(BinaryDocValuesUpdate update, int docIDUpto) } update.DocIDUpto = docIDUpto; - // since it's a LinkedHashMap, we must first remove the Term entry so that + // since it's an OrderedDictionary, we must first remove the Term entry so that // it's added last (we're interested in insertion-order). if (current != null) { diff --git a/src/Lucene.Net.Core/Index/FrozenBufferedUpdates.cs b/src/Lucene.Net.Core/Index/FrozenBufferedUpdates.cs index 8e73544c2d..af8584e409 100644 --- a/src/Lucene.Net.Core/Index/FrozenBufferedUpdates.cs +++ b/src/Lucene.Net.Core/Index/FrozenBufferedUpdates.cs @@ -95,7 +95,7 @@ public FrozenBufferedUpdates(BufferedUpdates deletes, bool isSegmentPrivate) // updated. IList allNumericUpdates = new List(); int numericUpdatesSize = 0; - foreach (/*Linked*/HashMap numericUpdates in deletes.NumericUpdates.Values) + foreach (var numericUpdates in deletes.NumericUpdates.Values) { foreach (NumericDocValuesUpdate update in numericUpdates.Values) { @@ -111,7 +111,7 @@ public FrozenBufferedUpdates(BufferedUpdates deletes, bool isSegmentPrivate) // updated. IList allBinaryUpdates = new List(); int binaryUpdatesSize = 0; - foreach (/*Linked*/HashMap binaryUpdates in deletes.BinaryUpdates.Values) + foreach (var binaryUpdates in deletes.BinaryUpdates.Values) { foreach (BinaryDocValuesUpdate update in binaryUpdates.Values) {