public List <byte[]> GetLatestValues(ISnapshot head, long limit) { List <byte[]> result = new List <byte[]>(); lock (lock_db) { if (limit <= 0) { return(result); } long temp = limit; ISnapshot snapshot = this.head; for (; temp > 0 && snapshot.GetPrevious() != null; snapshot = snapshot.GetPrevious()) { if (!((Snapshot)(snapshot)).DB.IsEmpty) { --temp; result.AddRange(((Snapshot)(snapshot)).DB.Select(data => data.Value.Data).ToList()); } } if (snapshot.GetPrevious() == null && temp != 0) { foreach (var value in (((Common.LevelDB)((SnapshotRoot)snapshot).DB)).DB.GetLatestValues(temp)) { result.Add(value); } } } return(result); }
public List <byte[]> GetValuesNext(ISnapshot snapshot, byte[] key, long limit) { List <byte[]> result = new List <byte[]>(); if (limit <= 0) { return(result); } Dictionary <WrappedByteArray, WrappedByteArray> collection = new Dictionary <WrappedByteArray, WrappedByteArray>(new WrapperdByteArrayEqualComparer()); if (snapshot.GetPrevious() != null) { ((Snapshot)(snapshot)).Collect(collection); } Dictionary <byte[], byte[]> db_dictonary = new Dictionary <byte[], byte[]>((((Common.LevelDB)((SnapshotRoot)snapshot.GetRoot()).DB).DB.GetNext(key, limit))); foreach (KeyValuePair <WrappedByteArray, WrappedByteArray> pair in collection) { db_dictonary.Add(pair.Key.Data, pair.Value.Data); } return(db_dictonary .OrderBy(x => x.Key, new UnsignedByteArrayCompare()) .Where(y => ByteUtil.Compare(y.Key, key) >= 0) .Take((int)limit) .Select(z => z.Value) .ToList()); }
public byte[] Get(ISnapshot head, byte[] key) { ISnapshot snapshot = head; Value result = null; while (IsImplement(snapshot)) { result = ((Snapshot)(snapshot)).db.Get(Key.Of(key)); if (result != null) { return(result.Data); } snapshot = snapshot.GetPrevious(); } return(snapshot?.Get(key)); }