You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2012/04/25 21:36:42 UTC

svn commit: r1330511 - in /lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store: DataInput.java DataOutput.java

Author: rmuir
Date: Wed Apr 25 19:36:41 2012
New Revision: 1330511

URL: http://svn.apache.org/viewvc?rev=1330511&view=rev
Log:
LUCENE-2946: put vint table from fileformats in writeVInt

Modified:
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/DataInput.java
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/DataOutput.java

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/DataInput.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/DataInput.java?rev=1330511&r1=1330510&r2=1330511&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/DataInput.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/DataInput.java Wed Apr 25 19:36:41 2012
@@ -79,6 +79,9 @@ public abstract class DataInput implemen
   /** Reads an int stored in variable-length format.  Reads between one and
    * five bytes.  Smaller values take fewer bytes.  Negative numbers are not
    * supported.
+   * <p>
+   * The format is described further in {@link DataOutput#writeVInt(int)}.
+   * 
    * @see DataOutput#writeVInt(int)
    */
   public int readVInt() throws IOException {
@@ -121,7 +124,12 @@ public abstract class DataInput implemen
 
   /** Reads a long stored in variable-length format.  Reads between one and
    * nine bytes.  Smaller values take fewer bytes.  Negative numbers are not
-   * supported. */
+   * supported.
+   * <p>
+   * The format is described further in {@link DataOutput#writeVInt(int)}.
+   * 
+   * @see DataOutput#writeVLong(long)
+   */
   public long readVLong() throws IOException {
     /* This is the original code of this method,
      * but a Hotspot bug (see LUCENE-2975) corrupts the for-loop if

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/DataOutput.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/DataOutput.java?rev=1330511&r1=1330510&r2=1330511&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/DataOutput.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/DataOutput.java Wed Apr 25 19:36:41 2012
@@ -72,6 +72,107 @@ public abstract class DataOutput {
   /** Writes an int in a variable-length format.  Writes between one and
    * five bytes.  Smaller values take fewer bytes.  Negative numbers are
    * supported, but should be avoided.
+   * <p>VByte is a variable-length format for positive integers is defined where the
+   * high-order bit of each byte indicates whether more bytes remain to be read. The
+   * low-order seven bits are appended as increasingly more significant bits in the
+   * resulting integer value. Thus values from zero to 127 may be stored in a single
+   * byte, values from 128 to 16,383 may be stored in two bytes, and so on.</p>
+   * <p>VByte Encoding Example</p>
+   * <table cellspacing="0" cellpadding="2" border="0">
+   * <col width="64*">
+   * <col width="64*">
+   * <col width="64*">
+   * <col width="64*">
+   * <tr valign="top">
+   *   <th align="left" width="25%">Value</th>
+   *   <th align="left" width="25%">Byte 1</th>
+   *   <th align="left" width="25%">Byte 2</th>
+   *   <th align="left" width="25%">Byte 3</th>
+   * </tr>
+   * <tr valign="bottom">
+   *   <td width="25%">0</td>
+   *   <td width="25%"><kbd>00000000</kbd></td>
+   *   <td width="25%"></td>
+   *   <td width="25%"></td>
+   * </tr>
+   * <tr valign="bottom">
+   *   <td width="25%">1</td>
+   *   <td width="25%"><kbd>00000001</kbd></td>
+   *   <td width="25%"></td>
+   *   <td width="25%"></td>
+   * </tr>
+   * <tr valign="bottom">
+   *   <td width="25%">2</td>
+   *   <td width="25%"><kbd>00000010</kbd></td>
+   *   <td width="25%"></td>
+   *   <td width="25%"></td>
+   * </tr>
+   * <tr>
+   *   <td valign="top" width="25%">...</td>
+   *   <td valign="bottom" width="25%"></td>
+   *   <td valign="bottom" width="25%"></td>
+   *   <td valign="bottom" width="25%"></td>
+   * </tr>
+   * <tr valign="bottom">
+   *   <td width="25%">127</td>
+   *   <td width="25%"><kbd>01111111</kbd></td>
+   *   <td width="25%"></td>
+   *   <td width="25%"></td>
+   * </tr>
+   * <tr valign="bottom">
+   *   <td width="25%">128</td>
+   *   <td width="25%"><kbd>10000000</kbd></td>
+   *   <td width="25%"><kbd>00000001</kbd></td>
+   *   <td width="25%"></td>
+   * </tr>
+   * <tr valign="bottom">
+   *   <td width="25%">129</td>
+   *   <td width="25%"><kbd>10000001</kbd></td>
+   *   <td width="25%"><kbd>00000001</kbd></td>
+   *   <td width="25%"></td>
+   * </tr>
+   * <tr valign="bottom">
+   *   <td width="25%">130</td>
+   *   <td width="25%"><kbd>10000010</kbd></td>
+   *   <td width="25%"><kbd>00000001</kbd></td>
+   *   <td width="25%"></td>
+   * </tr>
+   * <tr>
+   *   <td valign="top" width="25%">...</td>
+   *   <td width="25%"></td>
+   *   <td width="25%"></td>
+   *   <td width="25%"></td>
+   * </tr>
+   * <tr valign="bottom">
+   *   <td width="25%">16,383</td>
+   *   <td width="25%"><kbd>11111111</kbd></td>
+   *   <td width="25%"><kbd>01111111</kbd></td>
+   *   <td width="25%"></td>
+   * </tr>
+   * <tr valign="bottom">
+   *   <td width="25%">16,384</td>
+   *   <td width="25%"><kbd>10000000</kbd></td>
+   *   <td width="25%"><kbd>10000000</kbd></td>
+   *   <td width="25%"><kbd>00000001</kbd></td>
+   * </tr>
+   * <tr valign="bottom">
+   *   <td width="25%">16,385</td>
+   *   <td width="25%"><kbd>10000001</kbd></td>
+   *   <td width="25%"><kbd>10000000</kbd></td>
+   *   <td width="25%"><kbd>00000001</kbd></td>
+   * </tr>
+   * <tr>
+   *   <td valign="top" width="25%">...</td>
+   *   <td valign="bottom" width="25%"></td>
+   *   <td valign="bottom" width="25%"></td>
+   *   <td valign="bottom" width="25%"></td>
+   * </tr>
+   * </table>
+   * <p>This provides compression while still being efficient to decode.</p>
+   * 
+   * @param i Smaller values take fewer bytes.  Negative numbers are
+   * supported, but should be avoided.
+   * @throws IOException If there is an I/O error writing to the underlying medium.
    * @see DataInput#readVInt()
    */
   public final void writeVInt(int i) throws IOException {
@@ -93,6 +194,8 @@ public abstract class DataOutput {
   /** Writes an long in a variable-length format.  Writes between one and nine
    * bytes.  Smaller values take fewer bytes.  Negative numbers are not
    * supported.
+   * <p>
+   * The format is described further in {@link DataOutput#writeVInt(int)}.
    * @see DataInput#readVLong()
    */
   public final void writeVLong(long i) throws IOException {