Skip to content
This repository has been archived by the owner on Jul 25, 2019. It is now read-only.

codahale/longmapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LongMapper

CircleCI

Add to your project

<dependency>
  <groupId>com.codahale</groupId>
  <artifactId>longmapper</artifactId>
  <version>0.1.1</version>
</dependency>

Note: module name for Java 9+ is com.codahale.longmapper.

Use the thing

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 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.

About

A bijective mapping for 64-bit integers.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages