static void Main(string[] args) { Console.WriteLine("meebey LevelDB test."); var op = new LevelDB.Options() { CreateIfMissing = true, Compression = LevelDB.CompressionType.SnappyCompression }; // Neo.IO.Data.LevelDB.Options() { CreateIfMissing = true, Compression = Neo.IO.Data.LevelDB.CompressionType.kSnappyCompression }; var db = LevelDB.DB.Open(op, "c:/newdb_neo"); //var db2 = Neo.IO.Data.LevelDB.DB.Open("c:/newdb_neo2", op); int count = 0; Random r = new Random(); DateTime timeBegin = DateTime.Now; var wop = new LevelDB.WriteOptions(); for (var i = 0; i < 1000000; i++) { byte[] testkey = System.Text.Encoding.UTF8.GetBytes("testkey" + count); byte[] testv = new byte[1024]; r.NextBytes(testv); db.Put(wop, testkey, testv); if (i % 10000 == 0) { Console.WriteLine("had put " + (i + 1)); } } DateTime timeEnd = DateTime.Now; var totalseconds = (timeEnd - timeBegin).TotalSeconds; var speed = 1000000.0 / totalseconds; Console.WriteLine("put speed=" + speed + " per second"); }
public static LevelDB.DB OpenDB(string path) { var op = new LevelDB.Options() { CreateIfMissing = true, Compression = LevelDB.CompressionType.SnappyCompression }; return(LevelDB.DB.Open(op, path)); }
private LevelDB.DB <string, string> GetTestDb([CallerMemberName] string name = null) { LevelDB.Options options = new LevelDB.Options(); options.CreateIfMissing = true; var db = new LevelDB.DB(options, $"/tmp/DBTests-{name}").Cast <string, string>(); db.Put("c", "3").Put("b", "2").Put("a", "1"); db.Put("l", "12").Put("m", "13").Put("n", "14"); db.Put("z", "26").Put("y", "25").Put("x", "24"); return(db); }
public static LevelDB.DB OpenLevelDB(string path) { if (path == null) { throw new ArgumentNullException("path"); } string dependenciesPath = path; LevelDB.Options opts = new LevelDB.Options(); opts.CreateIfMissing = true; return(new LevelDB.DB(opts, dependenciesPath, System.Text.Encoding.Unicode)); }
public void Integers() { using var log = Log(); LevelDB.Options options = new LevelDB.Options(); options.CreateIfMissing = true; using LevelDB.DB <int, string> db = new LevelDB.DB(options, $"/tmp/DBTests-Integers").Cast <int, string>(); db.Put(1, "aaa").Put(2, "bbb").Put(3, "ccc"); db.Put(7, "ggg").Put(8, "hhh").Put(9, "iii"); db.Put(6, "fff").Put(5, "eee").Put(4, "ddd"); Assert.Equal( "4=ddd;5=eee;6=fff;7=ggg", string.Join(";", db.GetIterable().Range(4, 8).Select(kv => $"{kv.Key}={kv.Value}"))); }
public void Join() { using var log = Log(); LevelDB.Options options = new LevelDB.Options(); options.CreateIfMissing = true; using LevelDB.DB db = new LevelDB.DB(options, $"/tmp/DBTests-Join"); var parents = db.Cast <Parent, string>(); var children = db.Cast <Child, string>(); parents.Put(new Parent(1), "aaa"); parents.Put(new Parent(2), "bbb"); children.Put(new Child(1, 11), "afirst"); children.Put(new Child(1, 12), "asecond"); children.Put(new Child(2, 21), "afirst"); children.Put(new Child(2, 22), "asecond"); { var join = from parent in parents.GetIterable().Range(new Parent(1), new Parent(3)) join child in children.GetIterable().Range(new Child(1, 1), new Child(3, 1)) on parent.Key.parentId equals child.Key.parentId select $"[{parent.Value} => {child.Key.parentId}:{child.Key.childId}:{child.Value}]"; Assert.Equal( "[aaa => 1:11:afirst]; [aaa => 1:12:asecond]; [bbb => 2:21:afirst]; [bbb => 2:22:asecond]", string.Join("; ", join)); } { IEnumerable <KeyValuePair <Tuple <Parent, Child>, Tuple <string, string> > > streamJoin = parents.GetIterable().Range(new Parent(1), new Parent(3)) .Join( children.GetIterable().Range(new Child(1, 1), new Child(3, 1)), (k1, k2) => k1.parentId.CompareTo(k2.parentId)); Assert.Equal( "1/11 => aaa/afirst; 1/12 => aaa/asecond; 2/21 => bbb/afirst; 2/22 => bbb/asecond", string.Join("; ", streamJoin.Select(row => $"{row.Key.Item1.parentId}/{row.Key.Item2.childId} => {row.Value.Item1}/{row.Value.Item2}"))); } { IMergeJoinIterable <Parent, Child, string, string> streamJoin = Tuple.Create( parents.GetIterable().Range(new Parent(1), new Parent(3)), children.GetIterable().Range(new Child(1, 1), new Child(3, 1))) .Join2(sizeof(int), sizeof(int)); Assert.Equal( "1/11 => aaa/afirst; 1/12 => aaa/asecond; 2/21 => bbb/afirst; 2/22 => bbb/asecond", string.Join("; ", streamJoin.Select(row => $"{row.Key.Left.parentId}/{row.Key.Right.childId} => {row.Value.Left}/{row.Value.Right}"))); } }
public void Prefix() { using var log = Log(); LevelDB.Options options = new LevelDB.Options(); options.CreateIfMissing = true; using var db = new LevelDB.DB(options, $"/tmp/DBTests-Prefix").Cast <string, int>(); db .Put("a", 1) .Put("aa", 2) .Put("ab", 3) .Put("b", 4) .Put("ba", 5) .Put("bb", 6) .Put("c", 7); Assert.Equal( "a=1;aa=2;ab=3", string.Join(";", db.GetIterable().Prefix("a").Select(kv => $"{kv.Key}={kv.Value}"))); Assert.Equal( "b=4;ab=3;aa=2", string.Join(";", db.GetIterable().Reverse().Prefix("a").Select(kv => $"{kv.Key}={kv.Value}"))); Assert.Equal( "b=4;ab=3;aa=2", string.Join(";", db.GetIterable().Prefix("a").Reverse().Select(kv => $"{kv.Key}={kv.Value}"))); }