public void Evaluate(ICollection<ScheduleHandle> handles) { lock (this) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QScheduleEval(_currentTime); } // Get the values on or before the current time - to get those that are exactly on the // current time we just add one to the current time for getting the head map var headMap = _timeHandleMap.Head(_currentTime + 1); if (headMap.IsEmpty()) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AScheduleEval(handles); } return; } // First determine all triggers to shoot IList<long> removeKeys = new List<long>(); foreach (var entry in headMap) { var key = entry.Key; var value = entry.Value; removeKeys.Add(key); foreach (var handle in value.Values) { handles.Add(handle); } } // Next remove all handles foreach (var entry in headMap) { foreach (var handle in entry.Value.Values) { _handleSetMap.Remove(handle); } } // Remove all triggered msec values foreach (var key in removeKeys) { _timeHandleMap.Remove(key); } if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AScheduleEval(handles); } } }
/// <summary> /// Returns a readonly ordered dictionary that includes everything before the value. /// Whether the value is included in the range depends on whether the isInclusive /// flag is set. /// </summary> /// <param name="value">The end value.</param> /// <param name="isInclusive">if set to <c>true</c> [is inclusive].</param> /// <returns></returns> public IOrderedDictionary <TK1, TV1> Head( TK1 value, bool isInclusive = false) { return(new TransformOrderedDictionary <TK1, TV1, TK2, TV2>( _subDictionaryOrdered.Head(KeyIn(value), isInclusive), KeyOut, KeyIn, ValueOut, ValueIn)); }
public void LookupLessEqual( ISet<EventBean> result, IOrderedDictionary<object, CompositeIndexEntry> propertyIndex, object keyStart, CompositeIndexQueryResultPostProcessor postProcessor) { if (keyStart == null) { return; } keyStart = Coerce(keyStart); Normalize(result, propertyIndex.Head(keyStart, true), postProcessor); }
public void LookupRangeInverted( ISet<EventBean> result, IOrderedDictionary<object, CompositeIndexEntry> propertyIndex, object keyStart, bool includeStart, object keyEnd, bool includeEnd, CompositeIndexQueryResultPostProcessor postProcessor) { if (keyStart == null || keyEnd == null) { return; } keyStart = Coerce(keyStart); keyEnd = Coerce(keyEnd); var submapOne = propertyIndex.Head(keyStart, !includeStart); var submapTwo = propertyIndex.Tail(keyEnd, !includeEnd); Normalize(result, submapOne, submapTwo, postProcessor); }
public override ISet<EventBean> LookupRangeInverted( object keyStart, bool includeStart, object keyEnd, bool includeEnd) { if (keyStart == null || keyEnd == null) { return Collections.GetEmptySet<EventBean>(); } keyStart = Coerce(keyStart); keyEnd = Coerce(keyEnd); var submapOne = propertyIndex.Head(keyStart, !includeStart); var submapTwo = propertyIndex.Tail(keyEnd, !includeEnd); return Normalize(submapOne, submapTwo); }
private static void AssertOrderedDictionary( IOrderedDictionary <int, IList <SupportBean> > treemap, IOrderedDictionary <object, ICollection <EventBean> > actual) { Assert.AreEqual(treemap.Count, actual.Count); foreach (var key in treemap.Keys) { var expectedEvents = treemap.Get(key).ToArray(); EPAssertionUtil.AssertEqualsExactOrder(expectedEvents, ToArrayOfUnderlying(actual.Get(key))); } CompareEntry(treemap.First(), actual.FirstEntry); CompareEntry(treemap.Last(), actual.LastEntry); CompareEntry(treemap.LessThanOrEqualTo(5), actual.LessThanOrEqualTo(5)); CompareEntry(treemap.GreaterThanOrEqualTo(5), actual.GreaterThanOrEqualTo(5)); CompareEntry(treemap.LessThan(5), actual.LessThan(5)); CompareEntry(treemap.GreaterThan(5), actual.GreaterThan(5)); Assert.AreEqual(treemap.Keys.First(), actual.FirstEntry.Key); Assert.AreEqual(treemap.Keys.Last(), actual.LastEntry.Key); Assert.AreEqual(treemap.LessThanOrEqualTo(5)?.Key, actual.LessThanOrEqualTo(5)?.Key); Assert.AreEqual(treemap.GreaterThanOrEqualTo(5)?.Key, actual.GreaterThanOrEqualTo(5)?.Key); Assert.AreEqual(treemap.LessThan(5)?.Key, actual.LessThan(5)?.Key); Assert.AreEqual(treemap.GreaterThan(5)?.Key, actual.GreaterThan(5)?.Key); Assert.AreEqual(treemap.ContainsKey(5), actual.ContainsKey(5)); Assert.AreEqual(treemap.IsEmpty(), actual.IsEmpty()); EPAssertionUtil.AssertEqualsExactOrder(new object[] { 1, 4, 6, 8, 9 }, actual.Keys.ToArray()); Assert.AreEqual(1, actual.Between(9, true, 9, true).Count); Assert.AreEqual(1, actual.Tail(9).Count); Assert.AreEqual(1, actual.Tail(9, true).Count); Assert.AreEqual(1, actual.Head(2).Count); Assert.AreEqual(1, actual.Head(2, false).Count); Assert.AreEqual(5, actual.Count); Assert.AreEqual(5, actual.Keys.Count); Assert.AreEqual(5, actual.Values.Count); // values var values = actual.Values; Assert.That(values.Count, Is.EqualTo(5)); Assert.That(values.IsEmpty(), Is.False); var valuesEnum = values.GetEnumerator(); Assert.That(valuesEnum, Is.Not.Null); Assert.That(valuesEnum.MoveNext, Is.True); CollectionAssert.AreEqual( treemap.Get(1).ToArray(), ToArrayOfUnderlying(valuesEnum.Current)); Assert.That(valuesEnum.MoveNext, Is.True); Assert.That(values.ToArray(), Has.Length.EqualTo(5)); CollectionAssert.AreEqual( treemap.Get(1).ToArray(), ToArrayOfUnderlying((ICollection <EventBean>)values.ToArray()[0])); // ordered key set var oks = actual.OrderedKeys; //Assert.That(oks.Comparator()); Assert.That(oks.FirstEntry, Is.EqualTo(1)); Assert.That(oks.LastEntry, Is.EqualTo(9)); Assert.That(oks.Count, Is.EqualTo(5)); Assert.That(oks.IsEmpty(), Is.False); Assert.That(oks.Contains(6), Is.True); Assert.That(oks.ToArray(), Is.Not.Null); Assert.That(oks.LessThan(5), Is.EqualTo(4)); Assert.That(oks.GreaterThan(5), Is.EqualTo(6)); Assert.That(oks.LessThanOrEqualTo(5), Is.EqualTo(4)); Assert.That(oks.GreaterThanOrEqualTo(5), Is.EqualTo(6)); Assert.That(oks.Between(1, true, 100, true), Is.Not.Null); Assert.That(oks.Head(100, true), Is.Not.Null); Assert.That(oks.Tail(1, true), Is.Not.Null); // ordered key set - enumerator var oksit = oks.GetEnumerator(); Assert.That(oksit, Is.Not.Null); Assert.That(oksit.MoveNext(), Is.True); Assert.That(oksit.Current, Is.EqualTo(1)); Assert.That(oksit.MoveNext(), Is.True); // entry set ICollection <KeyValuePair <object, ICollection <EventBean> > > set = actual; Assert.IsFalse(set.IsEmpty()); var setit = set.GetEnumerator(); var entry = setit.Advance(); Assert.AreEqual(1, entry.Key); Assert.IsTrue(setit.MoveNext()); EPAssertionUtil.AssertEqualsExactOrder(treemap.Get(1).ToArray(), ToArrayOfUnderlying(entry.Value)); var array = set.ToArray(); Assert.AreEqual(5, array.Length); Assert.AreEqual(1, array[0].Key); EPAssertionUtil.AssertEqualsExactOrder(treemap.Get(1).ToArray(), ToArrayOfUnderlying(array[0].Value)); Assert.IsNotNull(set.ToArray()); // sorted map var events = actual.Head(100); Assert.AreEqual(5, events.Count); }
public override void MatchEvent( EventBean theEvent, ICollection<FilterHandle> matches, ExprEvaluatorContext ctx) { var propertyValue = Lookupable.Eval.Eval(theEvent, ctx); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QFilterReverseIndex(this, propertyValue); } if (propertyValue == null) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AFilterReverseIndex(false); } return; } var filterOperator = this.FilterOperator; // Look up in table using (constantsMapRWLock.ReadLock.Acquire()) { // Get the head or tail end of the map depending on comparison type IDictionary<object, EventEvaluator> subMap; if ((filterOperator == FilterOperator.GREATER) || (filterOperator == FilterOperator.GREATER_OR_EQUAL)) { // At the head of the map are those with a lower numeric constants subMap = constantsMap.Head(propertyValue); } else { subMap = constantsMap.Tail(propertyValue); } // All entries in the subMap are elgibile, with an exception EventEvaluator exactEquals = null; if (filterOperator == FilterOperator.LESS) { exactEquals = constantsMap.Get(propertyValue); } foreach (var matcher in subMap.Values) { // For the LESS comparison type we ignore the exactly equal case // The subMap is sorted ascending, thus the exactly equals case is the first if (exactEquals != null) { exactEquals = null; continue; } matcher.MatchEvent(theEvent, matches, ctx); } if (filterOperator == FilterOperator.GREATER_OR_EQUAL) { var matcher = constantsMap.Get(propertyValue); if (matcher != null) { matcher.MatchEvent(theEvent, matches, ctx); } } } if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AFilterReverseIndex(null); } }
public override void MatchEvent( EventBean theEvent, ICollection<FilterHandle> matches, ExprEvaluatorContext ctx) { object propertyValue = Lookupable.Eval.Eval(theEvent, ctx); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QFilterReverseIndex(this, propertyValue); } if (propertyValue == null) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AFilterReverseIndex(false); } return; } // A undefine lower bound indicates an empty index if (lowerBounds == null) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AFilterReverseIndex(false); } return; } var filterOperator = FilterOperator; double propertyValueDouble = propertyValue.AsDouble(); // Based on current lower and upper bounds check if the property value falls outside - shortcut submap generation if (filterOperator == FilterOperator.GREATER && propertyValueDouble <= lowerBounds) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AFilterReverseIndex(false); } return; } if (filterOperator == FilterOperator.GREATER_OR_EQUAL && propertyValueDouble < lowerBounds) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AFilterReverseIndex(false); } return; } if (filterOperator == FilterOperator.LESS && propertyValueDouble >= upperBounds) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AFilterReverseIndex(false); } return; } if (filterOperator == FilterOperator.LESS_OR_EQUAL && propertyValueDouble > upperBounds) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AFilterReverseIndex(false); } return; } // Look up in table using (constantsMapRWLock.ReadLock.Acquire()) { // Get the head or tail end of the map depending on comparison type IDictionary<object, EventEvaluator> subMap; if (filterOperator == FilterOperator.GREATER || filterOperator == FilterOperator.GREATER_OR_EQUAL) { // At the head of the map are those with a lower numeric constants subMap = constantsMap.Head(propertyValue); } else { subMap = constantsMap.Tail(propertyValue); } // All entries in the subMap are eligible, with an exception EventEvaluator exactEquals = null; if (filterOperator == FilterOperator.LESS) { exactEquals = constantsMap.Get(propertyValue); } foreach (EventEvaluator matcher in subMap.Values) { // For the LESS comparison type we ignore the exactly equal case // The subMap is sorted ascending, thus the exactly equals case is the first if (exactEquals != null) { exactEquals = null; continue; } matcher.MatchEvent(theEvent, matches, ctx); } if (filterOperator == FilterOperator.GREATER_OR_EQUAL) { var matcher = constantsMap.Get(propertyValue); matcher?.MatchEvent(theEvent, matches, ctx); } } if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AFilterReverseIndex(null); } }