public IEnumerable <Triple> O(TripleObject o, Triple c) { if (c == null) { return(O(o)); } var oh = KeySegments.GetNameOKeyObject(_name, o); var startS = KeyConfig.ConcatBytes(oh, KeyConfig.ByteZero); var endS = KeyConfig.ConcatBytes(oh, KeyConfig.ByteOne); var(_, _, oKey) = new KeySegments(_name, c).GetKeys(); var continuation = KeyConfig.ConcatBytes(oKey, KeyConfig.ByteOne); if (KeyConfig.ByteCompare(continuation, startS) < 0) { throw new InvalidOperationException("Invalid continuation token. Before range"); } else if (KeyConfig.ByteCompare(continuation, endS) > 0) { return(Enumerable.Empty <Triple>()); } return(new RocksEnumerable(_db, continuation, endS, (Iterator it) => { return it.Next(); })); }
public IEnumerable <Triple> GetTriples() { var nameBytes = KeySegments.GetNameSKey(_name); var start = KeyConfig.ConcatBytes(nameBytes, KeyConfig.ByteZero); var end = KeyConfig.ConcatBytes(nameBytes, KeyConfig.ByteOne); return(new RocksEnumerable(_db, start, end, (Iterator it) => { return it.Next(); })); }
public IEnumerable <IGrouping <string, TripleObject> > GetSubjectGroupings(string s) { var sh = KeySegments.GetNameSKeySubject(_name, s); var startS = KeyConfig.ConcatBytes(sh, KeyConfig.ByteZero); var endS = KeyConfig.ConcatBytes(sh, KeyConfig.ByteOne); return(new RocksSubjectGrouping(_db, _name, s, startS, endS)); }
public IEnumerable <Triple> PO(string p, TripleObject o) { var ph = KeySegments.GetNamePKeyPredicateObject(_name, p, o); var startS = KeyConfig.ConcatBytes(ph, KeyConfig.ByteZero); var endS = KeyConfig.ConcatBytes(ph, KeyConfig.ByteOne); return(new RocksEnumerable(_db, startS, endS, (Iterator it) => { return it.Next(); })); }
public static byte[] GetNamePKeyPredicate(string name, string predicate) { var nameBytes = KeyConfig.GetBytes(name); var z = KeyConfig.ByteZero; var pBytes = KeyConfig.GetBytes(predicate); return(KeyConfig.ConcatBytes(nameBytes, KeyConfig.ByteP, z, pBytes)); }
public static byte[] GetNameSKeySubject(string name, string subject) { var nameBytes = KeyConfig.GetBytes(name); var z = KeyConfig.ByteZero; var sBytes = KeyConfig.GetBytes(subject); return(KeyConfig.ConcatBytes(nameBytes, KeyConfig.ByteS, z, sBytes)); }
public IEnumerable <Triple> SP(string s, string p) { var sh = KeySegments.GetNameSKeySubjectPredicate(_name, s, p); var startS = KeyConfig.ConcatBytes(sh, KeyConfig.ByteZero); var endS = KeyConfig.ConcatBytes(sh, KeyConfig.ByteOne); return(new RocksEnumerable(_db, startS, endS, (Iterator it) => { return it.Next(); })); }
public IEnumerable <Triple> OS(TripleObject o, string s) { var oh = KeySegments.GetNameOKeyObjectSubject(_name, o, s); var startS = KeyConfig.ConcatBytes(oh, KeyConfig.ByteZero); var endS = KeyConfig.ConcatBytes(oh, KeyConfig.ByteOne); return(new RocksEnumerable(_db, startS, endS, (Iterator it) => { return it.Next(); })); }
public static byte[] GetNameOKeyObject(string name, TripleObject o) { var nameBytes = KeyConfig.GetBytes(name); var z = KeyConfig.ByteZero; var oBytes = KeyConfig.GetBytes(o.ToValue()); var isIdBytes = o.IsID ? KeyConfig.ByteTrue : KeyConfig.ByteFalse; return(KeyConfig.ConcatBytes(nameBytes, KeyConfig.ByteO, z, isIdBytes, z, oBytes)); }
public static byte[] ToBytes(this TripleObject o) { var oBytes = KeyConfig.GetBytes(o.ToValue()); var isIdBytes = o.IsID ? KeyConfig.ByteTrue : KeyConfig.ByteFalse; var typeBytes = KeyConfig.GetBytes((int)o.TokenType); // index is not converted return(KeyConfig.ConcatBytes(isIdBytes, typeBytes, oBytes)); }
public static byte[] GetNameSKeySubjectPredicateIndex(string name, string subject, string predicate, int index) { var nameBytes = KeyConfig.GetBytes(name); var z = KeyConfig.ByteZero; var sBytes = KeyConfig.GetBytes(subject); var pBytes = KeyConfig.GetBytes(predicate); var indexBytes = BitConverter.GetBytes(index); return(KeyConfig.ConcatBytes(nameBytes, KeyConfig.ByteS, z, sBytes, z, pBytes, z, indexBytes)); }
public bool Exists(string s, string p, TripleObject o) { var keySegments = new KeySegments(_name, s, p, o); var oPrefix = keySegments.GetOPrefix(); var start = KeyConfig.ConcatBytes(oPrefix, KeyConfig.ByteZero); var end = KeyConfig.ConcatBytes(oPrefix, KeyConfig.ByteOne); var oEnumerable = new RocksEnumerable(_db, start, end, (it) => it.Next()); return(oEnumerable.Any()); }
public (byte[], byte[], byte[]) GetKeys() { if (_sKey == null) { var z = KeyConfig.ByteZero; _sKey = KeyConfig.ConcatBytes(_name, KeyConfig.ByteS, z, S, z, P, z, Index, z, IsId, z, O); _pKey = KeyConfig.ConcatBytes(_name, KeyConfig.ByteP, z, P, z, IsId, z, O, z, Index, z, S); _oKey = KeyConfig.ConcatBytes(_name, KeyConfig.ByteO, z, IsId, z, O, z, S, z, P, z, Index); } return(_sKey, _pKey, _oKey); }
public IEnumerable <string> P() { var pPrefix = KeySegments.GetNamePPredicate(Name); var startP = KeyConfig.ConcatBytes(pPrefix, KeyConfig.ByteZero); var endP = KeyConfig.ConcatBytes(pPrefix, KeyConfig.ByteOne); var predicates = new RocksEnumerable(_db, startP, endP, (it) => { var key = it.Key(); var splits = KeyConfig.Split(key); var nextKey = KeyConfig.ConcatBytes(splits[0], KeyConfig.ByteZero, splits[1], KeyConfig.ByteOne); return(it.Seek(nextKey)); }).Select(x => x.Predicate); return(predicates); }
IEnumerator <IGrouping <string, TripleObject> > IEnumerable <IGrouping <string, TripleObject> > .GetEnumerator() { var predicates = new RocksEnumerable(_db, _start, _end, (it) => { var key = it.Key(); var splits = KeyConfig.Split(key); var nextKey = KeyConfig.ConcatBytes(splits[0], KeyConfig.ByteZero, splits[1], KeyConfig.ByteZero, splits[2], KeyConfig.ByteOne); return(it.Seek(nextKey)); }).Select(x => x.Predicate); foreach (var p in predicates) { yield return(new RocksPredicateGrouping(_db, _name, _s, p)); } }
public IEnumerator <TripleObject> GetEnumerator() { var sBytes = Hash($"{_name}.S"); var sh = Hash(_s); var ph = Hash(_p); var start = KeyConfig.ConcatBytes(sBytes, KeyConfig.ByteZero, sh, KeyConfig.ByteZero, ph, KeyConfig.ByteZero); var end = KeyConfig.ConcatBytes(sBytes, KeyConfig.ByteZero, sh, KeyConfig.ByteZero, ph, KeyConfig.ByteOne); var baseKey = $"{_name}.S.{Hash(_s)}.{Hash(_p)}"; IEnumerable <Triple> idEnum = new RocksEnumerable(_db, start, end, (iterator) => { return(iterator.Next()); }); foreach (var item in idEnum) { yield return(item.Object); } }
public IEnumerable <IGrouping <string, IGrouping <string, TripleObject> > > GetGroupings() { var nameBytes = KeySegments.GetNameSKey(Name); var start = KeyConfig.ConcatBytes(nameBytes, KeyConfig.ByteZero); var end = KeyConfig.ConcatBytes(nameBytes, KeyConfig.ByteOne); var subjects = new RocksEnumerable(_db, start, end, (it) => { var key = it.Key(); var splits = KeyConfig.Split(key); var nextKey = KeyConfig.ConcatBytes(splits[0], KeyConfig.ByteZero, splits[1], KeyConfig.ByteOne); return(it.Seek(nextKey)); }).Select(x => x.Subject); foreach (var s in subjects) { var sh = KeySegments.GetNameSKeySubject(Name, s); var startS = KeyConfig.ConcatBytes(sh, KeyConfig.ByteZero); var endS = KeyConfig.ConcatBytes(sh, KeyConfig.ByteOne); yield return(new RocksSubjectGrouping(_db, Name, s, startS, endS)); } }
public IEnumerable <Triple> SP(string s, string p, Triple c) { var sh = KeySegments.GetNameSKeySubjectPredicate(_name, s, p); var startS = KeyConfig.ConcatBytes(sh, KeyConfig.ByteZero); var endS = KeyConfig.ConcatBytes(sh, KeyConfig.ByteOne); // todo: optimize var(sKey, _, _) = new KeySegments(_name, c).GetKeys(); var continuation = KeyConfig.ConcatBytes(sKey, KeyConfig.ByteOne); if (KeyConfig.ByteCompare(continuation, startS) < 0) { throw new InvalidOperationException("Invalid continuation token. Before range"); } else if (KeyConfig.ByteCompare(continuation, endS) > 0) { return(Enumerable.Empty <Triple>()); } return(new RocksEnumerable(_db, continuation, endS, (Iterator it) => { return it.Next(); })); }
public IEnumerable <Triple> P(string p, Triple c) { if (c == null) { return(P(p)); } var ph = KeySegments.GetNamePKeyPredicate(_name, p); var startS = KeyConfig.ConcatBytes(ph, KeyConfig.ByteZero); var endS = KeyConfig.ConcatBytes(ph, KeyConfig.ByteOne); var(_, pKey, _) = new KeySegments(_name, c).GetKeys(); var continuation = KeyConfig.ConcatBytes(pKey, KeyConfig.ByteOne); if (KeyConfig.ByteCompare(continuation, startS) < 0) { throw new InvalidOperationException("Invalid continuation token. Before range"); } else if (KeyConfig.ByteCompare(continuation, endS) > 0) { return(Enumerable.Empty <Triple>()); } return(new RocksEnumerable(_db, continuation, endS, (Iterator it) => { return it.Next(); })); }
public static byte[] GetNameSKey(string name) { return(KeyConfig.ConcatBytes(KeyConfig.GetBytes(name), KeyConfig.ByteS)); }
public byte[] GetOPrefix() { var z = KeyConfig.ByteZero; return(KeyConfig.ConcatBytes(_name, KeyConfig.ByteO, z, IsId, z, O, z, S, z, P)); }
public static byte[] GetNamePPredicate(string name) { var nameBytes = KeyConfig.GetBytes(name); return(KeyConfig.ConcatBytes(nameBytes, KeyConfig.ByteP)); }