Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ebay/lexicaldecimal
A Lexicographical encoding of Java BigDecimals
https://github.com/ebay/lexicaldecimal
bigdecimal-utils java lexicographical
Last synced: about 1 month ago
JSON representation
A Lexicographical encoding of Java BigDecimals
- Host: GitHub
- URL: https://github.com/ebay/lexicaldecimal
- Owner: eBay
- License: apache-2.0
- Archived: true
- Created: 2019-12-20T20:28:12.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-01T02:32:39.000Z (over 3 years ago)
- Last Synced: 2024-09-28T23:05:23.191Z (about 2 months ago)
- Topics: bigdecimal-utils, java, lexicographical
- Language: Java
- Homepage:
- Size: 42 KB
- Stars: 9
- Watchers: 9
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Lexical Decimal
## Description
This library provides an implementation of a lexicographical encoding/decoding of BigDecimals. This allows you to store
BigDecimal values as byte arrays in a key value store, or other similar storage engines. The ordering of the encoded
value matches the ordering of the BigDecimal values.This uses the encoding described in the Decimal Infinite paper.
Fourny, Ghislain. (2015). [decimalInfinite: All Decimals In Bits, No Loss, Same Order, Simple.](https://www.researchgate.net/publication/278734280_decimalInfinite_All_Decimals_In_Bits_No_Loss_Same_Order_Simple)
## Usage1. Add a maven dependency.
```xml
com.ebay.data.encoding
lexical-decimal
1.0
```2. Encode a value
```java
BigDecimal val = new BigDecimal("1234.5678");
byte []encoded = BigDecimalEncoding.encode(val).toByteArray();
```3. Decode a previously encoded value
```java
byte []encoded ...
BigDecimal val = BigDecimalEncoding.decode(encoded);
```4. Accessing the encoded value
Encoding returns an instance of the Bits class that represents the encoded value. As above it can generate
a byte array. In addition it can also write the bits to an existing array or Stream.```java
OutputStream os = getOutputStream();
BigDecimal val = new BigDecimal("1234.5678");
BigDecimalEncoding.encode(val).writeTo(os);
```## See Also
* [decimalgamma-cpp](https://github.com/ghislainfourny/decimalgamma-cpp) Is a c++ implementation from the paper's Author.
* [decimalInfinite](https://github.com/ghislainfourny/decimalInfinite) a JSONiq implementation.## License
Copyright 2019 eBay Inc.
Author/Developer: Simon FellLicensed 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
https://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.