Created
January 12, 2015 18:34
-
-
Save krisskross/85d2d398f5b89976e8cf to your computer and use it in GitHub Desktop.
lmdbjni exmaple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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