You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Aaron Cohen <aa...@me.com.INVALID> on 2021/09/03 14:34:35 UTC

Question about readVint & writeVint from DataOutput and DataInput

While reading the Lucene JavaDoc I came across writeVInt <https://lucene.apache.org/core/8_9_0/core/org/apache/lucene/store/DataOutput.html#writeVInt-int-> & readVInt <https://lucene.apache.org/core/8_9_0/core/org/apache/lucene/store/DataInput.html#readVInt--> from DataOutput and DataInput base classes. It says for writeVint

Parameters:
i - Smaller values take fewer bytes. Negative numbers are supported, but should be avoided.

And for readVint "Negative numbers are supported, but should be avoided.”

This seems like an odd statement. Why would something be supported but should be avoided? Should I submit a PR to prevent negative integers?

Re: Question about readVint & writeVint from DataOutput and DataInput

Posted by Aaron Cohen <aa...@me.com.INVALID>.
Thank you for the clarification.

> On Sep 3, 2021, at 10:46 AM, Uwe Schindler <uw...@thetaphi.de> wrote:
> 
> They are fully supported, so you can write and read them.
> 
> The problem with negative numbers is that they need lot of (disk) space, because in two's complement they have almost all bits set. The largest number is kinds of disk space is -1.
> 
> Negative numbers appear in older index formats, so they can't be prevented by a pull request as suggested.
> 
> Just take the comment as given: all is supported, but if you want to store negative numbers use a different encoding, e.g. zigzag.
> 
> Uwe
> 
> Am 3. September 2021 14:34:35 UTC schrieb Aaron Cohen <aa...@me.com.INVALID>:
>> While reading the Lucene JavaDoc I came across writeVInt <https://lucene.apache.org/core/8_9_0/core/org/apache/lucene/store/DataOutput.html#writeVInt-int-> & readVInt <https://lucene.apache.org/core/8_9_0/core/org/apache/lucene/store/DataInput.html#readVInt--> from DataOutput and DataInput base classes. It says for writeVint
>> 
>> Parameters:
>> i - Smaller values take fewer bytes. Negative numbers are supported, but should be avoided.
>> 
>> And for readVint "Negative numbers are supported, but should be avoided.”
>> 
>> This seems like an odd statement. Why would something be supported but should be avoided? Should I submit a PR to prevent negative integers?
> --
> Uwe Schindler
> Achterdiek 19, 28357 Bremen
> https://www.thetaphi.de


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Question about readVint & writeVint from DataOutput and DataInput

Posted by Uwe Schindler <uw...@thetaphi.de>.
They are fully supported, so you can write and read them.

The problem with negative numbers is that they need lot of (disk) space, because in two's complement they have almost all bits set. The largest number is kinds of disk space is -1.

Negative numbers appear in older index formats, so they can't be prevented by a pull request as suggested.

Just take the comment as given: all is supported, but if you want to store negative numbers use a different encoding, e.g. zigzag.

Uwe

Am 3. September 2021 14:34:35 UTC schrieb Aaron Cohen <aa...@me.com.INVALID>:
>While reading the Lucene JavaDoc I came across writeVInt <https://lucene.apache.org/core/8_9_0/core/org/apache/lucene/store/DataOutput.html#writeVInt-int-> & readVInt <https://lucene.apache.org/core/8_9_0/core/org/apache/lucene/store/DataInput.html#readVInt--> from DataOutput and DataInput base classes. It says for writeVint
>
>Parameters:
>i - Smaller values take fewer bytes. Negative numbers are supported, but should be avoided.
>
>And for readVint "Negative numbers are supported, but should be avoided.”
>
>This seems like an odd statement. Why would something be supported but should be avoided? Should I submit a PR to prevent negative integers?
--
Uwe Schindler
Achterdiek 19, 28357 Bremen
https://www.thetaphi.de