Created
January 21, 2020 02:00
-
-
Save micahscopes/c705dc5f478adb229c8aae5eea3b992c to your computer and use it in GitHub Desktop.
Rewind hypertrie
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
const ram = require("random-access-memory"); | |
const hypertrie = require("hypertrie"); | |
const db = hypertrie(ram); | |
let xItems = ["little", "bits", "of", "info"].map( | |
item => ({ | |
type: "put", | |
key: "/x", | |
value: item | |
}) | |
); | |
let yItems = ["1", "2", "3", "4"].map(item => ({ | |
type: "put", | |
key: "/x/y", | |
value: item | |
})); | |
db.batch(xItems.concat(yItems), function() { | |
let history = db.history({ reverse: true }); | |
for (let i = db.version; i--; i > 1) { | |
history.next((_, obj) => { | |
if (obj && obj.key === "x") { | |
console.log( | |
obj.seq, | |
obj.key, | |
obj.value.toString(), | |
obj.hash.toString("hex") | |
); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment