https://github.com/codahale/longmapper
A bijective mapping for 64-bit integers.
https://github.com/codahale/longmapper
Last synced: 2 months ago
JSON representation
A bijective mapping for 64-bit integers.
- Host: GitHub
- URL: https://github.com/codahale/longmapper
- Owner: codahale
- License: apache-2.0
- Archived: true
- Created: 2018-01-09T06:04:53.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-03-31T03:39:33.000Z (almost 7 years ago)
- Last Synced: 2025-08-04T14:17:43.542Z (8 months ago)
- Language: Java
- Size: 51.8 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# LongMapper
[](https://circleci.com/gh/codahale/longmapper)
## Add to your project
```xml
com.codahale
longmapper
0.1.1
```
*Note: module name for Java 9+ is `com.codahale.longmapper`.*
## Use the thing
```java
import static java.nio.charset.StandardCharsets.UTF_8;
import com.codahale.longmapper.LongMapper;
class Example {
public static void main(String... args) {
final LongMapper mapper = new LongMapper("ayellowsubmarine".getBytes(UTF_8));
System.out.printf("Mapped %d to %d\n", 200, mapper.map(200));
System.out.printf("Unmapped %d to %d\n", mapper.map(200), mapper.unmap(mapper.map(200)));
}
}
```
## How it works
It encrypts each `long` as a 64-bit [Blowfish](https://en.wikipedia.org/wiki/Blowfish_(cipher))
block.
## Performance
It's fast. Plenty fast.
```
Benchmark Mode Cnt Score Error Units
Benchmarks.map avgt 20 102.132 ± 8.190 ns/op
Benchmarks.unmap avgt 20 115.311 ± 1.092 ns/op
```
## License
Copyright © 2018 Coda Hale
Distributed under the Apache License 2.0.