/// <summary> /// Method for generating product of two multisets asynchronously. /// </summary> /// <param name="multiset">Multiset.</param> /// <param name="other">Other Multiset.</param> /// <param name="target">Mutliset to generate the product in.</param> /// <param name="stop">Stop Token.</param> private static void GenerateProduct(BaseMultiset multiset, BaseMultiset other, BaseMultiset target, StopToken stop) { if (Options.UsePLinqEvaluation) { // Determine partition sizes so we can do a parallel product // Want to parallelize over whichever side is larger if (multiset.Count >= other.Count) { multiset.Sets.AsParallel().ForAll(x => EvalProduct(x, other, target as PartitionedMultiset, stop)); } else { other.Sets.AsParallel().ForAll(y => EvalProduct(y, multiset, target as PartitionedMultiset, stop)); } } else { foreach (ISet x in multiset.Sets) { foreach (ISet y in other.Sets) { target.Add(x.Join(y)); // if (stop.ShouldStop) break; } if (stop.ShouldStop) { break; } } } }
/// <summary> /// Method for generating product of two multisets asynchronously /// </summary> /// <param name="multiset">Multiset</param> /// <param name="other">Other Multiset</param> /// <param name="target">Mutliset to generate the product in</param> /// <param name="stop">Stop Token</param> private static void GenerateProduct(BaseMultiset multiset, BaseMultiset other, BaseMultiset target, StopToken stop) { foreach (ISet x in multiset.Sets) { foreach (ISet y in other.Sets) { target.Add(x.Join(y)); //if (stop.ShouldStop) break; } if (stop.ShouldStop) { break; } } }
private void EvalJoin(ISet y, List <String> joinVars, List <HashTable <INode, int> > values, List <List <int> > nulls, BaseMultiset joinedSet) { IEnumerable <int> possMatches = null; int i = 0; foreach (String var in joinVars) { INode value = y[var]; if (value != null) { if (values[i].ContainsKey(value)) { possMatches = (possMatches == null ? values[i].GetValues(value).Concat(nulls[i]) : possMatches.Intersect(values[i].GetValues(value).Concat(nulls[i]))); } else { possMatches = Enumerable.Empty <int>(); break; } } else { //Don't forget that a null will be potentially compatible with everything possMatches = (possMatches == null ? this.SetIDs : possMatches.Intersect(this.SetIDs)); } i++; } if (possMatches == null) { return; } //Now do the actual joins for the current set //Note - We access the dictionary directly here because going through the this[int id] method //incurs a Contains() call each time and we know the IDs must exist because they came from //our dictionary originally! foreach (int poss in possMatches) { if (this._sets[poss].IsCompatibleWith(y, joinVars)) { joinedSet.Add(this._sets[poss].Join(y)); } } }
private void EvalJoin(ISet y, List <String> joinVars, List <MultiDictionary <INode, List <int> > > values, List <List <int> > nulls, BaseMultiset joinedSet) { IEnumerable <int> possMatches = null; int i = 0; foreach (String var in joinVars) { INode value = y[var]; if (value != null) { if (values[i].ContainsKey(value)) { possMatches = (possMatches == null ? values[i][value].Concat(nulls[i]) : possMatches.Intersect(values[i][value].Concat(nulls[i]))); } else { possMatches = Enumerable.Empty <int>(); break; } } else { // Don't forget that a null will be potentially compatible with everything possMatches = (possMatches == null ? SetIDs : possMatches.Intersect(SetIDs)); } i++; } if (possMatches == null) { return; } // Now do the actual joins for the current set foreach (int poss in possMatches) { if (this[poss].IsCompatibleWith(y, joinVars)) { joinedSet.Add(this[poss].Join(y)); } } }
private void EvalJoin(ISet y, List<String> joinVars, List<HashTable<INode, int>> values, List<List<int>> nulls, BaseMultiset joinedSet) { IEnumerable<int> possMatches = null; int i = 0; foreach (String var in joinVars) { INode value = y[var]; if (value != null) { if (values[i].ContainsKey(value)) { possMatches = (possMatches == null ? values[i].GetValues(value).Concat(nulls[i]) : possMatches.Intersect(values[i].GetValues(value).Concat(nulls[i]))); } else { possMatches = Enumerable.Empty<int>(); break; } } else { //Don't forget that a null will be potentially compatible with everything possMatches = (possMatches == null ? this.SetIDs : possMatches.Intersect(this.SetIDs)); } i++; } if (possMatches == null) return; //Now do the actual joins for the current set //Note - We access the dictionary directly here because going through the this[int id] method //incurs a Contains() call each time and we know the IDs must exist because they came from //our dictionary originally! foreach (int poss in possMatches) { if (this._sets[poss].IsCompatibleWith(y, joinVars)) { joinedSet.Add(this._sets[poss].Join(y)); } } }
private void EvalLeftJoin(ISet x, BaseMultiset other, List <String> joinVars, List <MultiDictionary <INode, List <int> > > values, List <List <int> > nulls, BaseMultiset joinedSet, SparqlEvaluationContext subcontext, ISparqlExpression expr) { IEnumerable <int> possMatches = null; int i = 0; foreach (String var in joinVars) { INode value = x[var]; if (value != null) { if (values[i].ContainsKey(value)) { possMatches = (possMatches == null ? values[i][value].Concat(nulls[i]) : possMatches.Intersect(values[i][value].Concat(nulls[i]))); } else { possMatches = Enumerable.Empty <int>(); break; } } else { // Don't forget that a null will be potentially compatible with everything possMatches = (possMatches == null ? SetIDs : possMatches.Intersect(SetIDs)); } i++; } // If no possible matches just copy LHS across if (possMatches == null) { joinedSet.Add(x.Copy()); return; } // Now do the actual joins for the current set bool standalone = false; bool matched = false; foreach (int poss in possMatches) { if (other[poss].IsCompatibleWith(x, joinVars)) { ISet z = x.Join(other[poss]); joinedSet.Add(z); try { if (!expr.Evaluate(subcontext, z.ID).AsSafeBoolean()) { joinedSet.Remove(z.ID); } else { matched = true; } } catch { joinedSet.Remove(z.ID); standalone = true; } } } if (standalone || !matched) { joinedSet.Add(x.Copy()); } }
/// <summary> /// Method for generating product of two multisets asynchronously /// </summary> /// <param name="multiset">Multiset</param> /// <param name="other">Other Multiset</param> /// <param name="target">Mutliset to generate the product in</param> /// <param name="stop">Stop Token</param> private static void GenerateProduct(BaseMultiset multiset, BaseMultiset other, BaseMultiset target, StopToken stop) { foreach (ISet x in multiset.Sets) { foreach (ISet y in other.Sets) { target.Add(x.Join(y)); //if (stop.ShouldStop) break; } if (stop.ShouldStop) break; } }