public MappingPair(INode x, INode y, TripleIndexType type) { this._x = x; this._y = y; this._type = type; this._hash = Tools.CombineHashCodes(x, y); }
/// <summary> /// Creates a new Tree Indexed triple collection with the given Indexing options /// </summary> /// <param name="subjIndex">Whether to create a subject index</param> /// <param name="predIndex">Whether to create a predicate index</param> /// <param name="objIndex">Whether to create an object index</param> /// <param name="subjPredIndex">Whether to create a subject predicate index</param> /// <param name="subjObjIndex">Whether to create a subject object index</param> /// <param name="predObjIndex">Whether to create a predicate object index</param> /// <param name="compoundIndexMode">Mode to use for compound indexes</param> public TreeIndexedTripleCollection(bool subjIndex, bool predIndex, bool objIndex, bool subjPredIndex, bool subjObjIndex, bool predObjIndex, MultiDictionaryMode compoundIndexMode) { if (subjIndex) { _s = new MultiDictionary <INode, List <Triple> >(new FastVirtualNodeComparer(), MultiDictionaryMode.AVL); } if (predIndex) { _p = new MultiDictionary <INode, List <Triple> >(new FastVirtualNodeComparer(), MultiDictionaryMode.AVL); } if (objIndex) { _o = new MultiDictionary <INode, List <Triple> >(new FastVirtualNodeComparer(), MultiDictionaryMode.AVL); } if (subjPredIndex) { _sp = new MultiDictionary <Triple, List <Triple> >(t => Tools.CombineHashCodes(t.Subject, t.Predicate), false, new SubjectPredicateComparer(new FastVirtualNodeComparer()), compoundIndexMode); } if (subjObjIndex) { _so = new MultiDictionary <Triple, List <Triple> >(t => Tools.CombineHashCodes(t.Subject, t.Object), false, new SubjectObjectComparer(new FastVirtualNodeComparer()), compoundIndexMode); } if (predObjIndex) { _po = new MultiDictionary <Triple, List <Triple> >(t => Tools.CombineHashCodes(t.Predicate, t.Object), false, new PredicateObjectComparer(new FastVirtualNodeComparer()), compoundIndexMode); } }
/// <summary> /// Internal method for unindexing Triples as they are retracted /// </summary> /// <param name="t">Triple to unindex</param> private void UnIndex(Triple t) { this._subjIndex.Remove(t.Subject, t); this._predIndex.Remove(t.Predicate, t); this._objIndex.Remove(t.Object, t); if (this._fullyIndexed) { this._subjPredIndex.Remove(Tools.CombineHashCodes(t.Subject, t.Predicate), t); this._predObjIndex.Remove(Tools.CombineHashCodes(t.Predicate, t.Object), t); this._subjObjIndex.Remove(Tools.CombineHashCodes(t.Subject, t.Object), t); } }
/// <summary> /// Internal method for indexing Triples as they are asserted /// </summary> /// <param name="t">Triple to index</param> private void Index(Triple t) { this._subjIndex.Add(t.Subject, t); this._predIndex.Add(t.Predicate, t); this._objIndex.Add(t.Object, t); //Build full indexes only if enabled if (this._fullyIndexed) { this._subjPredIndex.Add(Tools.CombineHashCodes(t.Subject, t.Predicate), t); this._predObjIndex.Add(Tools.CombineHashCodes(t.Predicate, t.Object), t); this._subjObjIndex.Add(Tools.CombineHashCodes(t.Subject, t.Object), t); } }
/// <summary> /// Gets all the Triples with a given Subject and Object /// </summary> /// <param name="subj"></param> /// <param name="obj"></param> /// <returns></returns> public override IEnumerable <Triple> WithSubjectObject(INode subj, INode obj) { if (this._fullyIndexed) { int key = Tools.CombineHashCodes(subj, obj); if (this._subjObjIndex.ContainsKey(key)) { return(this._subjObjIndex.GetValues(key)); } else { return(Enumerable.Empty <Triple>()); } } else { return(base.WithSubjectObject(subj, obj)); } }
/// <summary> /// Internal method for indexing Triples as they are asserted /// </summary> /// <param name="t">Triple to index</param> private void Index(Triple t) { //As we are lazy indexing we only add to indexes if a relevant index //already exists if (this._subjIndex.ContainsKey(t.Subject)) { this._subjIndex.Add(t.Subject, t); } if (this._predIndex.ContainsKey(t.Predicate)) { this._predIndex.Add(t.Predicate, t); } if (this._objIndex.ContainsKey(t.Object)) { this._objIndex.Add(t.Object, t); } //Build full indexes only if enabled if (this._fullyIndexed) { int sp = Tools.CombineHashCodes(t.Subject, t.Predicate); if (this._subjPredIndex.ContainsKey(sp)) { this._subjPredIndex.Add(sp, t); } int po = Tools.CombineHashCodes(t.Predicate, t.Object); if (this._predObjIndex.ContainsKey(po)) { this._predObjIndex.Add(po, t); } int so = Tools.CombineHashCodes(t.Subject, t.Object); if (this._subjObjIndex.ContainsKey(so)) { this._subjObjIndex.Add(so, t); } } }
/// <summary> /// Gets all the Triples with a given Subject and Object /// </summary> /// <param name="subj"></param> /// <param name="obj"></param> /// <returns></returns> public override IEnumerable <Triple> WithSubjectObject(INode subj, INode obj) { if (this._fullyIndexed) { int key = Tools.CombineHashCodes(subj, obj); if (!this._subjObjIndex.ContainsKey(key)) { //Try and build the Index this._subjObjIndex.AddEmpty(key); foreach (Triple t in this._triples.Values) { if (t.Subject.Equals(subj) && t.Object.Equals(obj)) { this._subjObjIndex.Add(key, t); } } } return(this._subjObjIndex.GetValues(key)); } else { return(base.WithSubjectObject(subj, obj)); } }