示例#1
0
        public void EnumerateDifferenceAt(int offsetLength, int timeIndex, NaiadList <Weighted <S> > toFill)
        {
            if (toFill.Count == 0)
            {
                var temp = new OffsetLength(offsetLength);


                var accum = new CollectionTraceWithAggregationIncrement <S>();

                var handle = increments.Dereference(temp);
                for (int i = 0; i < handle.Length && !handle.Array[handle.Offset + i].IsEmpty(isZero); i++)
                {
                    if (handle.Array[handle.Offset + i].TimeIndex == timeIndex)
                    {
                        accum.Add(handle.Array[handle.Offset + i], axpy);
                    }
                }

                if (!accum.IsEmpty(isZero))
                {
                    toFill.Add(new Weighted <S>(accum.Value, 1));
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
示例#2
0
 public void ReleaseCache()
 {
     if (!cachedIncrementOffset.IsEmpty)
     {
         cachedIncrementOffset = new OffsetLength();
         cacheContents         = new CollectionTraceWithAggregationIncrement <S>();
     }
 }
示例#3
0
        public void SubtractStrictlyPriorDifferences(ref int keyIndex, int timeIndex)
        {
            var ol = new OffsetLength(keyIndex);

            // if there aren't any strictly prior differences we can just return
            if (ol.IsEmpty)
            {
                return;
            }

            var handle   = EnsureTime(ref ol, timeIndex);
            var position = 0;

            while (handle.Array[handle.Offset + position].TimeIndex != timeIndex)
            {
                position++;
            }

            // if the destination time is empty, we can swap in the accumulation (negated)
            if (!handle.Array[handle.Offset + position].IsEmpty(isZero))
            {
                // swap the accumulation in, and zero out the accumulation (the new correct accumulation for this key).
                var accum = UpdateAccumulation(ref ol, timeIndex);
                handle.Array[handle.Offset + position] = new CollectionTraceWithAggregationIncrement <S>(timeIndex).Add(accum, axpy);

                // we may have ended up with a null acculumation, must clean up
                if (handle.Array[handle.Offset + position].Weight == 0)
                {
                    for (int i = position + 1; i < handle.Length; i++)
                    {
                        handle.Array[handle.Offset + i - 1] = handle.Array[handle.Offset + i];
                    }

                    handle.Array[handle.Offset + handle.Length - 1] = new CollectionTraceWithAggregationIncrement <S>();
                    if (handle.Array[handle.Offset].Weight == 0)
                    {
                        increments.Release(ref ol);
                    }
                }

                // important to update the cached accumulation to reflect the emptiness
                // only do this if the cached accumulation is what we are working with
                if (cachedIncrementOffset.offsetLength == ol.offsetLength)
                {
                    cachedIncrementOffset = ol;
                    cacheContents         = new CollectionTraceWithAggregationIncrement <S>(timeIndex);
                }
            }
            else
            {
                throw new Exception("Attemping subtraction from non-empty time; something wrong in Operator logic");
            }

            keyIndex = ol.offsetLength;
        }
示例#4
0
        void Introduce(ref OffsetLength offsetLength, S element, Int64 weight, int timeIndex)
        {
            var handle = EnsureTime(ref offsetLength, timeIndex);

            var position = 0;

            while (handle.Array[handle.Offset + position].TimeIndex != timeIndex)
            {
                position++;
            }

            if (handle.Array[handle.Offset + position].IsEmpty(isZero))
            {
                handle.Array[handle.Offset + position] = new CollectionTraceWithAggregationIncrement <S>(weight, timeIndex, element);
            }
            else
            {
                var incr   = handle.Array[handle.Offset + position];
                var result = new CollectionTraceWithAggregationIncrement <S>(incr.Weight + weight, timeIndex, axpy(1, element, incr.Value));
                handle.Array[handle.Offset + position] = result;
            }

            // if the introduction results in an empty region, we need to clean up
            if (handle.Array[handle.Offset + position].IsEmpty(isZero))
            {
                // drag everything after it down one
                for (int i = position + 1; i < handle.Length; i++)
                {
                    handle.Array[handle.Offset + i - 1] = handle.Array[handle.Offset + i];
                }

                handle.Array[handle.Offset + handle.Length - 1] = new CollectionTraceWithAggregationIncrement <S>();

                // if the root element is empty, the list must be empty
                if (handle.Array[handle.Offset].IsEmpty(isZero))
                {
                    increments.Release(ref offsetLength);
                }
            }
        }
示例#5
0
文件: Increments.cs 项目: omidm/naiad
 public bool Equals(CollectionTraceWithAggregationIncrement <S> other)
 {
     return(this.Weight == other.Weight && this.TimeIndex == other.TimeIndex && this.Value.Equals(other.Value));
 }
示例#6
0
文件: Increments.cs 项目: omidm/naiad
 public CollectionTraceWithAggregationIncrement <S> Add(CollectionTraceWithAggregationIncrement <S> that, Func <Int64, S, S, S> axpy, int scale = 1)
 {
     this.Weight += scale * that.Weight;
     this.Value   = axpy(scale, that.Value, this.Value);
     return(this);
 }