Skip to content

Instantly share code, notes, and snippets.

@krisskross
Created January 12, 2015 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisskross/85d2d398f5b89976e8cf to your computer and use it in GitHub Desktop.
Save krisskross/85d2d398f5b89976e8cf to your computer and use it in GitHub Desktop.
lmdbjni exmaple
public class Tests {
static Path dir = Paths.get("/tmp/test");
static Database test;
static Env env;
static {
try {
FileUtils.deleteIfExist(dir);
Files.createDirectory(dir);
} catch (IOException e) {
e.printStackTrace();
}
env = new Env();
env.open(dir.toFile().getAbsolutePath());
env.setMapSize(4294967296L);
test = env.openDatabase("test");
}
public static void main(String[] args) {
Transaction tx = env.createTransaction();
for (int i = 0; i < 10000000; i++) {
if (i % 10000 == 0) {
tx.commit();
tx = env.createTransaction();
System.out.println(i);
}
test.put(tx, fromLong(i), new byte[] {3, 2, 1});
}
}
public static byte[] fromLong(final long n) {
final byte[] b = new byte[8];
setLong(b, n);
return b;
}
private static void setLong(final byte[] b, final long n) {
setLong(b, n, 0);
}
private static void setLong(final byte[] b, final long n, final int offset) {
b[offset + 0] = (byte) (n >>> 56);
b[offset + 1] = (byte) (n >>> 48);
b[offset + 2] = (byte) (n >>> 40);
b[offset + 3] = (byte) (n >>> 32);
b[offset + 4] = (byte) (n >>> 24);
b[offset + 5] = (byte) (n >>> 16);
b[offset + 6] = (byte) (n >>> 8);
b[offset + 7] = (byte) (n >>> 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment