You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by pn...@apache.org on 2014/09/28 10:50:14 UTC

[10/10] git commit: Lucene.Net.Codes/Sep fully ported, work done on SimpleText and Memory as well

Lucene.Net.Codes/Sep fully ported, work done on SimpleText and Memory as well


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

Branch: refs/heads/master
Commit: d852d5b0479b24e84f66a6d24a0136fc7d5562ae
Parents: 3b226e8
Author: Prescott Nasser <pn...@apache.org>
Authored: Sun Sep 28 01:49:21 2014 -0700
Committer: Prescott Nasser <pn...@apache.org>
Committed: Sun Sep 28 01:49:21 2014 -0700

----------------------------------------------------------------------
 src/Lucene.Net.Codecs/HashMapHelperClass.cs     |   26 +
 src/Lucene.Net.Codecs/Lucene.Net.Codecs.csproj  |    3 +
 .../Memory/DirectDocValuesConsumer.cs           |  727 ++-
 .../Memory/DirectDocValuesFormat.cs             |  161 +-
 .../Memory/DirectDocValuesProducer.cs           | 1271 +++--
 .../Memory/DirectPostingsFormat.cs              | 5238 ++++++++++--------
 .../Memory/FSTOrdPostingsFormat.cs              |  151 +-
 .../Memory/FSTOrdPulsing41PostingsFormat.cs     |  174 +-
 .../Memory/FSTOrdTermsReader.cs                 | 2014 ++++---
 .../Memory/FSTOrdTermsWriter.cs                 |  809 +--
 .../Memory/FSTPostingsFormat.cs                 |  151 +-
 .../Memory/FSTPulsing41PostingsFormat.cs        |  176 +-
 src/Lucene.Net.Codecs/Memory/FSTTermOutputs.cs  |  704 ++-
 src/Lucene.Net.Codecs/Memory/FSTTermsReader.cs  | 1772 +++---
 src/Lucene.Net.Codecs/Memory/FSTTermsWriter.cs  |  568 +-
 .../Memory/MemoryDocValuesConsumer.cs           |  956 ++--
 .../Memory/MemoryDocValuesFormat.cs             |  133 +-
 .../Memory/MemoryDocValuesProducer.cs           | 1653 +++---
 .../Memory/MemoryPostingsFormat.cs              | 2139 +++----
 src/Lucene.Net.Codecs/RectangularArrays.cs      |   29 +
 src/Lucene.Net.Codecs/Sep/IntIndexInput.cs      |   82 +-
 src/Lucene.Net.Codecs/Sep/IntIndexOutput.cs     |   80 +-
 src/Lucene.Net.Codecs/Sep/IntStreamFactory.cs   |   40 +-
 src/Lucene.Net.Codecs/Sep/SepPostingsReader.cs  | 1402 ++---
 src/Lucene.Net.Codecs/Sep/SepPostingsWriter.cs  |  728 +--
 src/Lucene.Net.Codecs/Sep/SepSkipListReader.cs  |  389 +-
 src/Lucene.Net.Codecs/Sep/SepSkipListWriter.cs  |  391 +-
 .../SimpleText/SimpleTextDocValuesReader.cs     |   27 +-
 .../SimpleText/SimpleTextDocValuesWriter.cs     |   74 +-
 .../SimpleText/SimpleTextSegmentInfoReader.cs   |    4 +-
 .../SimpleText/SimpleTextTermVectorsWriter.cs   |   50 +-
 src/Lucene.Net.Codecs/StringHelperClass.cs      |    6 +-
 .../Codecs/StoredFieldsReader.cs                |   46 +-
 33 files changed, 12444 insertions(+), 9730 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d852d5b0/src/Lucene.Net.Codecs/HashMapHelperClass.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/HashMapHelperClass.cs b/src/Lucene.Net.Codecs/HashMapHelperClass.cs
new file mode 100644
index 0000000..489b446
--- /dev/null
+++ b/src/Lucene.Net.Codecs/HashMapHelperClass.cs
@@ -0,0 +1,26 @@
+//---------------------------------------------------------------------------------------------------------
+//	Copyright © 2007 - 2014 Tangible Software Solutions Inc.
+//	This class can be used by anyone provided that the copyright notice remains intact.
+//
+//	This class is used to replace calls to some Java HashMap or Hashtable methods.
+//---------------------------------------------------------------------------------------------------------
+using System.Collections.Generic;
+internal static class HashMapHelperClass
+{
+	internal static HashSet<KeyValuePair<TKey, TValue>> SetOfKeyValuePairs<TKey, TValue>(this IDictionary<TKey, TValue> dictionary)
+	{
+		HashSet<KeyValuePair<TKey, TValue>> entries = new HashSet<KeyValuePair<TKey, TValue>>();
+		foreach (KeyValuePair<TKey, TValue> keyValuePair in dictionary)
+		{
+			entries.Add(keyValuePair);
+		}
+		return entries;
+	}
+
+	internal static TValue GetValueOrNull<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
+	{
+		TValue ret;
+		dictionary.TryGetValue(key, out ret);
+		return ret;
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d852d5b0/src/Lucene.Net.Codecs/Lucene.Net.Codecs.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Lucene.Net.Codecs.csproj b/src/Lucene.Net.Codecs/Lucene.Net.Codecs.csproj
index 31340ae..f9500ef 100644
--- a/src/Lucene.Net.Codecs/Lucene.Net.Codecs.csproj
+++ b/src/Lucene.Net.Codecs/Lucene.Net.Codecs.csproj
@@ -33,6 +33,7 @@
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System.Core" />
+    <Reference Include="System.Numerics" />
     <Reference Include="System.Xml.Linq" />
     <Reference Include="System.Data.DataSetExtensions" />
     <Reference Include="Microsoft.CSharp" />
@@ -60,6 +61,7 @@
     <Compile Include="DiskDV\DiskDocValuesFormat.cs" />
     <Compile Include="DiskDV\DiskDocValuesProducer.cs" />
     <Compile Include="DiskDV\DiskNormsFormat.cs" />
+    <Compile Include="HashMapHelperClass.cs" />
     <Compile Include="Intblock\FixedIntBlockIndexInput.cs" />
     <Compile Include="Intblock\FixedIntBlockIndexOutput.cs" />
     <Compile Include="Intblock\IBlockReader.cs" />
@@ -89,6 +91,7 @@
     <Compile Include="Pulsing\PulsingPostingsFormat.cs" />
     <Compile Include="Pulsing\PulsingPostingsReader.cs" />
     <Compile Include="Pulsing\PulsingPostingsWriter.cs" />
+    <Compile Include="RectangularArrays.cs" />
     <Compile Include="Sep\IntIndexInput.cs" />
     <Compile Include="Sep\IntIndexOutput.cs" />
     <Compile Include="Sep\IntStreamFactory.cs" />

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d852d5b0/src/Lucene.Net.Codecs/Memory/DirectDocValuesConsumer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/DirectDocValuesConsumer.cs b/src/Lucene.Net.Codecs/Memory/DirectDocValuesConsumer.cs
index ddddf6f..8362727 100644
--- a/src/Lucene.Net.Codecs/Memory/DirectDocValuesConsumer.cs
+++ b/src/Lucene.Net.Codecs/Memory/DirectDocValuesConsumer.cs
@@ -1,304 +1,423 @@
-package codecs.memory;
-
-/*
- * 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.
- */
-
-import java.io.IOException;
-import java.util.Iterator;
-
-import codecs.CodecUtil;
-import codecs.DocValuesConsumer;
-import index.FieldInfo;
-import index.IndexFileNames;
-import index.SegmentWriteState;
-import store.IndexOutput;
-import util.BytesRef;
-import util.IOUtils;
-
-import static codecs.memory.DirectDocValuesProducer.VERSION_CURRENT;
-import static codecs.memory.DirectDocValuesProducer.BYTES;
-import static codecs.memory.DirectDocValuesProducer.SORTED;
-import static codecs.memory.DirectDocValuesProducer.SORTED_SET;
-import static codecs.memory.DirectDocValuesProducer.NUMBER;
-
-/**
- * Writer for {@link DirectDocValuesFormat}
- */
-
-class DirectDocValuesConsumer extends DocValuesConsumer {
-  IndexOutput data, meta;
-  final int maxDoc;
-
-  DirectDocValuesConsumer(SegmentWriteState state, String dataCodec, String dataExtension, String metaCodec, String metaExtension)  {
-    maxDoc = state.segmentInfo.getDocCount();
-    bool success = false;
-    try {
-      String dataName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, dataExtension);
-      data = state.directory.createOutput(dataName, state.context);
-      CodecUtil.writeHeader(data, dataCodec, VERSION_CURRENT);
-      String metaName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, metaExtension);
-      meta = state.directory.createOutput(metaName, state.context);
-      CodecUtil.writeHeader(meta, metaCodec, VERSION_CURRENT);
-      success = true;
-    } finally {
-      if (!success) {
-        IOUtils.closeWhileHandlingException(this);
-      }
-    }
-  }
-
-  @Override
-  public void addNumericField(FieldInfo field, Iterable<Number> values)  {
-    meta.writeVInt(field.number);
-    meta.writeByte(NUMBER);
-    addNumericFieldValues(field, values);
-  }
-
-  private void addNumericFieldValues(FieldInfo field, Iterable<Number> values)  {
-    meta.writeLong(data.getFilePointer());
-    long minValue = Long.MAX_VALUE;
-    long maxValue = Long.MIN_VALUE;
-    bool missing = false;
-
-    long count = 0;
-    for (Number nv : values) {
-      if (nv != null) {
-        long v = nv.longValue();
-        minValue = Math.min(minValue, v);
-        maxValue = Math.max(maxValue, v);
-      } else {
-        missing = true;
-      }
-      count++;
-      if (count >= DirectDocValuesFormat.MAX_SORTED_SET_ORDS) {
-        throw new IllegalArgumentException("DocValuesField \"" + field.name + "\" is too large, must be <= " + DirectDocValuesFormat.MAX_SORTED_SET_ORDS + " values/total ords");
-      }
-    }
-    meta.writeInt((int) count);
-    
-    if (missing) {
-      long start = data.getFilePointer();
-      writeMissingBitset(values);
-      meta.writeLong(start);
-      meta.writeLong(data.getFilePointer() - start);
-    } else {
-      meta.writeLong(-1L);
-    }
-
-    byte byteWidth;
-    if (minValue >= Byte.MIN_VALUE && maxValue <= Byte.MAX_VALUE) {
-      byteWidth = 1;
-    } else if (minValue >= Short.MIN_VALUE && maxValue <= Short.MAX_VALUE) {
-      byteWidth = 2;
-    } else if (minValue >= Integer.MIN_VALUE && maxValue <= Integer.MAX_VALUE) {
-      byteWidth = 4;
-    } else {
-      byteWidth = 8;
-    }
-    meta.writeByte(byteWidth);
-
-    for (Number nv : values) {
-      long v;
-      if (nv != null) {
-        v = nv.longValue();
-      } else {
-        v = 0;
-      }
-
-      switch(byteWidth) {
-      case 1:
-        data.writeByte((byte) v);
-        break;
-      case 2:
-        data.writeShort((short) v);
-        break;
-      case 4:
-        data.writeInt((int) v);
-        break;
-      case 8:
-        data.writeLong(v);
-        break;
-      }
-    }
-  }
-  
-  @Override
-  public void close()  {
-    bool success = false;
-    try {
-      if (meta != null) {
-        meta.writeVInt(-1); // write EOF marker
-        CodecUtil.writeFooter(meta); // write checksum
-      }
-      if (data != null) {
-        CodecUtil.writeFooter(data);
-      }
-      success = true;
-    } finally {
-      if (success) {
-        IOUtils.close(data, meta);
-      } else {
-        IOUtils.closeWhileHandlingException(data, meta);
-      }
-      data = meta = null;
-    }
-  }
-
-  @Override
-  public void addBinaryField(FieldInfo field, final Iterable<BytesRef> values)  {
-    meta.writeVInt(field.number);
-    meta.writeByte(BYTES);
-    addBinaryFieldValues(field, values);
-  }
-
-  private void addBinaryFieldValues(FieldInfo field, final Iterable<BytesRef> values)  {
-    // write the byte[] data
-    final long startFP = data.getFilePointer();
-    bool missing = false;
-    long totalBytes = 0;
-    int count = 0;
-    for(BytesRef v : values) {
-      if (v != null) {
-        data.writeBytes(v.bytes, v.offset, v.length);
-        totalBytes += v.length;
-        if (totalBytes > DirectDocValuesFormat.MAX_TOTAL_BYTES_LENGTH) {
-          throw new IllegalArgumentException("DocValuesField \"" + field.name + "\" is too large, cannot have more than DirectDocValuesFormat.MAX_TOTAL_BYTES_LENGTH (" + DirectDocValuesFormat.MAX_TOTAL_BYTES_LENGTH + ") bytes");
-        }
-      } else {
-        missing = true;
-      }
-      count++;
-    }
-
-    meta.writeLong(startFP);
-    meta.writeInt((int) totalBytes);
-    meta.writeInt(count);
-    if (missing) {
-      long start = data.getFilePointer();
-      writeMissingBitset(values);
-      meta.writeLong(start);
-      meta.writeLong(data.getFilePointer() - start);
-    } else {
-      meta.writeLong(-1L);
-    }
-    
-    int addr = 0;
-    for (BytesRef v : values) {
-      data.writeInt(addr);
-      if (v != null) {
-        addr += v.length;
-      }
-    }
-    data.writeInt(addr);
-  }
-  
-  // TODO: in some cases representing missing with minValue-1 wouldn't take up additional space and so on,
-  // but this is very simple, and algorithms only check this for values of 0 anyway (doesnt slow down normal decode)
-  void writeMissingBitset(Iterable<?> values)  {
-    long bits = 0;
-    int count = 0;
-    for (Object v : values) {
-      if (count == 64) {
-        data.writeLong(bits);
-        count = 0;
-        bits = 0;
-      }
-      if (v != null) {
-        bits |= 1L << (count & 0x3f);
-      }
-      count++;
-    }
-    if (count > 0) {
-      data.writeLong(bits);
-    }
-  }
-
-  @Override
-  public void addSortedField(FieldInfo field, Iterable<BytesRef> values, Iterable<Number> docToOrd)  {
-    meta.writeVInt(field.number);
-    meta.writeByte(SORTED);
-
-    // write the ordinals as numerics
-    addNumericFieldValues(field, docToOrd);
-    
-    // write the values as binary
-    addBinaryFieldValues(field, values);
-  }
-
-  // note: this might not be the most efficient... but its fairly simple
-  @Override
-  public void addSortedSetField(FieldInfo field, Iterable<BytesRef> values, final Iterable<Number> docToOrdCount, final Iterable<Number> ords)  {
-    meta.writeVInt(field.number);
-    meta.writeByte(SORTED_SET);
-
-    // First write docToOrdCounts, except we "aggregate" the
-    // counts so they turn into addresses, and add a final
-    // value = the total aggregate:
-    addNumericFieldValues(field, new Iterable<Number>() {
-
-        // Just aggregates the count values so they become
-        // "addresses", and adds one more value in the end
-        // (the final sum):
-
-        @Override
-        public Iterator<Number> iterator() {
-          final Iterator<Number> iter = docToOrdCount.iterator();
-
-          return new Iterator<Number>() {
-
-            long sum;
-            bool ended;
-
-            @Override
-            public bool hasNext() {
-              return iter.hasNext() || !ended;
-            }
-
-            @Override
-            public Number next() {
-              long toReturn = sum;
-
-              if (iter.hasNext()) {
-                Number n = iter.next();
-                if (n != null) {
-                  sum += n.longValue();
-                }
-              } else if (!ended) {
-                ended = true;
-              } else {
-                Debug.Assert( false;
-              }
-
-              return toReturn;
-            }
-
-            @Override
-            public void remove() {
-              throw new UnsupportedOperationException();
-            }
-          };
-        }
-      });
-
-    // Write ordinals for all docs, appended into one big
-    // numerics:
-    addNumericFieldValues(field, ords);
-      
-    // write the values as binary
-    addBinaryFieldValues(field, values);
-  }
-}
+using System;
+using System.Diagnostics;
+using System.Collections.Generic;
+
+namespace org.apache.lucene.codecs.memory
+{
+
+	/*
+	 * 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 FieldInfo = org.apache.lucene.index.FieldInfo;
+	using IndexFileNames = org.apache.lucene.index.IndexFileNames;
+	using SegmentWriteState = org.apache.lucene.index.SegmentWriteState;
+	using IndexOutput = org.apache.lucene.store.IndexOutput;
+	using BytesRef = org.apache.lucene.util.BytesRef;
+	using IOUtils = org.apache.lucene.util.IOUtils;
+
+//JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+	import static org.apache.lucene.codecs.memory.DirectDocValuesProducer.VERSION_CURRENT;
+//JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+	import static org.apache.lucene.codecs.memory.DirectDocValuesProducer.BYTES;
+//JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+	import static org.apache.lucene.codecs.memory.DirectDocValuesProducer.SORTED;
+//JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+	import static org.apache.lucene.codecs.memory.DirectDocValuesProducer.SORTED_SET;
+//JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+	import static org.apache.lucene.codecs.memory.DirectDocValuesProducer.NUMBER;
+
+	/// <summary>
+	/// Writer for <seealso cref="DirectDocValuesFormat"/>
+	/// </summary>
+
+	internal class DirectDocValuesConsumer : DocValuesConsumer
+	{
+	  internal IndexOutput data, meta;
+	  internal readonly int maxDoc;
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: DirectDocValuesConsumer(org.apache.lucene.index.SegmentWriteState state, String dataCodec, String dataExtension, String metaCodec, String metaExtension) throws java.io.IOException
+	  internal DirectDocValuesConsumer(SegmentWriteState state, string dataCodec, string dataExtension, string metaCodec, string metaExtension)
+	  {
+		maxDoc = state.segmentInfo.DocCount;
+		bool success = false;
+		try
+		{
+		  string dataName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, dataExtension);
+		  data = state.directory.createOutput(dataName, state.context);
+		  CodecUtil.writeHeader(data, dataCodec, VERSION_CURRENT);
+		  string metaName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, metaExtension);
+		  meta = state.directory.createOutput(metaName, state.context);
+		  CodecUtil.writeHeader(meta, metaCodec, VERSION_CURRENT);
+		  success = true;
+		}
+		finally
+		{
+		  if (!success)
+		  {
+			IOUtils.closeWhileHandlingException(this);
+		  }
+		}
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void addNumericField(org.apache.lucene.index.FieldInfo field, Iterable<Number> values) throws java.io.IOException
+	  public override void addNumericField(FieldInfo field, IEnumerable<Number> values)
+	  {
+		meta.writeVInt(field.number);
+		meta.writeByte(NUMBER);
+		addNumericFieldValues(field, values);
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private void addNumericFieldValues(org.apache.lucene.index.FieldInfo field, Iterable<Number> values) throws java.io.IOException
+	  private void addNumericFieldValues(FieldInfo field, IEnumerable<Number> values)
+	  {
+		meta.writeLong(data.FilePointer);
+		long minValue = long.MaxValue;
+		long maxValue = long.MinValue;
+		bool missing = false;
+
+		long count = 0;
+		foreach (Number nv in values)
+		{
+		  if (nv != null)
+		  {
+			long v = (long)nv;
+			minValue = Math.Min(minValue, v);
+			maxValue = Math.Max(maxValue, v);
+		  }
+		  else
+		  {
+			missing = true;
+		  }
+		  count++;
+		  if (count >= DirectDocValuesFormat.MAX_SORTED_SET_ORDS)
+		  {
+			throw new System.ArgumentException("DocValuesField \"" + field.name + "\" is too large, must be <= " + DirectDocValuesFormat.MAX_SORTED_SET_ORDS + " values/total ords");
+		  }
+		}
+		meta.writeInt((int) count);
+
+		if (missing)
+		{
+		  long start = data.FilePointer;
+		  writeMissingBitset(values);
+		  meta.writeLong(start);
+		  meta.writeLong(data.FilePointer - start);
+		}
+		else
+		{
+		  meta.writeLong(-1L);
+		}
+
+		sbyte byteWidth;
+		if (minValue >= sbyte.MinValue && maxValue <= sbyte.MaxValue)
+		{
+		  byteWidth = 1;
+		}
+		else if (minValue >= short.MinValue && maxValue <= short.MaxValue)
+		{
+		  byteWidth = 2;
+		}
+		else if (minValue >= int.MinValue && maxValue <= int.MaxValue)
+		{
+		  byteWidth = 4;
+		}
+		else
+		{
+		  byteWidth = 8;
+		}
+		meta.writeByte(byteWidth);
+
+		foreach (Number nv in values)
+		{
+		  long v;
+		  if (nv != null)
+		  {
+			v = (long)nv;
+		  }
+		  else
+		  {
+			v = 0;
+		  }
+
+		  switch (byteWidth)
+		  {
+		  case 1:
+			data.writeByte((sbyte) v);
+			break;
+		  case 2:
+			data.writeShort((short) v);
+			break;
+		  case 4:
+			data.writeInt((int) v);
+			break;
+		  case 8:
+			data.writeLong(v);
+			break;
+		  }
+		}
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void close() throws java.io.IOException
+	  public override void close()
+	  {
+		bool success = false;
+		try
+		{
+		  if (meta != null)
+		  {
+			meta.writeVInt(-1); // write EOF marker
+			CodecUtil.writeFooter(meta); // write checksum
+		  }
+		  if (data != null)
+		  {
+			CodecUtil.writeFooter(data);
+		  }
+		  success = true;
+		}
+		finally
+		{
+		  if (success)
+		  {
+			IOUtils.close(data, meta);
+		  }
+		  else
+		  {
+			IOUtils.closeWhileHandlingException(data, meta);
+		  }
+		  data = meta = null;
+		}
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void addBinaryField(org.apache.lucene.index.FieldInfo field, final Iterable<org.apache.lucene.util.BytesRef> values) throws java.io.IOException
+//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
+	  public override void addBinaryField(FieldInfo field, IEnumerable<BytesRef> values)
+	  {
+		meta.writeVInt(field.number);
+		meta.writeByte(BYTES);
+		addBinaryFieldValues(field, values);
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private void addBinaryFieldValues(org.apache.lucene.index.FieldInfo field, final Iterable<org.apache.lucene.util.BytesRef> values) throws java.io.IOException
+//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
+	  private void addBinaryFieldValues(FieldInfo field, IEnumerable<BytesRef> values)
+	  {
+		// write the byte[] data
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final long startFP = data.getFilePointer();
+		long startFP = data.FilePointer;
+		bool missing = false;
+		long totalBytes = 0;
+		int count = 0;
+		foreach (BytesRef v in values)
+		{
+		  if (v != null)
+		  {
+			data.writeBytes(v.bytes, v.offset, v.length);
+			totalBytes += v.length;
+			if (totalBytes > DirectDocValuesFormat.MAX_TOTAL_BYTES_LENGTH)
+			{
+			  throw new System.ArgumentException("DocValuesField \"" + field.name + "\" is too large, cannot have more than DirectDocValuesFormat.MAX_TOTAL_BYTES_LENGTH (" + DirectDocValuesFormat.MAX_TOTAL_BYTES_LENGTH + ") bytes");
+			}
+		  }
+		  else
+		  {
+			missing = true;
+		  }
+		  count++;
+		}
+
+		meta.writeLong(startFP);
+		meta.writeInt((int) totalBytes);
+		meta.writeInt(count);
+		if (missing)
+		{
+		  long start = data.FilePointer;
+		  writeMissingBitset(values);
+		  meta.writeLong(start);
+		  meta.writeLong(data.FilePointer - start);
+		}
+		else
+		{
+		  meta.writeLong(-1L);
+		}
+
+		int addr = 0;
+		foreach (BytesRef v in values)
+		{
+		  data.writeInt(addr);
+		  if (v != null)
+		  {
+			addr += v.length;
+		  }
+		}
+		data.writeInt(addr);
+	  }
+
+	  // TODO: in some cases representing missing with minValue-1 wouldn't take up additional space and so on,
+	  // but this is very simple, and algorithms only check this for values of 0 anyway (doesnt slow down normal decode)
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: void writeMissingBitset(Iterable<?> values) throws java.io.IOException
+	  internal virtual void writeMissingBitset<T1>(IEnumerable<T1> values)
+	  {
+		long bits = 0;
+		int count = 0;
+		foreach (object v in values)
+		{
+		  if (count == 64)
+		  {
+			data.writeLong(bits);
+			count = 0;
+			bits = 0;
+		  }
+		  if (v != null)
+		  {
+			bits |= 1L << (count & 0x3f);
+		  }
+		  count++;
+		}
+		if (count > 0)
+		{
+		  data.writeLong(bits);
+		}
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void addSortedField(org.apache.lucene.index.FieldInfo field, Iterable<org.apache.lucene.util.BytesRef> values, Iterable<Number> docToOrd) throws java.io.IOException
+	  public override void addSortedField(FieldInfo field, IEnumerable<BytesRef> values, IEnumerable<Number> docToOrd)
+	  {
+		meta.writeVInt(field.number);
+		meta.writeByte(SORTED);
+
+		// write the ordinals as numerics
+		addNumericFieldValues(field, docToOrd);
+
+		// write the values as binary
+		addBinaryFieldValues(field, values);
+	  }
+
+	  // note: this might not be the most efficient... but its fairly simple
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void addSortedSetField(org.apache.lucene.index.FieldInfo field, Iterable<org.apache.lucene.util.BytesRef> values, final Iterable<Number> docToOrdCount, final Iterable<Number> ords) throws java.io.IOException
+//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
+	  public override void addSortedSetField(FieldInfo field, IEnumerable<BytesRef> values, IEnumerable<Number> docToOrdCount, IEnumerable<Number> ords)
+	  {
+		meta.writeVInt(field.number);
+		meta.writeByte(SORTED_SET);
+
+		// First write docToOrdCounts, except we "aggregate" the
+		// counts so they turn into addresses, and add a final
+		// value = the total aggregate:
+		addNumericFieldValues(field, new IterableAnonymousInnerClassHelper(this, docToOrdCount));
+
+		// Write ordinals for all docs, appended into one big
+		// numerics:
+		addNumericFieldValues(field, ords);
+
+		// write the values as binary
+		addBinaryFieldValues(field, values);
+	  }
+
+	  private class IterableAnonymousInnerClassHelper : IEnumerable<Number>
+	  {
+		  private readonly DirectDocValuesConsumer outerInstance;
+
+		  private IEnumerable<Number> docToOrdCount;
+
+		  public IterableAnonymousInnerClassHelper(DirectDocValuesConsumer outerInstance, IEnumerable<Number> docToOrdCount)
+		  {
+			  this.outerInstance = outerInstance;
+			  this.docToOrdCount = docToOrdCount;
+		  }
+
+
+			  // Just aggregates the count values so they become
+			  // "addresses", and adds one more value in the end
+			  // (the final sum):
+
+		  public virtual IEnumerator<Number> GetEnumerator()
+		  {
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final java.util.Iterator<Number> iter = docToOrdCount.iterator();
+			IEnumerator<Number> iter = docToOrdCount.GetEnumerator();
+
+			return new IteratorAnonymousInnerClassHelper(this, iter);
+		  }
+
+		  private class IteratorAnonymousInnerClassHelper : IEnumerator<Number>
+		  {
+			  private readonly IterableAnonymousInnerClassHelper outerInstance;
+
+			  private IEnumerator<Number> iter;
+
+			  public IteratorAnonymousInnerClassHelper(IterableAnonymousInnerClassHelper outerInstance, IEnumerator<Number> iter)
+			  {
+				  this.outerInstance = outerInstance;
+				  this.iter = iter;
+			  }
+
+
+			  internal long sum;
+			  internal bool ended;
+
+			  public virtual bool hasNext()
+			  {
+//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
+				return iter.hasNext() || !ended;
+			  }
+
+			  public virtual Number next()
+			  {
+				long toReturn = sum;
+
+//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
+				if (iter.hasNext())
+				{
+//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
+				  Number n = iter.next();
+				  if (n != null)
+				  {
+					sum += (long)n;
+				  }
+				}
+				else if (!ended)
+				{
+				  ended = true;
+				}
+				else
+				{
+				  Debug.Assert(false);
+				}
+
+				return toReturn;
+			  }
+
+			  public virtual void remove()
+			  {
+				throw new System.NotSupportedException();
+			  }
+		  }
+	  }
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d852d5b0/src/Lucene.Net.Codecs/Memory/DirectDocValuesFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/DirectDocValuesFormat.cs b/src/Lucene.Net.Codecs/Memory/DirectDocValuesFormat.cs
index fb98c99..715d190 100644
--- a/src/Lucene.Net.Codecs/Memory/DirectDocValuesFormat.cs
+++ b/src/Lucene.Net.Codecs/Memory/DirectDocValuesFormat.cs
@@ -1,83 +1,94 @@
-package codecs.memory;
+namespace org.apache.lucene.codecs.memory
+{
 
-/*
- * 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.
- */
+	/*
+	 * 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.
+	 */
 
-import java.io.IOException;
+	using SortedSetDocValuesField = org.apache.lucene.document.SortedSetDocValuesField; // javadocs
+	using SegmentReadState = org.apache.lucene.index.SegmentReadState;
+	using SegmentWriteState = org.apache.lucene.index.SegmentWriteState;
+	using ArrayUtil = org.apache.lucene.util.ArrayUtil;
 
-import codecs.DocValuesConsumer;
-import codecs.DocValuesFormat;
-import codecs.DocValuesProducer;
-import document.SortedSetDocValuesField; // javadocs
-import index.SegmentReadState;
-import index.SegmentWriteState;
-import util.ArrayUtil;
+	/// <summary>
+	/// In-memory docvalues format that does no (or very little)
+	///  compression.  Indexed values are stored on disk, but
+	///  then at search time all values are loaded into memory as
+	///  simple java arrays.  For numeric values, it uses
+	///  byte[], short[], int[], long[] as necessary to fit the
+	///  range of the values.  For binary values, there is an int
+	///  (4 bytes) overhead per value.
+	/// 
+	///  <para>Limitations:
+	///  <ul>
+	///    <li>For binary and sorted fields the total space
+	///        required for all binary values cannot exceed about
+	///        2.1 GB (see #MAX_TOTAL_BYTES_LENGTH).</li>
+	/// 
+	///    <li>For sorted set fields, the sum of the size of each
+	///        document's set of values cannot exceed about 2.1 B
+	///        values (see #MAX_SORTED_SET_ORDS).  For example,
+	///        if every document has 10 values (10 instances of
+	///        <seealso cref="SortedSetDocValuesField"/>) added, then no
+	///        more than ~210 M documents can be added to one
+	///        segment. </li>
+	///  </ul> 
+	/// </para>
+	/// </summary>
 
-/** In-memory docvalues format that does no (or very little)
- *  compression.  Indexed values are stored on disk, but
- *  then at search time all values are loaded into memory as
- *  simple java arrays.  For numeric values, it uses
- *  byte[], short[], int[], long[] as necessary to fit the
- *  range of the values.  For binary values, there is an int
- *  (4 bytes) overhead per value.
- *
- *  <p>Limitations:
- *  <ul>
- *    <li>For binary and sorted fields the total space
- *        required for all binary values cannot exceed about
- *        2.1 GB (see #MAX_TOTAL_BYTES_LENGTH).</li>
- *
- *    <li>For sorted set fields, the sum of the size of each
- *        document's set of values cannot exceed about 2.1 B
- *        values (see #MAX_SORTED_SET_ORDS).  For example,
- *        if every document has 10 values (10 instances of
- *        {@link SortedSetDocValuesField}) added, then no
- *        more than ~210 M documents can be added to one
- *        segment. </li>
- *  </ul> */
+	public class DirectDocValuesFormat : DocValuesFormat
+	{
 
-public class DirectDocValuesFormat extends DocValuesFormat {
+	  /// <summary>
+	  /// The sum of all byte lengths for binary field, or for
+	  ///  the unique values in sorted or sorted set fields, cannot
+	  ///  exceed this. 
+	  /// </summary>
+	  public static readonly int MAX_TOTAL_BYTES_LENGTH = ArrayUtil.MAX_ARRAY_LENGTH;
 
-  /** The sum of all byte lengths for binary field, or for
-   *  the unique values in sorted or sorted set fields, cannot
-   *  exceed this. */
-  public final static int MAX_TOTAL_BYTES_LENGTH = ArrayUtil.MAX_ARRAY_LENGTH;
+	  /// <summary>
+	  /// The sum of the number of values across all documents
+	  ///  in a sorted set field cannot exceed this. 
+	  /// </summary>
+	  public static readonly int MAX_SORTED_SET_ORDS = ArrayUtil.MAX_ARRAY_LENGTH;
 
-  /** The sum of the number of values across all documents
-   *  in a sorted set field cannot exceed this. */
-  public final static int MAX_SORTED_SET_ORDS = ArrayUtil.MAX_ARRAY_LENGTH;
+	  /// <summary>
+	  /// Sole constructor. </summary>
+	  public DirectDocValuesFormat() : base("Direct")
+	  {
+	  }
 
-  /** Sole constructor. */
-  public DirectDocValuesFormat() {
-    super("Direct");
-  }
-  
-  @Override
-  public DocValuesConsumer fieldsConsumer(SegmentWriteState state)  {
-    return new DirectDocValuesConsumer(state, DATA_CODEC, DATA_EXTENSION, METADATA_CODEC, METADATA_EXTENSION);
-  }
-  
-  @Override
-  public DocValuesProducer fieldsProducer(SegmentReadState state)  {
-    return new DirectDocValuesProducer(state, DATA_CODEC, DATA_EXTENSION, METADATA_CODEC, METADATA_EXTENSION);
-  }
-  
-  static final String DATA_CODEC = "DirectDocValuesData";
-  static final String DATA_EXTENSION = "dvdd";
-  static final String METADATA_CODEC = "DirectDocValuesMetadata";
-  static final String METADATA_EXTENSION = "dvdm";
-}
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public org.apache.lucene.codecs.DocValuesConsumer fieldsConsumer(org.apache.lucene.index.SegmentWriteState state) throws java.io.IOException
+	  public override DocValuesConsumer fieldsConsumer(SegmentWriteState state)
+	  {
+		return new DirectDocValuesConsumer(state, DATA_CODEC, DATA_EXTENSION, METADATA_CODEC, METADATA_EXTENSION);
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public org.apache.lucene.codecs.DocValuesProducer fieldsProducer(org.apache.lucene.index.SegmentReadState state) throws java.io.IOException
+	  public override DocValuesProducer fieldsProducer(SegmentReadState state)
+	  {
+		return new DirectDocValuesProducer(state, DATA_CODEC, DATA_EXTENSION, METADATA_CODEC, METADATA_EXTENSION);
+	  }
+
+	  internal const string DATA_CODEC = "DirectDocValuesData";
+	  internal const string DATA_EXTENSION = "dvdd";
+	  internal const string METADATA_CODEC = "DirectDocValuesMetadata";
+	  internal const string METADATA_EXTENSION = "dvdm";
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d852d5b0/src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs b/src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs
index 6d63d5b..ee88b68 100644
--- a/src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs
+++ b/src/Lucene.Net.Codecs/Memory/DirectDocValuesProducer.cs
@@ -1,511 +1,760 @@
-package codecs.memory;
-
-/*
- * 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.
- */
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicLong;
-
-import codecs.CodecUtil;
-import codecs.DocValuesProducer;
-import index.BinaryDocValues;
-import index.CorruptIndexException;
-import index.DocValues;
-import index.FieldInfo;
-import index.IndexFileNames;
-import index.NumericDocValues;
-import index.RandomAccessOrds;
-import index.SegmentReadState;
-import index.SortedDocValues;
-import index.SortedSetDocValues;
-import store.ChecksumIndexInput;
-import store.IndexInput;
-import util.Bits;
-import util.BytesRef;
-import util.FixedBitSet;
-import util.IOUtils;
-import util.RamUsageEstimator;
-
-/**
- * Reader for {@link DirectDocValuesFormat}
- */
-
-class DirectDocValuesProducer extends DocValuesProducer {
-  // metadata maps (just file pointers and minimal stuff)
-  private final Map<Integer,NumericEntry> numerics = new HashMap<>();
-  private final Map<Integer,BinaryEntry> binaries = new HashMap<>();
-  private final Map<Integer,SortedEntry> sorteds = new HashMap<>();
-  private final Map<Integer,SortedSetEntry> sortedSets = new HashMap<>();
-  private final IndexInput data;
-  
-  // ram instances we have already loaded
-  private final Map<Integer,NumericDocValues> numericInstances = 
-      new HashMap<>();
-  private final Map<Integer,BinaryDocValues> binaryInstances =
-      new HashMap<>();
-  private final Map<Integer,SortedDocValues> sortedInstances =
-      new HashMap<>();
-  private final Map<Integer,SortedSetRawValues> sortedSetInstances =
-      new HashMap<>();
-  private final Map<Integer,Bits> docsWithFieldInstances = new HashMap<>();
-  
-  private final int maxDoc;
-  private final AtomicLong ramBytesUsed;
-  private final int version;
-  
-  static final byte NUMBER = 0;
-  static final byte BYTES = 1;
-  static final byte SORTED = 2;
-  static final byte SORTED_SET = 3;
-
-  static final int VERSION_START = 0;
-  static final int VERSION_CHECKSUM = 1;
-  static final int VERSION_CURRENT = VERSION_CHECKSUM;
-    
-  DirectDocValuesProducer(SegmentReadState state, String dataCodec, String dataExtension, String metaCodec, String metaExtension)  {
-    maxDoc = state.segmentInfo.getDocCount();
-    String metaName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, metaExtension);
-    // read in the entries from the metadata file.
-    ChecksumIndexInput in = state.directory.openChecksumInput(metaName, state.context);
-    ramBytesUsed = new AtomicLong(RamUsageEstimator.shallowSizeOfInstance(getClass()));
-    bool success = false;
-    try {
-      version = CodecUtil.checkHeader(in, metaCodec, 
-                                      VERSION_START,
-                                      VERSION_CURRENT);
-      readFields(in);
-
-      if (version >= VERSION_CHECKSUM) {
-        CodecUtil.checkFooter(in);
-      } else {
-        CodecUtil.checkEOF(in);
-      }
-      success = true;
-    } finally {
-      if (success) {
-        IOUtils.close(in);
-      } else {
-        IOUtils.closeWhileHandlingException(in);
-      }
-    }
-
-    success = false;
-    try {
-      String dataName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, dataExtension);
-      data = state.directory.openInput(dataName, state.context);
-      final int version2 = CodecUtil.checkHeader(data, dataCodec, 
-                                                 VERSION_START,
-                                                 VERSION_CURRENT);
-      if (version != version2) {
-        throw new CorruptIndexException("Format versions mismatch");
-      }
-
-      success = true;
-    } finally {
-      if (!success) {
-        IOUtils.closeWhileHandlingException(this.data);
-      }
-    }
-  }
-
-  private NumericEntry readNumericEntry(IndexInput meta)  {
-    NumericEntry entry = new NumericEntry();
-    entry.offset = meta.readLong();
-    entry.count = meta.readInt();
-    entry.missingOffset = meta.readLong();
-    if (entry.missingOffset != -1) {
-      entry.missingBytes = meta.readLong();
-    } else {
-      entry.missingBytes = 0;
-    }
-    entry.byteWidth = meta.readByte();
-
-    return entry;
-  }
-
-  private BinaryEntry readBinaryEntry(IndexInput meta)  {
-    BinaryEntry entry = new BinaryEntry();
-    entry.offset = meta.readLong();
-    entry.numBytes = meta.readInt();
-    entry.count = meta.readInt();
-    entry.missingOffset = meta.readLong();
-    if (entry.missingOffset != -1) {
-      entry.missingBytes = meta.readLong();
-    } else {
-      entry.missingBytes = 0;
-    }
-
-    return entry;
-  }
-
-  private SortedEntry readSortedEntry(IndexInput meta)  {
-    SortedEntry entry = new SortedEntry();
-    entry.docToOrd = readNumericEntry(meta);
-    entry.values = readBinaryEntry(meta);
-    return entry;
-  }
-
-  private SortedSetEntry readSortedSetEntry(IndexInput meta)  {
-    SortedSetEntry entry = new SortedSetEntry();
-    entry.docToOrdAddress = readNumericEntry(meta);
-    entry.ords = readNumericEntry(meta);
-    entry.values = readBinaryEntry(meta);
-    return entry;
-  }
-
-  private void readFields(IndexInput meta)  {
-    int fieldNumber = meta.readVInt();
-    while (fieldNumber != -1) {
-      int fieldType = meta.readByte();
-      if (fieldType == NUMBER) {
-        numerics.put(fieldNumber, readNumericEntry(meta));
-      } else if (fieldType == BYTES) {
-        binaries.put(fieldNumber, readBinaryEntry(meta));
-      } else if (fieldType == SORTED) {
-        sorteds.put(fieldNumber, readSortedEntry(meta));
-      } else if (fieldType == SORTED_SET) {
-        sortedSets.put(fieldNumber, readSortedSetEntry(meta));
-      } else {
-        throw new CorruptIndexException("invalid entry type: " + fieldType + ", input=" + meta);
-      }
-      fieldNumber = meta.readVInt();
-    }
-  }
-
-  @Override
-  public long ramBytesUsed() {
-    return ramBytesUsed.get();
-  }
-  
-  @Override
-  public void checkIntegrity()  {
-    if (version >= VERSION_CHECKSUM) {
-      CodecUtil.checksumEntireFile(data);
-    }
-  }
-
-  @Override
-  public synchronized NumericDocValues getNumeric(FieldInfo field)  {
-    NumericDocValues instance = numericInstances.get(field.number);
-    if (instance == null) {
-      // Lazy load
-      instance = loadNumeric(numerics.get(field.number));
-      numericInstances.put(field.number, instance);
-    }
-    return instance;
-  }
-  
-  private NumericDocValues loadNumeric(NumericEntry entry)  {
-    data.seek(entry.offset + entry.missingBytes);
-    switch (entry.byteWidth) {
-    case 1:
-      {
-        final byte[] values = new byte[entry.count];
-        data.readBytes(values, 0, entry.count);
-        ramBytesUsed.addAndGet(RamUsageEstimator.sizeOf(values));
-        return new NumericDocValues() {
-          @Override
-          public long get(int idx) {
-            return values[idx];
-          }
-        };
-      }
-
-    case 2:
-      {
-        final short[] values = new short[entry.count];
-        for(int i=0;i<entry.count;i++) {
-          values[i] = data.readShort();
-        }
-        ramBytesUsed.addAndGet(RamUsageEstimator.sizeOf(values));
-        return new NumericDocValues() {
-          @Override
-          public long get(int idx) {
-            return values[idx];
-          }
-        };
-      }
-
-    case 4:
-      {
-        final int[] values = new int[entry.count];
-        for(int i=0;i<entry.count;i++) {
-          values[i] = data.readInt();
-        }
-        ramBytesUsed.addAndGet(RamUsageEstimator.sizeOf(values));
-        return new NumericDocValues() {
-          @Override
-          public long get(int idx) {
-            return values[idx];
-          }
-        };
-      }
-
-    case 8:
-      {
-        final long[] values = new long[entry.count];
-        for(int i=0;i<entry.count;i++) {
-          values[i] = data.readLong();
-        }
-        ramBytesUsed.addAndGet(RamUsageEstimator.sizeOf(values));
-        return new NumericDocValues() {
-          @Override
-          public long get(int idx) {
-            return values[idx];
-          }
-        };
-      }
-    
-    default:
-      throw new Debug.Assert(ionError();
-    }
-  }
-
-  @Override
-  public synchronized BinaryDocValues getBinary(FieldInfo field)  {
-    BinaryDocValues instance = binaryInstances.get(field.number);
-    if (instance == null) {
-      // Lazy load
-      instance = loadBinary(binaries.get(field.number));
-      binaryInstances.put(field.number, instance);
-    }
-    return instance;
-  }
-  
-  private BinaryDocValues loadBinary(BinaryEntry entry)  {
-    data.seek(entry.offset);
-    final byte[] bytes = new byte[entry.numBytes];
-    data.readBytes(bytes, 0, entry.numBytes);
-    data.seek(entry.offset + entry.numBytes + entry.missingBytes);
-
-    final int[] address = new int[entry.count+1];
-    for(int i=0;i<entry.count;i++) {
-      address[i] = data.readInt();
-    }
-    address[entry.count] = data.readInt();
-
-    ramBytesUsed.addAndGet(RamUsageEstimator.sizeOf(bytes) + RamUsageEstimator.sizeOf(address));
-
-    return new BinaryDocValues() {
-      @Override
-      public void get(int docID, BytesRef result) {
-        result.bytes = bytes;
-        result.offset = address[docID];
-        result.length = address[docID+1] - result.offset;
-      };
-    };
-  }
-  
-  @Override
-  public synchronized SortedDocValues getSorted(FieldInfo field)  {
-    SortedDocValues instance = sortedInstances.get(field.number);
-    if (instance == null) {
-      // Lazy load
-      instance = loadSorted(field);
-      sortedInstances.put(field.number, instance);
-    }
-    return instance;
-  }
-
-  private SortedDocValues loadSorted(FieldInfo field)  {
-    final SortedEntry entry = sorteds.get(field.number);
-    final NumericDocValues docToOrd = loadNumeric(entry.docToOrd);
-    final BinaryDocValues values = loadBinary(entry.values);
-
-    return new SortedDocValues() {
-
-      @Override
-      public int getOrd(int docID) {
-        return (int) docToOrd.get(docID);
-      }
-
-      @Override
-      public void lookupOrd(int ord, BytesRef result) {
-        values.get(ord, result);
-      }
-
-      @Override
-      public int getValueCount() {
-        return entry.values.count;
-      }
-
-      // Leave lookupTerm to super's binary search
-
-      // Leave termsEnum to super
-    };
-  }
-
-  @Override
-  public synchronized SortedSetDocValues getSortedSet(FieldInfo field)  {
-    SortedSetRawValues instance = sortedSetInstances.get(field.number);
-    final SortedSetEntry entry = sortedSets.get(field.number);
-    if (instance == null) {
-      // Lazy load
-      instance = loadSortedSet(entry);
-      sortedSetInstances.put(field.number, instance);
-    }
-
-    final NumericDocValues docToOrdAddress = instance.docToOrdAddress;
-    final NumericDocValues ords = instance.ords;
-    final BinaryDocValues values = instance.values;
-
-    // Must make a new instance since the iterator has state:
-    return new RandomAccessOrds() {
-      int ordStart;
-      int ordUpto;
-      int ordLimit;
-
-      @Override
-      public long nextOrd() {
-        if (ordUpto == ordLimit) {
-          return NO_MORE_ORDS;
-        } else {
-          return ords.get(ordUpto++);
-        }
-      }
-      
-      @Override
-      public void setDocument(int docID) {
-        ordStart = ordUpto = (int) docToOrdAddress.get(docID);
-        ordLimit = (int) docToOrdAddress.get(docID+1);
-      }
-
-      @Override
-      public void lookupOrd(long ord, BytesRef result) {
-        values.get((int) ord, result);
-      }
-
-      @Override
-      public long getValueCount() {
-        return entry.values.count;
-      }
-
-      @Override
-      public long ordAt(int index) {
-        return ords.get(ordStart + index);
-      }
-
-      @Override
-      public int cardinality() {
-        return ordLimit - ordStart;
-      }
-
-      // Leave lookupTerm to super's binary search
-
-      // Leave termsEnum to super
-    };
-  }
-  
-  private SortedSetRawValues loadSortedSet(SortedSetEntry entry)  {
-    SortedSetRawValues instance = new SortedSetRawValues();
-    instance.docToOrdAddress = loadNumeric(entry.docToOrdAddress);
-    instance.ords = loadNumeric(entry.ords);
-    instance.values = loadBinary(entry.values);
-    return instance;
-  }
-
-  private Bits getMissingBits(int fieldNumber, final long offset, final long length)  {
-    if (offset == -1) {
-      return new Bits.MatchAllBits(maxDoc);
-    } else {
-      Bits instance;
-      synchronized(this) {
-        instance = docsWithFieldInstances.get(fieldNumber);
-        if (instance == null) {
-          IndexInput data = this.data.clone();
-          data.seek(offset);
-          Debug.Assert( length % 8 == 0;
-          long bits[] = new long[(int) length >> 3];
-          for (int i = 0; i < bits.length; i++) {
-            bits[i] = data.readLong();
-          }
-          instance = new FixedBitSet(bits, maxDoc);
-          docsWithFieldInstances.put(fieldNumber, instance);
-        }
-      }
-      return instance;
-    }
-  }
-  
-  @Override
-  public Bits getDocsWithField(FieldInfo field)  {
-    switch(field.getDocValuesType()) {
-      case SORTED_SET:
-        return DocValues.docsWithValue(getSortedSet(field), maxDoc);
-      case SORTED:
-        return DocValues.docsWithValue(getSorted(field), maxDoc);
-      case BINARY:
-        BinaryEntry be = binaries.get(field.number);
-        return getMissingBits(field.number, be.missingOffset, be.missingBytes);
-      case NUMERIC:
-        NumericEntry ne = numerics.get(field.number);
-        return getMissingBits(field.number, ne.missingOffset, ne.missingBytes);
-      default: 
-        throw new Debug.Assert(ionError();
-    }
-  }
-
-  @Override
-  public void close()  {
-    data.close();
-  }
-  
-  static class SortedSetRawValues {
-    NumericDocValues docToOrdAddress;
-    NumericDocValues ords;
-    BinaryDocValues values;
-  }
-
-  static class NumericEntry {
-    long offset;
-    int count;
-    long missingOffset;
-    long missingBytes;
-    byte byteWidth;
-    int packedIntsVersion;
-  }
-
-  static class BinaryEntry {
-    long offset;
-    long missingOffset;
-    long missingBytes;
-    int count;
-    int numBytes;
-    int minLength;
-    int maxLength;
-    int packedIntsVersion;
-    int blockSize;
-  }
-  
-  static class SortedEntry {
-    NumericEntry docToOrd;
-    BinaryEntry values;
-  }
-
-  static class SortedSetEntry {
-    NumericEntry docToOrdAddress;
-    NumericEntry ords;
-    BinaryEntry values;
-  }
-  
-  static class FSTEntry {
-    long offset;
-    long numOrds;
-  }
-}
+using System.Diagnostics;
+using System.Collections.Generic;
+
+namespace org.apache.lucene.codecs.memory
+{
+
+	/*
+	 * 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 BinaryDocValues = org.apache.lucene.index.BinaryDocValues;
+	using CorruptIndexException = org.apache.lucene.index.CorruptIndexException;
+	using DocValues = org.apache.lucene.index.DocValues;
+	using FieldInfo = org.apache.lucene.index.FieldInfo;
+	using IndexFileNames = org.apache.lucene.index.IndexFileNames;
+	using NumericDocValues = org.apache.lucene.index.NumericDocValues;
+	using RandomAccessOrds = org.apache.lucene.index.RandomAccessOrds;
+	using SegmentReadState = org.apache.lucene.index.SegmentReadState;
+	using SortedDocValues = org.apache.lucene.index.SortedDocValues;
+	using SortedSetDocValues = org.apache.lucene.index.SortedSetDocValues;
+	using ChecksumIndexInput = org.apache.lucene.store.ChecksumIndexInput;
+	using IndexInput = org.apache.lucene.store.IndexInput;
+	using Bits = org.apache.lucene.util.Bits;
+	using BytesRef = org.apache.lucene.util.BytesRef;
+	using FixedBitSet = org.apache.lucene.util.FixedBitSet;
+	using IOUtils = org.apache.lucene.util.IOUtils;
+	using RamUsageEstimator = org.apache.lucene.util.RamUsageEstimator;
+
+	/// <summary>
+	/// Reader for <seealso cref="DirectDocValuesFormat"/>
+	/// </summary>
+
+	internal class DirectDocValuesProducer : DocValuesProducer
+	{
+	  // metadata maps (just file pointers and minimal stuff)
+	  private readonly IDictionary<int?, NumericEntry> numerics = new Dictionary<int?, NumericEntry>();
+	  private readonly IDictionary<int?, BinaryEntry> binaries = new Dictionary<int?, BinaryEntry>();
+	  private readonly IDictionary<int?, SortedEntry> sorteds = new Dictionary<int?, SortedEntry>();
+	  private readonly IDictionary<int?, SortedSetEntry> sortedSets = new Dictionary<int?, SortedSetEntry>();
+	  private readonly IndexInput data;
+
+	  // ram instances we have already loaded
+	  private readonly IDictionary<int?, NumericDocValues> numericInstances = new Dictionary<int?, NumericDocValues>();
+	  private readonly IDictionary<int?, BinaryDocValues> binaryInstances = new Dictionary<int?, BinaryDocValues>();
+	  private readonly IDictionary<int?, SortedDocValues> sortedInstances = new Dictionary<int?, SortedDocValues>();
+	  private readonly IDictionary<int?, SortedSetRawValues> sortedSetInstances = new Dictionary<int?, SortedSetRawValues>();
+	  private readonly IDictionary<int?, Bits> docsWithFieldInstances = new Dictionary<int?, Bits>();
+
+	  private readonly int maxDoc;
+	  private readonly AtomicLong ramBytesUsed_Renamed;
+	  private readonly int version;
+
+	  internal const sbyte NUMBER = 0;
+	  internal const sbyte BYTES = 1;
+	  internal const sbyte SORTED = 2;
+	  internal const sbyte SORTED_SET = 3;
+
+	  internal const int VERSION_START = 0;
+	  internal const int VERSION_CHECKSUM = 1;
+	  internal const int VERSION_CURRENT = VERSION_CHECKSUM;
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: DirectDocValuesProducer(org.apache.lucene.index.SegmentReadState state, String dataCodec, String dataExtension, String metaCodec, String metaExtension) throws java.io.IOException
+	  internal DirectDocValuesProducer(SegmentReadState state, string dataCodec, string dataExtension, string metaCodec, string metaExtension)
+	  {
+		maxDoc = state.segmentInfo.DocCount;
+		string metaName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, metaExtension);
+		// read in the entries from the metadata file.
+		ChecksumIndexInput @in = state.directory.openChecksumInput(metaName, state.context);
+		ramBytesUsed_Renamed = new AtomicLong(RamUsageEstimator.shallowSizeOfInstance(this.GetType()));
+		bool success = false;
+		try
+		{
+		  version = CodecUtil.checkHeader(@in, metaCodec, VERSION_START, VERSION_CURRENT);
+		  readFields(@in);
+
+		  if (version >= VERSION_CHECKSUM)
+		  {
+			CodecUtil.checkFooter(@in);
+		  }
+		  else
+		  {
+			CodecUtil.checkEOF(@in);
+		  }
+		  success = true;
+		}
+		finally
+		{
+		  if (success)
+		  {
+			IOUtils.close(@in);
+		  }
+		  else
+		  {
+			IOUtils.closeWhileHandlingException(@in);
+		  }
+		}
+
+		success = false;
+		try
+		{
+		  string dataName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, dataExtension);
+		  data = state.directory.openInput(dataName, state.context);
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final int version2 = org.apache.lucene.codecs.CodecUtil.checkHeader(data, dataCodec, VERSION_START, VERSION_CURRENT);
+		  int version2 = CodecUtil.checkHeader(data, dataCodec, VERSION_START, VERSION_CURRENT);
+		  if (version != version2)
+		  {
+			throw new CorruptIndexException("Format versions mismatch");
+		  }
+
+		  success = true;
+		}
+		finally
+		{
+		  if (!success)
+		  {
+			IOUtils.closeWhileHandlingException(this.data);
+		  }
+		}
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private NumericEntry readNumericEntry(org.apache.lucene.store.IndexInput meta) throws java.io.IOException
+	  private NumericEntry readNumericEntry(IndexInput meta)
+	  {
+		NumericEntry entry = new NumericEntry();
+		entry.offset = meta.readLong();
+		entry.count = meta.readInt();
+		entry.missingOffset = meta.readLong();
+		if (entry.missingOffset != -1)
+		{
+		  entry.missingBytes = meta.readLong();
+		}
+		else
+		{
+		  entry.missingBytes = 0;
+		}
+		entry.byteWidth = meta.readByte();
+
+		return entry;
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private BinaryEntry readBinaryEntry(org.apache.lucene.store.IndexInput meta) throws java.io.IOException
+	  private BinaryEntry readBinaryEntry(IndexInput meta)
+	  {
+		BinaryEntry entry = new BinaryEntry();
+		entry.offset = meta.readLong();
+		entry.numBytes = meta.readInt();
+		entry.count = meta.readInt();
+		entry.missingOffset = meta.readLong();
+		if (entry.missingOffset != -1)
+		{
+		  entry.missingBytes = meta.readLong();
+		}
+		else
+		{
+		  entry.missingBytes = 0;
+		}
+
+		return entry;
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private SortedEntry readSortedEntry(org.apache.lucene.store.IndexInput meta) throws java.io.IOException
+	  private SortedEntry readSortedEntry(IndexInput meta)
+	  {
+		SortedEntry entry = new SortedEntry();
+		entry.docToOrd = readNumericEntry(meta);
+		entry.values = readBinaryEntry(meta);
+		return entry;
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private SortedSetEntry readSortedSetEntry(org.apache.lucene.store.IndexInput meta) throws java.io.IOException
+	  private SortedSetEntry readSortedSetEntry(IndexInput meta)
+	  {
+		SortedSetEntry entry = new SortedSetEntry();
+		entry.docToOrdAddress = readNumericEntry(meta);
+		entry.ords = readNumericEntry(meta);
+		entry.values = readBinaryEntry(meta);
+		return entry;
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private void readFields(org.apache.lucene.store.IndexInput meta) throws java.io.IOException
+	  private void readFields(IndexInput meta)
+	  {
+		int fieldNumber = meta.readVInt();
+		while (fieldNumber != -1)
+		{
+		  int fieldType = meta.readByte();
+		  if (fieldType == NUMBER)
+		  {
+			numerics[fieldNumber] = readNumericEntry(meta);
+		  }
+		  else if (fieldType == BYTES)
+		  {
+			binaries[fieldNumber] = readBinaryEntry(meta);
+		  }
+		  else if (fieldType == SORTED)
+		  {
+			sorteds[fieldNumber] = readSortedEntry(meta);
+		  }
+		  else if (fieldType == SORTED_SET)
+		  {
+			sortedSets[fieldNumber] = readSortedSetEntry(meta);
+		  }
+		  else
+		  {
+			throw new CorruptIndexException("invalid entry type: " + fieldType + ", input=" + meta);
+		  }
+		  fieldNumber = meta.readVInt();
+		}
+	  }
+
+	  public override long ramBytesUsed()
+	  {
+		return ramBytesUsed_Renamed.get();
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void checkIntegrity() throws java.io.IOException
+	  public override void checkIntegrity()
+	  {
+		if (version >= VERSION_CHECKSUM)
+		{
+		  CodecUtil.checksumEntireFile(data);
+		}
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public synchronized org.apache.lucene.index.NumericDocValues getNumeric(org.apache.lucene.index.FieldInfo field) throws java.io.IOException
+	  public override NumericDocValues getNumeric(FieldInfo field)
+	  {
+		  lock (this)
+		  {
+			NumericDocValues instance = numericInstances[field.number];
+			if (instance == null)
+			{
+			  // Lazy load
+			  instance = loadNumeric(numerics[field.number]);
+			  numericInstances[field.number] = instance;
+			}
+			return instance;
+		  }
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private org.apache.lucene.index.NumericDocValues loadNumeric(NumericEntry entry) throws java.io.IOException
+	  private NumericDocValues loadNumeric(NumericEntry entry)
+	  {
+		data.seek(entry.offset + entry.missingBytes);
+		switch (entry.byteWidth)
+		{
+		case 1:
+		{
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final byte[] values = new byte[entry.count];
+			sbyte[] values = new sbyte[entry.count];
+			data.readBytes(values, 0, entry.count);
+			ramBytesUsed_Renamed.addAndGet(RamUsageEstimator.sizeOf(values));
+			return new NumericDocValuesAnonymousInnerClassHelper(this, values);
+		}
+
+		case 2:
+		{
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final short[] values = new short[entry.count];
+			short[] values = new short[entry.count];
+			for (int i = 0;i < entry.count;i++)
+			{
+			  values[i] = data.readShort();
+			}
+			ramBytesUsed_Renamed.addAndGet(RamUsageEstimator.sizeOf(values));
+			return new NumericDocValuesAnonymousInnerClassHelper2(this, values);
+		}
+
+		case 4:
+		{
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final int[] values = new int[entry.count];
+			int[] values = new int[entry.count];
+			for (int i = 0;i < entry.count;i++)
+			{
+			  values[i] = data.readInt();
+			}
+			ramBytesUsed_Renamed.addAndGet(RamUsageEstimator.sizeOf(values));
+			return new NumericDocValuesAnonymousInnerClassHelper3(this, values);
+		}
+
+		case 8:
+		{
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final long[] values = new long[entry.count];
+			long[] values = new long[entry.count];
+			for (int i = 0;i < entry.count;i++)
+			{
+			  values[i] = data.readLong();
+			}
+			ramBytesUsed_Renamed.addAndGet(RamUsageEstimator.sizeOf(values));
+			return new NumericDocValuesAnonymousInnerClassHelper4(this, values);
+		}
+
+		default:
+		  throw new AssertionError();
+		}
+	  }
+
+	  private class NumericDocValuesAnonymousInnerClassHelper : NumericDocValues
+	  {
+		  private readonly DirectDocValuesProducer outerInstance;
+
+		  private sbyte[] values;
+
+		  public NumericDocValuesAnonymousInnerClassHelper(DirectDocValuesProducer outerInstance, sbyte[] values)
+		  {
+			  this.outerInstance = outerInstance;
+			  this.values = values;
+		  }
+
+		  public override long get(int idx)
+		  {
+			return values[idx];
+		  }
+	  }
+
+	  private class NumericDocValuesAnonymousInnerClassHelper2 : NumericDocValues
+	  {
+		  private readonly DirectDocValuesProducer outerInstance;
+
+		  private short[] values;
+
+		  public NumericDocValuesAnonymousInnerClassHelper2(DirectDocValuesProducer outerInstance, short[] values)
+		  {
+			  this.outerInstance = outerInstance;
+			  this.values = values;
+		  }
+
+		  public override long get(int idx)
+		  {
+			return values[idx];
+		  }
+	  }
+
+	  private class NumericDocValuesAnonymousInnerClassHelper3 : NumericDocValues
+	  {
+		  private readonly DirectDocValuesProducer outerInstance;
+
+		  private int[] values;
+
+		  public NumericDocValuesAnonymousInnerClassHelper3(DirectDocValuesProducer outerInstance, int[] values)
+		  {
+			  this.outerInstance = outerInstance;
+			  this.values = values;
+		  }
+
+		  public override long get(int idx)
+		  {
+			return values[idx];
+		  }
+	  }
+
+	  private class NumericDocValuesAnonymousInnerClassHelper4 : NumericDocValues
+	  {
+		  private readonly DirectDocValuesProducer outerInstance;
+
+		  private long[] values;
+
+		  public NumericDocValuesAnonymousInnerClassHelper4(DirectDocValuesProducer outerInstance, long[] values)
+		  {
+			  this.outerInstance = outerInstance;
+			  this.values = values;
+		  }
+
+		  public override long get(int idx)
+		  {
+			return values[idx];
+		  }
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public synchronized org.apache.lucene.index.BinaryDocValues getBinary(org.apache.lucene.index.FieldInfo field) throws java.io.IOException
+	  public override BinaryDocValues getBinary(FieldInfo field)
+	  {
+		  lock (this)
+		  {
+			BinaryDocValues instance = binaryInstances[field.number];
+			if (instance == null)
+			{
+			  // Lazy load
+			  instance = loadBinary(binaries[field.number]);
+			  binaryInstances[field.number] = instance;
+			}
+			return instance;
+		  }
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private org.apache.lucene.index.BinaryDocValues loadBinary(BinaryEntry entry) throws java.io.IOException
+	  private BinaryDocValues loadBinary(BinaryEntry entry)
+	  {
+		data.seek(entry.offset);
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final byte[] bytes = new byte[entry.numBytes];
+		sbyte[] bytes = new sbyte[entry.numBytes];
+		data.readBytes(bytes, 0, entry.numBytes);
+		data.seek(entry.offset + entry.numBytes + entry.missingBytes);
+
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final int[] address = new int[entry.count+1];
+		int[] address = new int[entry.count + 1];
+		for (int i = 0;i < entry.count;i++)
+		{
+		  address[i] = data.readInt();
+		}
+		address[entry.count] = data.readInt();
+
+		ramBytesUsed_Renamed.addAndGet(RamUsageEstimator.sizeOf(bytes) + RamUsageEstimator.sizeOf(address));
+
+		return new BinaryDocValuesAnonymousInnerClassHelper(this, bytes, address);
+	  }
+
+	  private class BinaryDocValuesAnonymousInnerClassHelper : BinaryDocValues
+	  {
+		  private readonly DirectDocValuesProducer outerInstance;
+
+		  private sbyte[] bytes;
+		  private int[] address;
+
+		  public BinaryDocValuesAnonymousInnerClassHelper(DirectDocValuesProducer outerInstance, sbyte[] bytes, int[] address)
+		  {
+			  this.outerInstance = outerInstance;
+			  this.bytes = bytes;
+			  this.address = address;
+		  }
+
+		  public override void get(int docID, BytesRef result)
+		  {
+			result.bytes = bytes;
+			result.offset = address[docID];
+			result.length = address[docID + 1] - result.offset;
+		  };
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public synchronized org.apache.lucene.index.SortedDocValues getSorted(org.apache.lucene.index.FieldInfo field) throws java.io.IOException
+	  public override SortedDocValues getSorted(FieldInfo field)
+	  {
+		  lock (this)
+		  {
+			SortedDocValues instance = sortedInstances[field.number];
+			if (instance == null)
+			{
+			  // Lazy load
+			  instance = loadSorted(field);
+			  sortedInstances[field.number] = instance;
+			}
+			return instance;
+		  }
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private org.apache.lucene.index.SortedDocValues loadSorted(org.apache.lucene.index.FieldInfo field) throws java.io.IOException
+	  private SortedDocValues loadSorted(FieldInfo field)
+	  {
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final SortedEntry entry = sorteds.get(field.number);
+		SortedEntry entry = sorteds[field.number];
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final org.apache.lucene.index.NumericDocValues docToOrd = loadNumeric(entry.docToOrd);
+		NumericDocValues docToOrd = loadNumeric(entry.docToOrd);
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final org.apache.lucene.index.BinaryDocValues values = loadBinary(entry.values);
+		BinaryDocValues values = loadBinary(entry.values);
+
+		return new SortedDocValuesAnonymousInnerClassHelper(this, entry, docToOrd, values);
+	  }
+
+	  private class SortedDocValuesAnonymousInnerClassHelper : SortedDocValues
+	  {
+		  private readonly DirectDocValuesProducer outerInstance;
+
+		  private org.apache.lucene.codecs.memory.DirectDocValuesProducer.SortedEntry entry;
+		  private NumericDocValues docToOrd;
+		  private BinaryDocValues values;
+
+		  public SortedDocValuesAnonymousInnerClassHelper(DirectDocValuesProducer outerInstance, org.apache.lucene.codecs.memory.DirectDocValuesProducer.SortedEntry entry, NumericDocValues docToOrd, BinaryDocValues values)
+		  {
+			  this.outerInstance = outerInstance;
+			  this.entry = entry;
+			  this.docToOrd = docToOrd;
+			  this.values = values;
+		  }
+
+
+		  public override int getOrd(int docID)
+		  {
+			return (int) docToOrd.get(docID);
+		  }
+
+		  public override void lookupOrd(int ord, BytesRef result)
+		  {
+			values.get(ord, result);
+		  }
+
+		  public override int ValueCount
+		  {
+			  get
+			  {
+				return entry.values.count;
+			  }
+		  }
+
+		  // Leave lookupTerm to super's binary search
+
+		  // Leave termsEnum to super
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public synchronized org.apache.lucene.index.SortedSetDocValues getSortedSet(org.apache.lucene.index.FieldInfo field) throws java.io.IOException
+	  public override SortedSetDocValues getSortedSet(FieldInfo field)
+	  {
+		  lock (this)
+		  {
+			SortedSetRawValues instance = sortedSetInstances[field.number];
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final SortedSetEntry entry = sortedSets.get(field.number);
+			SortedSetEntry entry = sortedSets[field.number];
+			if (instance == null)
+			{
+			  // Lazy load
+			  instance = loadSortedSet(entry);
+			  sortedSetInstances[field.number] = instance;
+			}
+        
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final org.apache.lucene.index.NumericDocValues docToOrdAddress = instance.docToOrdAddress;
+			NumericDocValues docToOrdAddress = instance.docToOrdAddress;
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final org.apache.lucene.index.NumericDocValues ords = instance.ords;
+			NumericDocValues ords = instance.ords;
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final org.apache.lucene.index.BinaryDocValues values = instance.values;
+			BinaryDocValues values = instance.values;
+        
+			// Must make a new instance since the iterator has state:
+			return new RandomAccessOrdsAnonymousInnerClassHelper(this, entry, docToOrdAddress, ords, values);
+		  }
+	  }
+
+	  private class RandomAccessOrdsAnonymousInnerClassHelper : RandomAccessOrds
+	  {
+		  private readonly DirectDocValuesProducer outerInstance;
+
+		  private org.apache.lucene.codecs.memory.DirectDocValuesProducer.SortedSetEntry entry;
+		  private NumericDocValues docToOrdAddress;
+		  private NumericDocValues ords;
+		  private BinaryDocValues values;
+
+		  public RandomAccessOrdsAnonymousInnerClassHelper(DirectDocValuesProducer outerInstance, org.apache.lucene.codecs.memory.DirectDocValuesProducer.SortedSetEntry entry, NumericDocValues docToOrdAddress, NumericDocValues ords, BinaryDocValues values)
+		  {
+			  this.outerInstance = outerInstance;
+			  this.entry = entry;
+			  this.docToOrdAddress = docToOrdAddress;
+			  this.ords = ords;
+			  this.values = values;
+		  }
+
+		  internal int ordStart;
+		  internal int ordUpto;
+		  internal int ordLimit;
+
+		  public override long nextOrd()
+		  {
+			if (ordUpto == ordLimit)
+			{
+			  return NO_MORE_ORDS;
+			}
+			else
+			{
+			  return ords.get(ordUpto++);
+			}
+		  }
+
+		  public override int Document
+		  {
+			  set
+			  {
+				ordStart = ordUpto = (int) docToOrdAddress.get(value);
+				ordLimit = (int) docToOrdAddress.get(value+1);
+			  }
+		  }
+
+		  public override void lookupOrd(long ord, BytesRef result)
+		  {
+			values.get((int) ord, result);
+		  }
+
+		  public override long ValueCount
+		  {
+			  get
+			  {
+				return entry.values.count;
+			  }
+		  }
+
+		  public override long ordAt(int index)
+		  {
+			return ords.get(ordStart + index);
+		  }
+
+		  public override int cardinality()
+		  {
+			return ordLimit - ordStart;
+		  }
+
+		  // Leave lookupTerm to super's binary search
+
+		  // Leave termsEnum to super
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private SortedSetRawValues loadSortedSet(SortedSetEntry entry) throws java.io.IOException
+	  private SortedSetRawValues loadSortedSet(SortedSetEntry entry)
+	  {
+		SortedSetRawValues instance = new SortedSetRawValues();
+		instance.docToOrdAddress = loadNumeric(entry.docToOrdAddress);
+		instance.ords = loadNumeric(entry.ords);
+		instance.values = loadBinary(entry.values);
+		return instance;
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private org.apache.lucene.util.Bits getMissingBits(int fieldNumber, final long offset, final long length) throws java.io.IOException
+//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
+	  private Bits getMissingBits(int fieldNumber, long offset, long length)
+	  {
+		if (offset == -1)
+		{
+		  return new Bits.MatchAllBits(maxDoc);
+		}
+		else
+		{
+		  Bits instance;
+		  lock (this)
+		  {
+			instance = docsWithFieldInstances[fieldNumber];
+			if (instance == null)
+			{
+			  IndexInput data = this.data.clone();
+			  data.seek(offset);
+			  Debug.Assert(length % 8 == 0);
+			  long[] bits = new long[(int) length >> 3];
+			  for (int i = 0; i < bits.Length; i++)
+			  {
+				bits[i] = data.readLong();
+			  }
+			  instance = new FixedBitSet(bits, maxDoc);
+			  docsWithFieldInstances[fieldNumber] = instance;
+			}
+		  }
+		  return instance;
+		}
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public org.apache.lucene.util.Bits getDocsWithField(org.apache.lucene.index.FieldInfo field) throws java.io.IOException
+	  public override Bits getDocsWithField(FieldInfo field)
+	  {
+		switch (field.DocValuesType)
+		{
+		  case SORTED_SET:
+			return DocValues.docsWithValue(getSortedSet(field), maxDoc);
+		  case SORTED:
+			return DocValues.docsWithValue(getSorted(field), maxDoc);
+		  case BINARY:
+			BinaryEntry be = binaries[field.number];
+			return getMissingBits(field.number, be.missingOffset, be.missingBytes);
+		  case NUMERIC:
+			NumericEntry ne = numerics[field.number];
+			return getMissingBits(field.number, ne.missingOffset, ne.missingBytes);
+		  default:
+			throw new AssertionError();
+		}
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void close() throws java.io.IOException
+	  public override void close()
+	  {
+		data.close();
+	  }
+
+	  internal class SortedSetRawValues
+	  {
+		internal NumericDocValues docToOrdAddress;
+		internal NumericDocValues ords;
+		internal BinaryDocValues values;
+	  }
+
+	  internal class NumericEntry
+	  {
+		internal long offset;
+		internal int count;
+		internal long missingOffset;
+		internal long missingBytes;
+		internal sbyte byteWidth;
+		internal int packedIntsVersion;
+	  }
+
+	  internal class BinaryEntry
+	  {
+		internal long offset;
+		internal long missingOffset;
+		internal long missingBytes;
+		internal int count;
+		internal int numBytes;
+		internal int minLength;
+		internal int maxLength;
+		internal int packedIntsVersion;
+		internal int blockSize;
+	  }
+
+	  internal class SortedEntry
+	  {
+		internal NumericEntry docToOrd;
+		internal BinaryEntry values;
+	  }
+
+	  internal class SortedSetEntry
+	  {
+		internal NumericEntry docToOrdAddress;
+		internal NumericEntry ords;
+		internal BinaryEntry values;
+	  }
+
+	  internal class FSTEntry
+	  {
+		internal long offset;
+		internal long numOrds;
+	  }
+	}
+
+}
\ No newline at end of file