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/12/02 18:41:39 UTC
[3/4] lucenenet git commit: finished conversion of
Lucene.Net.Codes.Intblock
finished conversion of Lucene.Net.Codes.Intblock
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/df4afdc3
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/df4afdc3
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/df4afdc3
Branch: refs/heads/master
Commit: df4afdc3ee75fc664525402a49756dcf8acd8102
Parents: a33ca52
Author: Prescott Nasser <pn...@apache.org>
Authored: Sat Nov 29 16:03:22 2014 -0800
Committer: Prescott Nasser <pn...@apache.org>
Committed: Sat Nov 29 16:03:22 2014 -0800
----------------------------------------------------------------------
.../Intblock/FixedIntBlockIndexInput.cs | 45 ++--
.../Intblock/FixedIntBlockIndexOutput.cs | 153 +++++--------
src/Lucene.Net.Codecs/Intblock/IBlockReader.cs | 10 +-
src/Lucene.Net.Codecs/Intblock/Index.cs | 78 -------
.../Intblock/IntBlockIndexInput.cs | 84 ++++++++
.../Intblock/IntBlockIndexOutput.cs | 85 ++++++++
.../Intblock/IntBlockIndexReader.cs | 100 +++++++++
src/Lucene.Net.Codecs/Intblock/Reader.cs | 81 -------
.../Intblock/VariableIntBlockIndexInput.cs | 216 +++++--------------
.../Intblock/VariableIntBlockIndexOutput.cs | 113 +++-------
src/Lucene.Net.Codecs/Lucene.Net.Codecs.csproj | 5 +-
src/Lucene.Net.Codecs/Sep/IntIndexOutput.cs | 2 +
12 files changed, 435 insertions(+), 537 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/df4afdc3/src/Lucene.Net.Codecs/Intblock/FixedIntBlockIndexInput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Intblock/FixedIntBlockIndexInput.cs b/src/Lucene.Net.Codecs/Intblock/FixedIntBlockIndexInput.cs
index dc7b558..f992c77 100644
--- a/src/Lucene.Net.Codecs/Intblock/FixedIntBlockIndexInput.cs
+++ b/src/Lucene.Net.Codecs/Intblock/FixedIntBlockIndexInput.cs
@@ -1,4 +1,4 @@
-/*
+/*
* 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.
@@ -15,22 +15,25 @@
* limitations under the License.
*/
-using Lucene.Net.Codecs.Sep;
-using Lucene.Net.Store;
-
namespace Lucene.Net.Codecs.Intblock
{
+ using Sep;
+ using IntIndexInput = Sep.IntIndexInput;
+ using IndexInput = Store.IndexInput;
+
/// <summary>
/// Naive int block API that writes vInts. This is
- /// expected to give poor performance; it's really only for
- /// testing the pluggability. One should typically use pfor instead. */
- ///
+ /// expected to give poor performance; it's really only for
+ /// testing the pluggability. One should typically use pfor instead.
+ /// </summary>
+
+ /// <summary>
/// Abstract base class that reads fixed-size blocks of ints
- /// from an IndexInput. While this is a simple approach, a
- /// more performant approach would directly create an impl
- /// of IntIndexInput inside Directory. Wrapping a generic
- /// IndexInput will likely cost performance.
+ /// from an IndexInput. While this is a simple approach, a
+ /// more performant approach would directly create an impl
+ /// of IntIndexInput inside Directory. Wrapping a generic
+ /// IndexInput will likely cost performance.
///
/// @lucene.experimental
/// </summary>
@@ -38,21 +41,20 @@ namespace Lucene.Net.Codecs.Intblock
{
private readonly IndexInput _input;
- private readonly int _blockSize;
+ protected internal readonly int BLOCK_SIZE;
- protected FixedIntBlockIndexInput(IndexInput input)
+ public FixedIntBlockIndexInput(IndexInput @in)
{
- _input = input;
- _blockSize = input.ReadVInt();
+ _input = @in;
+ BLOCK_SIZE = @in.ReadVInt();
}
public override IntIndexInputReader Reader()
{
- var buffer = new int[_blockSize];
- var clone = (IndexInput)_input.Clone();
-
+ var buffer = new int[BLOCK_SIZE];
+ var clone = (IndexInput) _input.Clone();
// TODO: can this be simplified?
- return new Reader(clone, buffer, BlockReader(clone, buffer));
+ return new IntBlockIndexReader(clone, buffer, GetBlockReader(clone, buffer));
}
public override void Dispose()
@@ -62,10 +64,11 @@ namespace Lucene.Net.Codecs.Intblock
public override IntIndexInputIndex Index()
{
- return new Index();
+ return new IntBlockIndexInput(this);
}
- protected abstract VariableIntBlockIndexInput.BlockReader BlockReader(IndexInput input, int[] buffer);
+ protected internal abstract IBlockReader GetBlockReader(IndexInput @in, int[] buffer);
}
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/df4afdc3/src/Lucene.Net.Codecs/Intblock/FixedIntBlockIndexOutput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Intblock/FixedIntBlockIndexOutput.cs b/src/Lucene.Net.Codecs/Intblock/FixedIntBlockIndexOutput.cs
index b19a0a3..96d08d1 100644
--- a/src/Lucene.Net.Codecs/Intblock/FixedIntBlockIndexOutput.cs
+++ b/src/Lucene.Net.Codecs/Intblock/FixedIntBlockIndexOutput.cs
@@ -1,4 +1,4 @@
-/*
+/*
* 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.
@@ -15,127 +15,74 @@
* limitations under the License.
*/
-/** Naive int block API that writes vInts. This is
- * expected to give poor performance; it's really only for
- * testing the pluggability. One should typically use pfor instead. */
+namespace Lucene.Net.Codecs.Intblock
+{
+ using Sep;
+ using IntIndexOutput = Sep.IntIndexOutput;
+ using IndexOutput = Store.IndexOutput;
-using System;
-using System.Diagnostics;
-using Lucene.Net.Codecs.Sep;
-using Lucene.Net.Store;
+ /// <summary>
+ /// Naive int block API that writes vInts. This is
+ /// expected to give poor performance; it's really only for
+ /// testing the pluggability. One should typically use pfor instead.
+ /// </summary>
-/// <summary>
-/// Abstract base class that writes fixed-size blocks of ints to an
-/// IndexOutput. While this is a simple approach, a more
-/// performant approach would directly create an impl of
-/// IntIndexOutput inside Directory. Wrapping a generic IndexInput
-/// will likely cost performance.
-///
-/// * @lucene.experimental
-/// </summary>
-public abstract class FixedIntBlockIndexOutput : IntIndexOutput {
-
- protected IndexOutput out;
- private int blockSize;
- protected int int[] buffer;
- private int upto;
-
- protected FixedIntBlockIndexOutput(IndexOutput out, int fixedBlockSize) {
- blockSize = fixedBlockSize;
- this.out = out;
- out.WriteVInt(blockSize);
- buffer = new int[blockSize];
- }
-
- protected abstract void flushBlock() ;
+ /// <summary>
+ /// Abstract base class that writes fixed-size blocks of ints
+ /// to an IndexOutput. While this is a simple approach, a
+ /// more performant approach would directly create an impl
+ /// of IntIndexOutput inside Directory. Wrapping a generic
+ /// IndexInput will likely cost performance.
+ ///
+ /// @lucene.experimental
+ /// </summary>
+ public abstract class FixedIntBlockIndexOutput : IntIndexOutput
+ {
+ private readonly int _blockSize;
+ protected internal readonly int[] BUFFER;
- public override IntIndexOutputIndex index() {
- return new Index();
- }
+ protected internal FixedIntBlockIndexOutput(IndexOutput output, int fixedBlockSize)
+ {
+ _blockSize = fixedBlockSize;
+ OUTPUT = output;
+ output.WriteVInt(_blockSize);
+ BUFFER = new int[_blockSize];
+ }
- private class Index : IntIndexOutputIndex
- {
- private long fp;
- private int upto;
- private long lastFP;
- private int lastUpto;
+ protected internal abstract void FlushBlock();
- public override void Mark()
+ public override IntIndexOutputIndex Index()
{
- fp =out.
- FilePointer;
- upto = FixedIntBlockIndexOutput.
- this.upto;
+ return new IntBlockIndexOuput(this);
}
- public override void CopyFrom(IntIndexOutputIndex other, bool copyLast)
+ public override void Write(int v)
{
- Index idx = (Index) other;
- fp = idx.fp;
- upto = idx.upto;
- if (copyLast)
+ BUFFER[_upto++] = v;
+ if (_upto == _blockSize)
{
- lastFP = fp;
- lastUpto = upto;
+ FlushBlock();
+ _upto = 0;
}
}
- public override void Write(DataOutput indexOut, bool absolute)
+ public override void Dispose()
{
- if (absolute)
+ try
{
- indexOut.WriteVInt(upto);
- indexOut.WriteVLong(fp);
+ if (_upto > 0)
+ {
+ // NOTE: entries in the block after current upto are
+ // invalid
+ FlushBlock();
+ }
}
- else if (fp == lastFP)
+ finally
{
- // same block
- Debug.Assert(upto >= lastUpto);
- var uptoDelta = upto - lastUpto;
- indexOut.WriteVInt(uptoDelta << 1 | 1);
+ OUTPUT.Dispose();
}
- else
- {
- // new block
- indexOut.WriteVInt(upto << 1);
- indexOut.WriteVLong(fp - lastFP);
- }
- lastUpto = upto;
- lastFP = fp;
- }
-
- public override String ToString()
- {
- return String.Format("fp={0} upto={1}", fp, upto);
}
}
- public override void Write(int v)
- {
- buffer[upto++] = v;
- if (upto == blockSize)
- {
- flushBlock();
- upto = 0;
- }
- }
-
- public override void Dispose()
- {
- try
- {
- if (upto > 0)
- {
- // NOTE: entries in the block after current upto are
- // invalid
- flushBlock();
- }
- }
- finally
- {
- out.
- Dispose();
- }
- }
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/df4afdc3/src/Lucene.Net.Codecs/Intblock/IBlockReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Intblock/IBlockReader.cs b/src/Lucene.Net.Codecs/Intblock/IBlockReader.cs
index adf14ec..6218502 100644
--- a/src/Lucene.Net.Codecs/Intblock/IBlockReader.cs
+++ b/src/Lucene.Net.Codecs/Intblock/IBlockReader.cs
@@ -18,12 +18,14 @@
namespace Lucene.Net.Codecs.Intblock
{
/// <summary>
- /// Interface for fixed-size block decoders
- ///
- /// Implementations should decode into the buffer in {@link #ReadBlock}
+ /// Interface for variable-size block decoders.
+ /// <para>
+ /// Implementations should decode into the buffer in <seealso cref="#readBlock"/>.
+ /// </para>
/// </summary>
public interface IBlockReader
{
- void ReadBlock();
+ int ReadBlock();
+ void Seek(long pos);
}
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/df4afdc3/src/Lucene.Net.Codecs/Intblock/Index.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Intblock/Index.cs b/src/Lucene.Net.Codecs/Intblock/Index.cs
deleted file mode 100644
index d2bd9a9..0000000
--- a/src/Lucene.Net.Codecs/Intblock/Index.cs
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.
- */
-
-namespace Lucene.Net.Codecs.Intblock
-{
- using Sep;
- using Store;
- using System;
- using System.Diagnostics;
-
- internal class Index : IntIndexInputIndex
- {
- private long _fp;
- private int _upto;
-
- public override void Read(DataInput indexIn, bool absolute)
- {
- if (absolute)
- {
- _upto = indexIn.ReadVInt();
- _fp = indexIn.ReadVLong();
- }
- else
- {
- var uptoDelta = indexIn.ReadVInt();
- if ((uptoDelta & 1) == 1)
- {
- // same block
- _upto += (int)((uint)uptoDelta >> 1);
- }
- else
- {
- // new block
- _upto = (int)((uint)uptoDelta >> 1);
- _fp += indexIn.ReadVLong();
- }
- }
- Debug.Assert(_upto < BlockSize);
- }
-
- public override void Seek(IntIndexInputReader other)
- {
- ((Reader) other).Seek(_fp, _upto);
- }
-
- public override void CopyFrom(IntIndexInputIndex other)
- {
- var idx = (Index) other;
- _fp = idx._fp;
- _upto = idx._upto;
- }
-
- public override IntIndexInputIndex Clone()
- {
- return new Index {_fp = _fp, _upto = _upto};
- }
-
- public override String ToString()
- {
- return String.Format("fp={0} upto={1}", _fp, _upto);
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/df4afdc3/src/Lucene.Net.Codecs/Intblock/IntBlockIndexInput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Intblock/IntBlockIndexInput.cs b/src/Lucene.Net.Codecs/Intblock/IntBlockIndexInput.cs
new file mode 100644
index 0000000..0e3e67f
--- /dev/null
+++ b/src/Lucene.Net.Codecs/Intblock/IntBlockIndexInput.cs
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ */
+
+namespace Lucene.Net.Codecs.Intblock
+{
+ using Sep;
+ using Store;
+
+ internal class IntBlockIndexInput : IntIndexInputIndex
+ {
+ private readonly IntIndexInput _outerInstance;
+ private long _fp;
+ private int _upto;
+
+ public IntBlockIndexInput(IntIndexInput outerInstance)
+ {
+ _outerInstance = outerInstance;
+ }
+
+ public override void Read(DataInput indexIn, bool absolute)
+ {
+ if (absolute)
+ {
+ _upto = indexIn.ReadVInt();
+ _fp = indexIn.ReadVLong();
+ }
+ else
+ {
+ int uptoDelta = indexIn.ReadVInt();
+ if ((uptoDelta & 1) == 1)
+ {
+ // same block
+ _upto += (int) ((uint) uptoDelta >> 1);
+ }
+ else
+ {
+ // new block
+ _upto = (int) ((uint) uptoDelta >> 1);
+ _fp += indexIn.ReadVLong();
+ }
+ }
+ // TODO: we can't do this assert because non-causal
+ // int encoders can have upto over the buffer size
+ //assert upto < maxBlockSize: "upto=" + upto + " max=" + maxBlockSize;
+ }
+
+ public override string ToString()
+ {
+ return "VarIntBlock.Index fp=" + _fp + " upto=" + _upto;
+ }
+
+ public override void Seek(IntIndexInputReader other)
+ {
+ ((IntBlockIndexReader)other).Seek(_fp, _upto);
+ }
+
+ public override void CopyFrom(IntIndexInputIndex other)
+ {
+ var idx = (IntBlockIndexInput)other;
+ _fp = idx._fp;
+ _upto = idx._upto;
+ }
+
+ public override IntIndexInputIndex Clone()
+ {
+ var other = new IntBlockIndexInput(_outerInstance) {_fp = _fp, _upto = _upto};
+ return other;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/df4afdc3/src/Lucene.Net.Codecs/Intblock/IntBlockIndexOutput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Intblock/IntBlockIndexOutput.cs b/src/Lucene.Net.Codecs/Intblock/IntBlockIndexOutput.cs
new file mode 100644
index 0000000..b5cec95
--- /dev/null
+++ b/src/Lucene.Net.Codecs/Intblock/IntBlockIndexOutput.cs
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+
+namespace Lucene.Net.Codecs.Intblock
+{
+ using Sep;
+ using Store;
+ using System.Diagnostics;
+
+ internal class IntBlockIndexOuput : IntIndexOutputIndex
+ {
+ private readonly IntIndexOutput _outerInstance;
+ private long _fp;
+ private int _upto;
+ private long _lastFp;
+ private int _lastUpto;
+
+ public IntBlockIndexOuput(IntIndexOutput outerInstance)
+ {
+ _outerInstance = outerInstance;
+ }
+
+ public override void Mark()
+ {
+ _fp = _outerInstance.OUTPUT.FilePointer;
+ _upto = _outerInstance._upto;
+ }
+
+ public override void CopyFrom(IntIndexOutputIndex other, bool copyLast)
+ {
+ var idx = (IntBlockIndexOuput)other;
+ _fp = idx._fp;
+ _upto = idx._upto;
+ if (copyLast)
+ {
+ _lastFp = _fp;
+ _lastUpto = _upto;
+ }
+ }
+
+ public override void Write(DataOutput indexOut, bool absolute)
+ {
+ Debug.Assert(_upto >= 0);
+ if (absolute)
+ {
+ indexOut.WriteVInt(_upto);
+ indexOut.WriteVLong(_fp);
+ }
+ else if (_fp == _lastFp)
+ {
+ // same block
+ Debug.Assert(_upto >= _lastUpto);
+ var uptoDelta = _upto - _lastUpto;
+ indexOut.WriteVInt(uptoDelta << 1 | 1);
+ }
+ else
+ {
+ // new block
+ indexOut.WriteVInt(_upto << 1);
+ indexOut.WriteVLong(_fp - _lastFp);
+ }
+ _lastUpto = _upto;
+ _lastFp = _fp;
+ }
+
+ public override string ToString()
+ {
+ return "fp=" + _fp + " upto=" + _upto;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/df4afdc3/src/Lucene.Net.Codecs/Intblock/IntBlockIndexReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Intblock/IntBlockIndexReader.cs b/src/Lucene.Net.Codecs/Intblock/IntBlockIndexReader.cs
new file mode 100644
index 0000000..22a4aa7
--- /dev/null
+++ b/src/Lucene.Net.Codecs/Intblock/IntBlockIndexReader.cs
@@ -0,0 +1,100 @@
+/*
+ * 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.
+ */
+
+namespace Lucene.Net.Codecs.Intblock
+{
+ using Sep;
+ using Store;
+ using System.Diagnostics;
+
+ internal class IntBlockIndexReader : IntIndexInputReader
+ {
+ private readonly IndexInput _input;
+
+ public readonly int[] PENDING;
+ private int _upto;
+
+ private bool _seekPending;
+ private long _pendingFp;
+ private int _pendingUpto;
+ private long _lastBlockFp;
+ private int _blockSize;
+ private readonly IBlockReader _blockReader;
+
+ public IntBlockIndexReader(IndexInput input, int[] pending, IBlockReader blockReader)
+ {
+ _input = input;
+ PENDING = pending;
+ _blockReader = blockReader;
+ _blockSize = pending.Length;
+ _upto = _blockSize;
+ }
+
+ internal virtual void Seek(long fp, int upto)
+ {
+ // TODO: should we do this in real-time, not lazy?
+ _pendingFp = fp;
+ _pendingUpto = upto;
+ Debug.Assert(_pendingUpto >= 0, "pendingUpto=" + _pendingUpto);
+ _seekPending = true;
+ }
+
+ internal void MaybeSeek()
+ {
+ if (!_seekPending) return;
+
+ if (_pendingFp != _lastBlockFp)
+ {
+ // need new block
+ _input.Seek(_pendingFp);
+ _lastBlockFp = _pendingFp;
+ _blockReader.Seek(_pendingFp);
+ _blockSize = _blockReader.ReadBlock();
+ }
+ _upto = _pendingUpto;
+
+ // TODO: if we were more clever when writing the
+ // index, such that a seek point wouldn't be written
+ // until the int encoder "committed", we could avoid
+ // this (likely minor) inefficiency:
+
+ // This is necessary for int encoders that are
+ // non-causal, ie must see future int values to
+ // encode the current ones.
+ while (_upto >= _blockSize)
+ {
+ _upto -= _blockSize;
+ _lastBlockFp = _input.FilePointer;
+ _blockSize = _blockReader.ReadBlock();
+ }
+ _seekPending = false;
+ }
+
+ public override int Next()
+ {
+ MaybeSeek();
+ if (_upto == _blockSize)
+ {
+ _lastBlockFp = _input.FilePointer;
+ _blockSize = _blockReader.ReadBlock();
+ _upto = 0;
+ }
+
+ return PENDING[_upto++];
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/df4afdc3/src/Lucene.Net.Codecs/Intblock/Reader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Intblock/Reader.cs b/src/Lucene.Net.Codecs/Intblock/Reader.cs
deleted file mode 100644
index 4966c14..0000000
--- a/src/Lucene.Net.Codecs/Intblock/Reader.cs
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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 System.Diagnostics;
-using Lucene.Net.Codecs.Sep;
-using Lucene.Net.Store;
-
-namespace Lucene.Net.Codecs.Intblock
-{
- internal class Reader : IntIndexInputReader
- {
-
- private readonly IndexInput _input;
- private readonly VariableIntBlockIndexInput.BlockReader _blockReader;
- private readonly int _blockSize;
- private readonly int[] _pending;
-
- private int _upto;
- private bool _seekPending;
- private long _pendingFp;
- private long _lastBlockFp = -1;
-
- public Reader(IndexInput input, int[] pending, VariableIntBlockIndexInput.BlockReader blockReader)
- {
- _input = input;
- _pending = pending;
- _blockSize = pending.Length;
- _blockReader = blockReader;
- _upto = _blockSize;
- }
-
- private void Seek(long fp, int upto)
- {
- Debug.Assert(upto < _blockSize);
-
- if (_seekPending || fp != _lastBlockFp)
- {
- _pendingFp = fp;
- _seekPending = true;
- }
-
- _upto = upto;
- }
-
- public override int Next()
- {
- if (_seekPending)
- {
- // Seek & load new block
- _input.Seek(_pendingFp);
- _lastBlockFp = _pendingFp;
- _blockReader.readBlock();
- _seekPending = false;
- }
- else if (_upto == _blockSize)
- {
- // Load new block
- _lastBlockFp = _input.FilePointer;
- _blockReader.readBlock();
- _upto = 0;
- }
-
- return _pending[_upto++];
- }
- }
-}
-
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/df4afdc3/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexInput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexInput.cs b/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexInput.cs
index cc0b6f1..2ed4c47 100644
--- a/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexInput.cs
+++ b/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexInput.cs
@@ -1,4 +1,4 @@
-/*
+/*
* 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.
@@ -15,180 +15,60 @@
* limitations under the License.
*/
-/** Naive int block API that writes vInts. This is
- * expected to give poor performance; it's really only for
- * testing the pluggability. One should typically use pfor instead. */
-
-// TODO: much of this can be shared code w/ the fixed case
-
-/** Abstract base class that reads variable-size blocks of ints
- * from an IndexInput. While this is a simple approach, a
- * more performant approach would directly create an impl
- * of IntIndexInput inside Directory. Wrapping a generic
- * IndexInput will likely cost performance.
- *
- * @lucene.experimental
- */
-
-using Lucene.Net.Codecs.Sep;
-using Lucene.Net.Store;
-
-public abstract class VariableIntBlockIndexInput : IntIndexInput {
-
- protected final IndexInput in;
- protected final int maxBlockSize;
-
- protected VariableIntBlockIndexInput(final IndexInput in) {
- this.in = in;
- maxBlockSize = in.readInt();
- }
-
- @Override
- public IntIndexInput.Reader reader() {
- final int[] buffer = new int[maxBlockSize];
- final IndexInput clone = in.clone();
- // TODO: can this be simplified?
- return new Reader(clone, buffer, this.getBlockReader(clone, buffer));
- }
-
- @Override
- public void close() {
- in.close();
- }
-
- @Override
- public IntIndexInput.Index index() {
- return new Index();
- }
-
- protected abstract BlockReader getBlockReader(IndexInput in, int[] buffer) ;
-
- /**
- * Interface for variable-size block decoders.
- * <p>
- * Implementations should decode into the buffer in {@link #readBlock}.
- */
- public interface BlockReader {
- public int readBlock() ;
- public void seek(long pos) ;
- }
-
- private static class Reader : IntIndexInputReader {
- private final IndexInput in;
-
- public final int[] pending;
- int upto;
-
- private bool seekPending;
- private long pendingFP;
- private int pendingUpto;
- private long lastBlockFP;
- private int blockSize;
- private final BlockReader blockReader;
-
- public Reader(final IndexInput in, final int[] pending, final BlockReader blockReader) {
- this.in = in;
- this.pending = pending;
- this.blockReader = blockReader;
- }
-
- void seek(final long fp, final int upto) {
- // TODO: should we do this in real-time, not lazy?
- pendingFP = fp;
- pendingUpto = upto;
- Debug.Assert( pendingUpto >= 0: "pendingUpto=" + pendingUpto;
- seekPending = true;
- }
-
- private final void maybeSeek() {
- if (seekPending) {
- if (pendingFP != lastBlockFP) {
- // need new block
- in.seek(pendingFP);
- blockReader.seek(pendingFP);
- lastBlockFP = pendingFP;
- blockSize = blockReader.readBlock();
+namespace Lucene.Net.Codecs.Intblock
+{
+ using Sep;
+ using IntIndexInput = Sep.IntIndexInput;
+ using IndexInput = Store.IndexInput;
+
+ /// <summary>
+ /// Naive int block API that writes vInts. This is
+ /// expected to give poor performance; it's really only for
+ /// testing the pluggability. One should typically use pfor instead.
+ /// </summary>
+
+ // TODO: much of this can be shared code w/ the fixed case
+
+ /// <summary>
+ /// Abstract base class that reads variable-size blocks of ints
+ /// from an IndexInput. While this is a simple approach, a
+ /// more performant approach would directly create an impl
+ /// of IntIndexInput inside Directory. Wrapping a generic
+ /// IndexInput will likely cost performance.
+ ///
+ /// @lucene.experimental
+ /// </summary>
+ public abstract class VariableIntBlockIndexInput : IntIndexInput
+ {
+ private readonly IndexInput _input;
+ protected internal readonly int MAX_BLOCK_SIZE;
+
+ protected internal VariableIntBlockIndexInput(IndexInput input)
+ {
+ _input = input;
+ MAX_BLOCK_SIZE = input.ReadInt();
}
- upto = pendingUpto;
-
- // TODO: if we were more clever when writing the
- // index, such that a seek point wouldn't be written
- // until the int encoder "committed", we could avoid
- // this (likely minor) inefficiency:
- // This is necessary for int encoders that are
- // non-causal, ie must see future int values to
- // encode the current ones.
- while(upto >= blockSize) {
- upto -= blockSize;
- lastBlockFP = in.getFilePointer();
- blockSize = blockReader.readBlock();
+ public override IntIndexInputReader Reader()
+ {
+ var buffer = new int[MAX_BLOCK_SIZE];
+ var clone = (IndexInput)_input.Clone();
+ // TODO: can this be simplified?
+ return new IntBlockIndexReader(clone, buffer, GetBlockReader(clone, buffer));
}
- seekPending = false;
- }
- }
-
- @Override
- public int next() {
- this.maybeSeek();
- if (upto == blockSize) {
- lastBlockFP = in.getFilePointer();
- blockSize = blockReader.readBlock();
- upto = 0;
- }
- return pending[upto++];
- }
- }
-
- private class Index : IntIndexInputIndex {
- private long fp;
- private int upto;
-
- @Override
- public void read(final DataInput indexIn, final bool absolute) {
- if (absolute) {
- upto = indexIn.readVInt();
- fp = indexIn.readVLong();
- } else {
- final int uptoDelta = indexIn.readVInt();
- if ((uptoDelta & 1) == 1) {
- // same block
- upto += uptoDelta >>> 1;
- } else {
- // new block
- upto = uptoDelta >>> 1;
- fp += indexIn.readVLong();
+ public override void Dispose()
+ {
+ _input.Dispose();
}
- }
- // TODO: we can't do this Debug.Assert( because non-causal
- // int encoders can have upto over the buffer size
- //Debug.Assert( upto < maxBlockSize: "upto=" + upto + " max=" + maxBlockSize;
- }
- @Override
- public String toString() {
- return "VarIntBlock.Index fp=" + fp + " upto=" + upto + " maxBlock=" + maxBlockSize;
- }
+ public override IntIndexInputIndex Index()
+ {
+ return new IntBlockIndexInput(this);
+ }
- @Override
- public void seek(final IntIndexInput.Reader other) {
- ((Reader) other).seek(fp, upto);
- }
+ protected internal abstract IBlockReader GetBlockReader(IndexInput @in, int[] buffer);
- @Override
- public void copyFrom(final IntIndexInput.Index other) {
- final Index idx = (Index) other;
- fp = idx.fp;
- upto = idx.upto;
}
- @Override
- public Index clone() {
- Index other = new Index();
- other.fp = fp;
- other.upto = upto;
- return other;
- }
- }
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/df4afdc3/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexOutput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexOutput.cs b/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexOutput.cs
index a5de4ca..dd30ba7 100644
--- a/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexOutput.cs
+++ b/src/Lucene.Net.Codecs/Intblock/VariableIntBlockIndexOutput.cs
@@ -1,4 +1,4 @@
-/*
+/*
* 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.
@@ -19,53 +19,56 @@ namespace Lucene.Net.Codecs.Intblock
{
using System.Diagnostics;
- using Store;
using Sep;
+ using IntIndexOutput = Sep.IntIndexOutput;
+ using IndexOutput = Store.IndexOutput;
+
+ /// <summary>
+ /// Naive int block API that writes vInts. This is
+ /// expected to give poor performance; it's really only for
+ /// testing the pluggability. One should typically use pfor instead.
+ /// </summary>
+
+
+ // TODO: much of this can be shared code w/ the fixed case
/// <summary>
- /// Naive int block API that writes vInts. This is expected to give poor
- /// performance; it's really only for testing the pluggability. One
- /// should typically use pfor instead.
- ///
- /// TODO: much of this can be shared code w/ the fixed case
- ///
/// Abstract base class that writes variable-size blocks of ints
- /// to an IndexOutput. While this is a simple approach, a
- /// more performant approach would directly create an impl
- /// of IntIndexOutput inside Directory. Wrapping a generic
- /// IndexInput will likely cost performance.
+ /// to an IndexOutput. While this is a simple approach, a
+ /// more performant approach would directly create an impl
+ /// of IntIndexOutput inside Directory. Wrapping a generic
+ /// IndexInput will likely cost performance.
///
/// @lucene.experimental
/// </summary>
public abstract class VariableIntBlockIndexOutput : IntIndexOutput
{
- private readonly IndexOutput _output;
- private int _upto;
private bool _hitExcDuringWrite;
- /// <Remarks>
- /// TODO what Var-Var codecs exist in practice, and what are their blocksizes like?
- /// If it's less than 128 should we set that as max and use byte?
- ///
- /// NOTE: maxblockSize must be the maxium block size plus the max non-causal lookahed
- /// of your codec. EG Simple9 requires lookahead=1 becuase on seeing the Nth value it
- /// knows it must now encode the N-1 values before it
- /// </Remarks>
- protected VariableIntBlockIndexOutput(IndexOutput output, int maxBlockSize)
+ // TODO what Var-Var codecs exist in practice... and what are there blocksizes like?
+ // if its less than 128 we should set that as max and use byte?
+
+ /// <summary>
+ /// NOTE: maxBlockSize must be the maximum block size
+ /// plus the max non-causal lookahead of your codec. EG Simple9
+ /// requires lookahead=1 because on seeing the Nth value
+ /// it knows it must now encode the N-1 values before it.
+ /// </summary>
+ protected internal VariableIntBlockIndexOutput(IndexOutput output, int maxBlockSize)
{
- _output = output;
- _output.WriteInt(maxBlockSize);
+ OUTPUT = output;
+ output.WriteInt(maxBlockSize);
}
/// <summary>
- /// Called one value at a time. Return the number of
- /// buffered input values that have been written out
+ /// Called one value at a time. Return the number of
+ /// buffered input values that have been written to out.
/// </summary>
- protected abstract int Add(int value);
+ protected internal abstract int Add(int value);
public override IntIndexOutputIndex Index()
{
- return new VariableIntBlockIndexOutputIndex();
+ return new IntBlockIndexOuput(this);
}
public override void Write(int v)
@@ -93,59 +96,9 @@ namespace Lucene.Net.Codecs.Intblock
}
finally
{
- _output.Dispose();
+ OUTPUT.Dispose();
}
}
}
- internal class VariableIntBlockIndexOutputIndex : IntIndexOutputIndex
- {
- private long _fp;
- private int _upto;
- private long _lastFp;
- private int _lastUpto;
-
- public override void Mark()
- {
- _fp = output.FilePointer;
- _upto = VariableIntBlockIndexOutput.
- this._upto;
- }
-
- public override void CopyFrom(IntIndexOutputIndex other, bool copyLast)
- {
- var idx = (Index)other;
- _fp = idx.fp;
- _upto = idx.upto;
- if (!copyLast) return;
-
- _lastFp = _fp;
- _lastUpto = _upto;
- }
-
- public override void Write(DataOutput indexOut, bool absolute)
- {
- Debug.Assert(_upto >= 0);
- if (absolute)
- {
- indexOut.WriteVInt(_upto);
- indexOut.WriteVLong(_fp);
- }
- else if (_fp == _lastFp)
- {
- // same block
- Debug.Assert(_upto >= _lastUpto);
- var uptoDelta = _upto - _lastUpto;
- indexOut.WriteVInt(uptoDelta << 1 | 1);
- }
- else
- {
- // new block
- indexOut.WriteVInt(_upto << 1);
- indexOut.WriteVLong(_fp - _lastFp);
- }
- _lastUpto = _upto;
- _lastFp = _fp;
- }
- }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/df4afdc3/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 f9500ef..ee2ff66 100644
--- a/src/Lucene.Net.Codecs/Lucene.Net.Codecs.csproj
+++ b/src/Lucene.Net.Codecs/Lucene.Net.Codecs.csproj
@@ -65,8 +65,9 @@
<Compile Include="Intblock\FixedIntBlockIndexInput.cs" />
<Compile Include="Intblock\FixedIntBlockIndexOutput.cs" />
<Compile Include="Intblock\IBlockReader.cs" />
- <Compile Include="Intblock\Index.cs" />
- <Compile Include="Intblock\Reader.cs" />
+ <Compile Include="Intblock\IntBlockIndexInput.cs" />
+ <Compile Include="Intblock\IntBlockIndexOutput.cs" />
+ <Compile Include="Intblock\IntBlockIndexReader.cs" />
<Compile Include="Intblock\VariableIntBlockIndexInput.cs" />
<Compile Include="Intblock\VariableIntBlockIndexOutput.cs" />
<Compile Include="Memory\DirectDocValuesConsumer.cs" />
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/df4afdc3/src/Lucene.Net.Codecs/Sep/IntIndexOutput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Sep/IntIndexOutput.cs b/src/Lucene.Net.Codecs/Sep/IntIndexOutput.cs
index 901dbe1..e7c51e9 100644
--- a/src/Lucene.Net.Codecs/Sep/IntIndexOutput.cs
+++ b/src/Lucene.Net.Codecs/Sep/IntIndexOutput.cs
@@ -34,6 +34,8 @@ namespace Lucene.Net.Codecs.Sep
/// </remarks>
public abstract class IntIndexOutput : IDisposable
{
+ protected internal IndexOutput OUTPUT;
+ protected internal int _upto;
/// <summary>
/// Write an int to the primary file. The value must be