lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [2/2] lucenenet git commit: use OrderedDictionary to preserve insertion order
Date Tue, 03 Feb 2015 23:37:37 GMT
use OrderedDictionary to preserve insertion order


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/0275b4da
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/0275b4da
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/0275b4da

Branch: refs/heads/master
Commit: 0275b4dafa908b301870bdb19b19b06ee76ee789
Parents: 107238d
Author: Laimonas Simutis <laimis@gmail.com>
Authored: Tue Feb 3 16:34:13 2015 -0500
Committer: Laimonas Simutis <laimis@gmail.com>
Committed: Tue Feb 3 16:34:13 2015 -0500

----------------------------------------------------------------------
 src/Lucene.Net.Core/Index/BufferedUpdates.cs    | 42 +++++++++++++-------
 .../Index/FrozenBufferedUpdates.cs              |  4 +-
 2 files changed, 29 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/0275b4da/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
index 9bfe4f2..a043e87 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 @@ namespace Lucene.Net.Index
 
         // 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
+        // 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<string, /*Linked*/HashMap<Term, NumericDocValuesUpdate>>
NumericUpdates = new Dictionary<string, /*Linked*/HashMap<Term, NumericDocValuesUpdate>>();
+        internal readonly IDictionary<string, OrderedDictionary> NumericUpdates = new
Dictionary<string, OrderedDictionary>();
 
         // 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
+        // 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<string, /*Linked*/HashMap<Term, BinaryDocValuesUpdate>>
BinaryUpdates = new Dictionary<string, /*Linked*/HashMap<Term, BinaryDocValuesUpdate>>();
+        internal readonly IDictionary<string, OrderedDictionary> BinaryUpdates = new
Dictionary<string, OrderedDictionary>();
 
         public static readonly int MAX_INT = Convert.ToInt32(int.MaxValue);
 
@@ -246,15 +247,21 @@ namespace Lucene.Net.Index
 
         public virtual void AddNumericUpdate(NumericDocValuesUpdate update, int docIDUpto)
         {
-            /*Linked*/HashMap<Term, NumericDocValuesUpdate> fieldUpdates;
+            OrderedDictionary fieldUpdates = null;
             if (!NumericUpdates.TryGetValue(update.Field, out fieldUpdates))
             {
-                fieldUpdates = new /*Linked*/HashMap<Term, NumericDocValuesUpdate>();
+                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 @@ namespace Lucene.Net.Index
             }
 
             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 @@ namespace Lucene.Net.Index
 
         public virtual void AddBinaryUpdate(BinaryDocValuesUpdate update, int docIDUpto)
         {
-            /*Linked*/
-            HashMap<Term, BinaryDocValuesUpdate> fieldUpdates;
+            OrderedDictionary fieldUpdates;
             if (!BinaryUpdates.TryGetValue(update.Field, out fieldUpdates))
             {
-                fieldUpdates = new /*Linked*/HashMap<Term, BinaryDocValuesUpdate>();
+                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 @@ namespace Lucene.Net.Index
             }
 
             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)
             {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/0275b4da/src/Lucene.Net.Core/Index/FrozenBufferedUpdates.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/FrozenBufferedUpdates.cs b/src/Lucene.Net.Core/Index/FrozenBufferedUpdates.cs
index 8e73544..af8584e 100644
--- a/src/Lucene.Net.Core/Index/FrozenBufferedUpdates.cs
+++ b/src/Lucene.Net.Core/Index/FrozenBufferedUpdates.cs
@@ -95,7 +95,7 @@ namespace Lucene.Net.Index
             // updated.
             IList<NumericDocValuesUpdate> allNumericUpdates = new List<NumericDocValuesUpdate>();
             int numericUpdatesSize = 0;
-            foreach (/*Linked*/HashMap<Term, NumericDocValuesUpdate> numericUpdates
in deletes.NumericUpdates.Values)
+            foreach (var numericUpdates in deletes.NumericUpdates.Values)
             {
                 foreach (NumericDocValuesUpdate update in numericUpdates.Values)
                 {
@@ -111,7 +111,7 @@ namespace Lucene.Net.Index
             // updated.
             IList<BinaryDocValuesUpdate> allBinaryUpdates = new List<BinaryDocValuesUpdate>();
             int binaryUpdatesSize = 0;
-            foreach (/*Linked*/HashMap<Term, BinaryDocValuesUpdate> binaryUpdates in
deletes.BinaryUpdates.Values)
+            foreach (var binaryUpdates in deletes.BinaryUpdates.Values)
             {
                 foreach (BinaryDocValuesUpdate update in binaryUpdates.Values)
                 {


Mime
View raw message