コード例 #1
0
        public void add_whenLinked(IDeque <SimpleLinkedValue> deque)
        {
            var sizeBefore = ((ICollection)deque).Count;

            deque.Add(deque.Peek());
            Assert.That(deque, HasCount(sizeBefore));
        }
コード例 #2
0
ファイル: Deque`1.cs プロジェクト: uniblab/Icod.Collections
 private Deque(Dequelette left, IDeque <Dequelette> middle, Dequelette right, System.Int64 count) : this()
 {
     if (count <= 0)
     {
         throw new System.ArgumentOutOfRangeException("count", "count must be positive.");
     }
     else if (null == right)
     {
         throw new System.ArgumentNullException("right");
     }
     else if (null == left)
     {
         throw new System.ArgumentNullException("left");
     }
     myLeft       = left;
     myMiddle     = middle ?? Deque <Dequelette> .Empty;
     myRight      = right;
     myLongCount  = count;
     myShortCount = (System.Int32)System.Math.Min((System.Int64)System.Int32.MaxValue, myLongCount);
     unchecked {
         myHashCode += left.GetHashCode();
         myHashCode += myMiddle.GetHashCode();
         myHashCode += right.GetHashCode();
     }
 }
コード例 #3
0
        public override void Assign(object value, IGraphProcessingEnvironment procEnv)
        {
            object container = DestVar.GetVariableValue(procEnv);
            object key       = KeyExpression.Evaluate(procEnv);

            if (container is IList)
            {
                IList array = (IList)container;
                if (array.Count > (int)key)
                {
                    array[(int)key] = value;
                }
            }
            else if (container is IDeque)
            {
                IDeque deque = (IDeque)container;
                if (deque.Count > (int)key)
                {
                    deque[(int)key] = value;
                }
            }
            else
            {
                IDictionary map = (IDictionary)container;
                if (map.Contains(key))
                {
                    map[key] = value;
                }
            }
        }
コード例 #4
0
        private static void AppendDeque(StringBuilder sb, IDeque deque, AttributeType attrValueType, IGraph graph)
        {
            bool first = true;

            foreach (Object entry in deque)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    sb.Append(",");
                }

                if (attrValueType != null)
                {
                    sb.Append(ToString(entry, attrValueType, graph));
                }
                else
                {
                    sb.Append(ToStringAutomatic(entry, graph));
                }
            }
        }
コード例 #5
0
        private void DequeOperations(IDeque <string> deque)
        {
            var lastPrepend = string.Empty;
            var lastAppend  = string.Empty;
            var testNumber  = 10000;

            for (var i = 0; i < testNumber; i++)
            {
                lastPrepend = Guid.NewGuid().ToString();
                lastAppend  = Guid.NewGuid().ToString();
                deque.Prepend(lastPrepend);
                deque.Append(lastAppend);
            }
            Assert.Equal(testNumber * 2, deque.Count);
            Assert.Equal(lastPrepend, deque.First);
            Assert.Equal(lastAppend, deque.Last);
            Assert.Equal(lastPrepend, deque.Shift());
            Assert.Equal(testNumber * 2 - 1, deque.Count);
            Assert.Equal(lastAppend, deque.Pop());
            Assert.Equal(testNumber * 2 - 2, deque.Count);

            for (var i = 0; i < (testNumber * 2 - 2); i++)
            {
                Assert.False(string.IsNullOrEmpty(deque.Pop()));
            }
            Assert.Equal(0, deque.Count);
        }
コード例 #6
0
 /// <summary>
 /// Returns an <see cref="IEnumerable{T}"/> of Dequeued Items from the Front of the
 /// <paramref name="deque"/>. The returned items will be in
 /// <see cref="IDeque{T}.DequeueFront"/> order and there may be as many as up to
 /// <paramref name="count"/> items.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="deque"></param>
 /// <param name="count"></param>
 /// <returns></returns>
 public static IEnumerable <T> DequeueFrontMany <T>(this IDeque <T> deque, int count = 1)
 {
     while (count-- > 0 && deque.Count > 0)
     {
         yield return(deque.DequeueFront());
     }
 }
コード例 #7
0
ファイル: Gesture.cs プロジェクト: aepstein824/uist
 public Gesture(GestureGenerator.State state, GestureGenerator.EventType eventType, DateTime startTime, IDeque<SensorData> dataSinceGestureStart)
 {
     DataSinceGestureStart = dataSinceGestureStart;
     StartTime = startTime;
     State = state;
     EventType = eventType;
 }
コード例 #8
0
        public override void Assign(object value, IGraphProcessingEnvironment procEnv)
        {
            IGraphElement elem = (IGraphElement)DestVar.GetVariableValue(procEnv);
            object container = elem.GetAttribute(AttributeName);
            object key = KeyExpression.Evaluate(procEnv);
            AttributeType attrType = elem.Type.GetAttributeType(AttributeName);

            BaseGraph.ChangingAttributeAssignElement(procEnv.Graph, elem, attrType, value, key);

            if(container is IList)
            {
                IList array = (IList)container;
                array[(int)key] = value;
            }
            else if(container is IDeque)
            {
                IDeque deque = (IDeque)container;
                deque[(int)key] = value;
            }
            else
            {
                IDictionary map = (IDictionary)container;
                map[key] = value;
            }

            BaseGraph.ChangedAttribute(procEnv.Graph, elem, attrType);
        }
コード例 #9
0
 private void DequeExceptions(IDeque <int> deque)
 {
     Assert.Throws(typeof(InvalidOperationException), () => deque.Pop());
     Assert.Throws(typeof(InvalidOperationException), () => deque.Shift());
     Assert.Throws(typeof(InvalidOperationException), () => deque.First);
     Assert.Throws(typeof(InvalidOperationException), () => deque.Last);
 }
コード例 #10
0
        private void DequeEnumerator(IDeque <int> deque)
        {
            var cursor1 = 0;

            foreach (var item in deque)
            {
                cursor1++;
            }
            Assert.Equal(0, cursor1);

            for (var i = 0; i < 100000; i++)
            {
                deque.Append(i);
            }
            var cursor2 = 0;

            foreach (var item in deque)
            {
                Assert.Equal(cursor2, item);
                cursor2++;
            }
            for (var i = 1; i < 100001; i++)
            {
                deque.Prepend(-i);
            }
            var cursor3 = -100000;

            foreach (var item in deque)
            {
                Assert.Equal(cursor3, item);
                cursor3++;
            }
        }
コード例 #11
0
ファイル: EmitHelper.cs プロジェクト: jblomer/GrGen.NET
 /// <summary>
 /// Returns a string representation of the given Deque
 /// </summary>
 /// <param name="deque">The Deque of which to get the string representation</param>
 /// <param name="graph">The graph with the model and the element names if available, otherwise null</param>
 /// <returns>string representation of Deque</returns>
 public static string ToString(IDeque deque, IGraph graph)
 {
     string type;
     string content;
     ToString(deque, out type, out content, null, graph);
     return content;
 }
コード例 #12
0
 public static bool NotEqualIDeque(IDeque a, IDeque b)
 {
     if (a == null || b == null)
     {
         if (a == null && b == null)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
     if (a.Count != b.Count)
     {
         return(true);
     }
     if (LessOrEqualIDeque(a, b))
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
コード例 #13
0
        private static void AppendDeque(StringBuilder sb, IDeque deque, AttributeType attrValueType, IGraph graph,
                                        bool firstLevelObjectEmitted, IDictionary <string, IObject> nameToObject, IGraphProcessingEnvironment procEnv)
        {
            bool first = true;

            foreach (object entry in deque)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    sb.Append(",");
                }

                if (attrValueType != null)
                {
                    sb.Append(ToString(entry, attrValueType, graph, firstLevelObjectEmitted, nameToObject, procEnv));
                }
                else
                {
                    sb.Append(ToStringAutomatic(entry, graph, firstLevelObjectEmitted, nameToObject, procEnv));
                }
            }
        }
コード例 #14
0
        /// <summary>
        /// Returns a string representation of the given Deque
        /// </summary>
        /// <param name="deque">The Deque of which to get the string representation</param>
        /// <param name="type">The type as string, e.g deque<int></param>
        /// <param name="content">The content as string, e.g. ] 42, 43 [</param>
        /// <param name="attrType">The attribute type of the deque if available, otherwise null</param>
        /// <param name="graph">The graph with the model and the element names if available, otherwise null</param>
        /// <param name="firstLevelObjectEmitted">Prevents emitting of further objects and thus infinite regressions</param>
        /// <param name="nameToObject">If not null, the names of visited objects are added</param>
        /// <param name="procEnv">If not null, the processing environment is used for transient object unique id emitting and fetching</param>
        public static void ToString(IDeque deque, out string type, out string content,
                                    AttributeType attrType, IGraph graph, bool firstLevelObjectEmitted,
                                    IDictionary <string, IObject> nameToObject, IGraphProcessingEnvironment procEnv)
        {
            Type valueType;

            ContainerHelper.GetDequeType(deque, out valueType);

            StringBuilder sb = new StringBuilder(256);

            sb.Append("]");

            AttributeType attrValueType = attrType != null ? attrType.ValueType : null;

            if (deque != null)
            {
                type = "deque<" + valueType.Name + ">";
                AppendDeque(sb, deque, attrValueType, graph, firstLevelObjectEmitted, nameToObject, procEnv);
            }
            else
            {
                type = "<INVALID>";
            }

            sb.Append("[");
            content = sb.ToString();
        }
コード例 #15
0
 /// <summary>
 /// Returns an <see cref="IEnumerable{T}"/> of Dequeued Items from the Back of the
 /// <paramref name="deque"/>. The returned items will be in
 /// <see cref="Generic.IDeque{T}.DequeueBack"/> order and there may be as many as
 /// up to <paramref name="count"/> items.
 /// </summary>
 /// <param name="deque"></param>
 /// <param name="count"></param>
 /// <returns></returns>
 public static IEnumerable <object> DequeueBackMany(this IDeque deque, int count = 1)
 {
     while (count-- > 0 && deque.Count > 0)
     {
         yield return(deque.DequeueBack());
     }
 }
コード例 #16
0
        /// <summary>
        /// Returns a string representation of the given Deque
        /// </summary>
        /// <param name="deque">The Deque of which to get the string representation</param>
        /// <param name="type">The type as string, e.g deque<int></param>
        /// <param name="content">The content as string, e.g. ] 42, 43 [</param>
        /// <param name="attrType">The attribute type of the deque if available, otherwise null</param>
        /// <param name="graph">The graph with the model and the element names if available, otherwise null</param>
        public static void ToString(IDeque deque, out string type, out string content,
                                    AttributeType attrType, IGraph graph)
        {
            Type valueType;

            ContainerHelper.GetDequeType(deque, out valueType);

            StringBuilder sb = new StringBuilder(256);

            sb.Append("]");

            AttributeType attrValueType = attrType != null ? attrType.ValueType : null;

            if (deque != null)
            {
                type = "deque<" + valueType.Name + ">";
                AppendDeque(sb, deque, attrValueType, graph);
            }
            else
            {
                type = "<INVALID>";
            }

            sb.Append("[");
            content = sb.ToString();
        }
コード例 #17
0
 /// <summary>
 /// Creates a shallow clone of the given container.
 /// </summary>
 /// <param name="oldContainer">The container to clone.</param>
 /// <returns>A shallow clone of the container</returns>
 public static object Clone(object oldContainer)
 {
     if (oldContainer is IDictionary)
     {
         Type        keyType, valueType;
         IDictionary dict = ContainerHelper.GetDictionaryTypes(
             oldContainer, out keyType, out valueType);
         return(NewDictionary(keyType, valueType, oldContainer));
     }
     else if (oldContainer is IList)
     {
         Type  valueType;
         IList array = ContainerHelper.GetListType(
             oldContainer, out valueType);
         return(NewList(valueType, oldContainer));
     }
     else if (oldContainer is IDeque)
     {
         Type   valueType;
         IDeque deque = ContainerHelper.GetDequeType(
             oldContainer, out valueType);
         return(NewDeque(valueType, oldContainer));
     }
     return(null); // no known container type
 }
コード例 #18
0
ファイル: Program.cs プロジェクト: JohannesSpicker/Micha-C-
        static bool TestDeque(IDeque <int> deque, int n)
        {
            if (deque.Size != 0)
            {
                return(false);
            }
            for (int i = 0; i < n; i++)
            {
                deque.Prepend(i);
                deque.Append(i);
                deque.RemoveFirst();
            }

            if (deque.Size != n)
            {
                return(false);
            }
            if (n > 0 && (deque.First != 0 || deque.Last != n - 1))
            {
                return(false);
            }
            int elem = -1;

            for (int i = 0; i < n; i++)
            {
                elem = deque.RemoveLast();
            }
            if (deque.Size != 0 || elem != 0)
            {
                return(false);
            }
            return(true);
        }
コード例 #19
0
ファイル: Highlighter.cs プロジェクト: tmaierhofer/grgen
        private void HighlightDeque(IDeque value, string name, bool addAnnotation)
        {
            int    distanceToTop = 0;
            object prevElem      = null;

            foreach (object elem in value)
            {
                if (elem is IGraphElement)
                {
                    HighlightSingleValue(elem, name + "@" + distanceToTop, addAnnotation);
                }
                if (elem is INode && distanceToTop >= 1)
                {
                    if (addAnnotation)
                    {
                        ycompClient.AddEdge(name + distanceToTop, name + "[->]", (INode)prevElem, (INode)elem);
                    }
                    else
                    {
                        ycompClient.DeleteEdge(name + distanceToTop);
                    }
                }
                prevElem = elem;
                ++distanceToTop;
            }
        }
コード例 #20
0
        public void add_whenEmpty(IDeque <SimpleLinkedValue> deque)
        {
            SimpleLinkedValue value = new SimpleLinkedValue(1);

            deque.Add(value);
            Assert.That(deque.Peek(), Is.SameAs(value));
            Assert.That(deque, HasCount(1));
        }
コード例 #21
0
ファイル: EmitHelper.cs プロジェクト: tmaierhofer/grgen
        /// <summary>
        /// Returns a string representation of the given Deque
        /// </summary>
        /// <param name="deque">The Deque of which to get the string representation</param>
        /// <param name="graph">The graph with the model and the element names if available, otherwise null</param>
        /// <returns>string representation of Deque</returns>
        public static string ToString(IDeque deque, IGraph graph)
        {
            string type;
            string content;

            ToString(deque, out type, out content, null, graph);
            return(content);
        }
コード例 #22
0
        public void removeElement_whenFound(IDeque <SimpleLinkedValue> deque)
        {
            SimpleLinkedValue first = deque.Peek();

            Assert.That(deque.Remove(first), Is.True);
            Assert.That(deque, HasCount((int)Capacity() - 1));
            Assert.That(deque.Contains(first), Is.False);
        }
コード例 #23
0
        public void add_whenPopulated(IDeque <SimpleLinkedValue> deque)
        {
            SimpleLinkedValue value = new SimpleLinkedValue((int)Capacity());

            deque.Add(value);
            Assert.That(deque.Peek(), Is.Not.SameAs(value));
            Assert.That(deque, HasCount((int)Capacity() + 1));
        }
コード例 #24
0
ファイル: Deque`1.cs プロジェクト: uniblab/Icod.Collections
 static Deque()
 {
     theHashCode = typeof(Deque <T>).AssemblyQualifiedName.GetHashCode();
     unchecked {
         theHashCode += typeof(T).AssemblyQualifiedName.GetHashCode();
     }
     theEmpty = new EmptyDeque();
 }
コード例 #25
0
        public void dequeue_whenPopulated(IDeque <SimpleLinkedValue> deque)
        {
            SimpleLinkedValue first = deque.Peek();

            Assert.That(deque.Dequeue(), Is.SameAs(first));
            Assert.That(deque, HasCount((int)Capacity() - 1));
            Assert.That(deque.Contains(first), Is.False);
        }
コード例 #26
0
 public static bool GreaterThanIDeque(IDeque a, IDeque b)
 {
     if (a.Count == b.Count)
     {
         return(false);
     }
     return(GreaterOrEqualIDeque(a, b));
 }
コード例 #27
0
 public static bool LessThanIDeque(IDeque a, IDeque b)
 {
     if (a.Count == b.Count)
     {
         return(false);
     }
     return(LessOrEqualIDeque(a, b));
 }
コード例 #28
0
 public static IDeque FillDeque(IDeque dequeToCopyTo, string valueTypeName, object hopefullyDequeToCopy, IGraphModel model)
 {
     if (hopefullyDequeToCopy is IDeque)
     {
         return(FillDeque(dequeToCopyTo, valueTypeName, (IDeque)hopefullyDequeToCopy, model));
     }
     throw new Exception("Deque copy constructor expects deque as source.");
 }
コード例 #29
0
 private void DequeCollectionOperations(IDeque <int> deque)
 {
     for (var i = 0; i < 1000; i++)
     {
         deque.Append(i + 1);
     }
     deque.CollectionOperations <int>(1000);
 }
コード例 #30
0
ファイル: EmitHelper.cs プロジェクト: GunterMueller/grgen
        /// <summary>
        /// Returns a string representation of the given Deque
        /// </summary>
        /// <param name="deque">The Deque of which to get the string representation</param>
        /// <param name="graph">The graph with the model and the element names if available, otherwise null</param>
        /// <param name="firstLevelObjectEmitted">Prevents emitting of further objects and thus infinite regressions</param>
        /// <param name="nameToObject">If not null, the names of visited objects are added</param>
        /// <param name="procEnv">If not null, the processing environment is used for transient object unique id emitting and fetching</param>
        /// <returns>string representation of Deque</returns>
        public static string ToString(IDeque deque, IGraph graph, bool firstLevelObjectEmitted,
                                      IDictionary <string, IObject> nameToObject, IGraphProcessingEnvironment procEnv)
        {
            string type;
            string content;

            ToString(deque, out type, out content, null, graph, firstLevelObjectEmitted, nameToObject, procEnv);
            return(content);
        }
コード例 #31
0
        /// <summary>
        /// Enqueues a sequence of items to the back of the <see cref="IDeque{T}"/>.
        /// </summary>
        /// <typeparam name="T">The type of items.</typeparam>
        /// <param name="deque">The double-ended queue to add the items to.</param>
        /// <param name="items">The items to enqueue.</param>
        public static void EnqueueRangeToBack <T>(this IDeque <T> deque, IEnumerable <T> items)
        {
            deque.ThrowIfNull(nameof(deque));
            items.ThrowIfNull(nameof(items));

            foreach (T item in items)
            {
                deque.EnqueueItemToBack(item);
            }
        }
コード例 #32
0
 public static void FillDequeWithVar <K>(Deque <K> targetDeque, Type varType, IDeque sourceDeque)
 {
     foreach (object entry in sourceDeque)
     {
         if (entry.GetType() == varType)
         {
             targetDeque.Add((K)entry);
         }
     }
 }
コード例 #33
0
ファイル: GestureGenerator.cs プロジェクト: aepstein824/uist
 public void HandleSensorData(SensorData sd)
 {
     State origState = state;
     dataSinceStateStart = dataSinceStateStart.EnqueueRight(sd);
     ChangeState(sd.FingerCount(), sd.Distance());
     if (origState != state)
     {
         // state changed! Send off the vanish event for the previous gesture, and a appear event for the current gesture
         gestures.Enqueue(new Gesture(origState, EventType.VANISH, stateEntryTime, dataSinceStateStart));
         stateEntryTime = DateTime.Now;
         dataSinceStateStart = Deque<SensorData>.Empty;
         dataSinceStateStart = dataSinceStateStart.EnqueueRight(sd);
         gestures.Enqueue(new Gesture(state, EventType.APPEAR, stateEntryTime, dataSinceStateStart));
     }
     else
     {
         // continuation of the existing gesture
         gestures.Enqueue(new Gesture(state, EventType.MOVE, stateEntryTime, dataSinceStateStart));
     }
 }
コード例 #34
0
ファイル: EmitHelper.cs プロジェクト: jblomer/GrGen.NET
        /// <summary>
        /// Returns a string representation of the given Deque
        /// </summary>
        /// <param name="deque">The Deque of which to get the string representation</param>
        /// <param name="type">The type as string, e.g deque<int></param>
        /// <param name="content">The content as string, e.g. ] 42, 43 [</param>
        /// <param name="attrType">The attribute type of the deque if available, otherwise null</param>
        /// <param name="graph">The graph with the model and the element names if available, otherwise null</param>
        public static void ToString(IDeque deque, out string type, out string content,
            AttributeType attrType, IGraph graph)
        {
            Type valueType;
            ContainerHelper.GetDequeType(deque, out valueType);

            StringBuilder sb = new StringBuilder(256);
            sb.Append("]");

            AttributeType attrValueType = attrType != null ? attrType.ValueType : null;

            if(deque != null)
            {
                type = "deque<" + valueType.Name + ">";
                bool first = true;
                foreach(Object entry in deque)
                {
                    if(first) { sb.Append(ToString(entry, attrValueType, graph)); first = false; }
                    else { sb.Append(","); sb.Append(ToString(entry, attrValueType, graph)); }
                }
            }
            else
            {
                type = "<INVALID>";
            }

            sb.Append("[");
            content = sb.ToString();
        }
コード例 #35
0
ファイル: EmitHelper.cs プロジェクト: jblomer/GrGen.NET
 /// <summary>
 /// Returns a string representation of the given Deque
 /// after the given operation with the given parameters was applied
 /// </summary>
 /// <param name="deque">The base Deque of the operation</param>
 /// <param name="changeType">The type of the change operation</param>
 /// <param name="newValue">The new value to be inserted/added if changeType==PutElement on deque.</param>
 /// <param name="type">The type as string, e.g deque<int></param>
 /// <param name="content">The content as string, e.g. ] 42, 43 [ </param>
 /// <param name="attrType">The attribute type of the Deque</param>
 /// <param name="graph">The graph with the model and the element names</param>
 public static void ToString(IDeque deque,
     AttributeChangeType changeType, Object newValue,
     out string type, out string content,
     AttributeType attrType, IGraph graph)
 {
     if(changeType == AttributeChangeType.PutElement)
     {
         Type valueType;
         ContainerHelper.GetDequeType(deque, out valueType);
         ToString(deque, out type, out content, attrType, graph);
         content += ".add(" + ToString(newValue, attrType.ValueType, graph) + ")";
     }
     else if(changeType == AttributeChangeType.RemoveElement)
     {
         Type valueType;
         ContainerHelper.GetDequeType(deque, out valueType);
         ToString(deque, out type, out content, attrType, graph);
         content += ".rem()";
     }
     else // changeType==AttributeChangeType.Assign
     {
         ToString((IDeque)newValue, out type, out content, attrType, graph);
     }
 }
コード例 #36
0
ファイル: Debugger.cs プロジェクト: jblomer/GrGen.NET
 void HighlightDeque(IDeque value, string name, bool addAnnotation)
 {
     int distanceToTop = 0;
     object prevElem = null;
     foreach(object elem in value)
     {
         if(elem is IGraphElement)
             HighlightSingleValue(elem, name + "@" + distanceToTop, addAnnotation);
         if(elem is INode && distanceToTop >= 1)
         {
             if(addAnnotation)
                 ycompClient.AddEdge(name + distanceToTop, name + "[->]", (INode)prevElem, (INode)elem);
             else
                 ycompClient.DeleteEdge(name + distanceToTop);
         }
         prevElem = elem;
         ++distanceToTop;
     }
 }