Ejemplo n.º 1
0
        public void TestAddRemoveAndClearMethods()
        {
            var sut = new IndexedList <ItemMetadata>();

            sut.AddIndex("Idx", metadata => metadata.BlobRef);

            var item1 = new ItemMetadata
            {
                BlobRef = Guid.NewGuid().ToString(),
                Name    = "Tag",
                Value   = "Cuba"
            };

            var item2 = new ItemMetadata
            {
                BlobRef = Guid.NewGuid().ToString(),
                Name    = "Tag",
                Value   = "beach"
            };

            var item3 = new ItemMetadata
            {
                BlobRef = Guid.NewGuid().ToString(),
                Name    = "Tag",
                Value   = "pooltable"
            };

            Assert.That(sut.Count, Is.EqualTo(0));

            sut.Add(item1);

            Assert.That(sut.Count, Is.EqualTo(1));

            sut.Add(item2);

            Assert.That(sut.Count, Is.EqualTo(2));

            sut.Insert(1, item3);
            Assert.That(sut.Count, Is.EqualTo(3));

            sut.RemoveAt(2);

            Assert.That(sut.Count, Is.EqualTo(2));
            Assert.That(sut[0].Value, Is.EqualTo("Cuba"));

            sut.Clear();

            Assert.That(sut.Count, Is.EqualTo(0));
        }
Ejemplo n.º 2
0
        public void AddPosition(float distance = 5f)
        {
            MaintainCache();

            if (Cache.Any(p => DateTime.UtcNow.Subtract(p.RecordedAt).TotalMilliseconds < 250))
            {
                return;
            }

            var myPosition = Core.Player.Position;

            if (Cache.Any(p => p.Position.Distance(myPosition) < distance))
            {
                return;
            }

            if (myPosition == Vector3.Zero)
            {
                return;
            }

            RecentPositions.Add(myPosition);

            Cache.Add(new PositionHistory());
        }
Ejemplo n.º 3
0
    // Adds a factor to the collection and adjusts the time rate accordingly.
    // Returns the index of the factor.
    public int Add(float factor)
    {
        int index = factors.Add(factor);

        UpdateTimeRate();
        return(index);
    }
Ejemplo n.º 4
0
        public void Add(Triple triple)
        {
            if (triple.From.ObjectType != ObjectType.None)
            {
                _triplesByLeft.Add(triple.From.ObjectKey, triple);
                _triplesByLeftInstructionKey.Add(triple.From.InstructionKey, triple);
                _triplesByLeftObjectKeyMember.Add(triple.From.ObjectKeyMember, triple);

                if (triple.From.ObjectKey.IndexOf(".ctor") > -1)
                {
                    _leftConstructorTriplesByTypeKey.Add(triple.From.ObjectKeyType, triple);
                }
            }

            if (!string.IsNullOrEmpty(triple.From.InstanceOwnerKey))
            {
                _triplesByLeftInstanceOwnerKey.Add(triple.From.InstanceOwnerKey, triple);
            }

            _triplesByRight.Add(triple.To.ObjectKey, triple);
            _triplesByRightInstructionKey.Add(triple.To.InstructionKey, triple);
            _triplesByRightObjectKeyMember.Add(triple.To.ObjectKeyMember, triple);

            if (!string.IsNullOrEmpty(triple.To.InstanceOwnerKey))
            {
                _triplesByRightInstanceOwnerKey.Add(triple.To.InstanceOwnerKey, triple);
            }

            if (triple.SetsObjectInitializerMember)
            {
                _objectInitializerTriplesByRightByConstructorInstructionKey.Add(triple.ConstructorInstructionKey, triple);
            }

            _triplesHashset.Add(triple);
        }
Ejemplo n.º 5
0
        public void IndexedListAddShouldAddToList()
        {
            var indexedList = new IndexedList <int>();

            indexedList.Add(0);
            Assert.AreEqual(1, indexedList.Count);
        }
Ejemplo n.º 6
0
    // Adds a factor to the collection and adjusts the product accordingly.
    // Returns the index of the factor.
    public int Add(float factor)
    {
        int index = factors.Add(factor);

        UpdateProduct();
        return(index);
    }
Ejemplo n.º 7
0
        private void AddProduction(IProduction production)
        {
            _productions.Add(production);
            AddProductionToLeftHandSideLookup(production);

            if (production.IsEmpty)
            {
                _transativeNullableSymbols.Add(production.LeftHandSide);
            }

            var leftHandSide = production.LeftHandSide;
            var symbolPath   = _symbolPaths.AddOrGetExisting(leftHandSide);

            for (var s = 0; s < production.RightHandSide.Count; s++)
            {
                var symbol = production.RightHandSide[s];
                if (symbol.SymbolType == SymbolType.LexerRule)
                {
                    AddLexerRule(symbol as ILexerRule);
                }
                RegisterDottedRule(production, s);
                RegisterSymbolPath(production, symbolPath, s);
                RegisterSymbolInReverseLookup(production, symbol);
            }
            RegisterDottedRule(production, production.RightHandSide.Count);
        }
Ejemplo n.º 8
0
 private void AddIgnoreRules(IReadOnlyList <ILexerRule> ignoreRules)
 {
     for (int i = 0; i < ignoreRules.Count; i++)
     {
         var ignoreRule = ignoreRules[i];
         _ignores.Add(ignoreRule);
         _lexerRules.Add(ignoreRule);
     }
 }
Ejemplo n.º 9
0
 private void AddTriviaRules(IReadOnlyList <ILexerRule> triviaRules)
 {
     for (int i = 0; i < triviaRules.Count; i++)
     {
         var triviaRule = triviaRules[i];
         _trivia.Add(triviaRule);
         _lexerRules.Add(triviaRule);
     }
 }
Ejemplo n.º 10
0
 private static void TrackIndepenantInternal(LoadedBundle loadedBundle, GameObject go)
 {
     if (go.scene.name == null)
     {
         throw new System.Exception("GameObject is not instantiated one");
     }
     s_TrackingGameObjects.Add(new TrackingGameObject(go, loadedBundle));
     RetainBundleInternal(loadedBundle, 1);
 }
Ejemplo n.º 11
0
        private static IndexedList <int> CreateListForRange(int min, int max)
        {
            var indexedList = new IndexedList <int>();

            for (var i = min; i <= max; i++)
            {
                indexedList.Add(i);
            }
            return(indexedList);
        }
Ejemplo n.º 12
0
        public void TestAdd()
        {
            IndexedList<string, SiteLink> list = new IndexedList<string, SiteLink> (siteLink => siteLink.SiteId) {
                new SiteLink("enwiki", "Foo")
            };
            list.Add(new SiteLink("dewiki", "Bar"));

            Assert.Equal("Foo", list["enwiki"].PageName);
            Assert.Equal("Bar", list["dewiki"].PageName);
        }
Ejemplo n.º 13
0
    static object Solve()
    {
        var n  = int.Parse(Console.ReadLine());
        var s0 = Console.ReadLine().Select(c => c == 'B').ToArray();
        var t  = Console.ReadLine().Select(c => c == 'B').ToArray();

        var s = new IndexedList <bool>();

        foreach (var v in s0)
        {
            s.Add(v);
        }

        var r = 0L;
        // 先行インデックス
        var q = 0;

        for (int i = 0; i < n; i++)
        {
            var v = s[i];
            if (v == t[i])
            {
                continue;
            }

            if (i == n - 1)
            {
                return(-1);
            }

            q = Math.Max(q, i);
            while (q + 1 < n && s[q] != s[q + 1])
            {
                q++;
            }
            if (q == n - 1)
            {
                return(-1);
            }

            r += q - i + 1;
            s.RemoveAt(q);
            s.RemoveAt(q);
            s.Insert(i, !v);
            s.Insert(i, !v);
        }

        if (!s.SequenceEqual(t))
        {
            throw new InvalidOperationException();
        }

        return(r);
    }
Ejemplo n.º 14
0
 public Domain(string name, IEnumerable <string> values) : base(name)
 {
     Values = new IndexedList <IndexedNamedItem>();
     if (values != null)
     {
         foreach (var value in values)
         {
             Values.Add(new IndexedNamedItem(value));
         }
     }
 }
Ejemplo n.º 15
0
        public SplitArray(int sizeX, int sizeY)
        {
            LengthX = sizeX;
            LengthY = sizeY;
            _nodes  = new IndexedList <T[]>(sizeX);

            for (int ix = 0; ix < sizeX; ++ix)
            {
                _nodes.Add(new T[sizeY]);
            }
        }
		public void should_be_able_to_get_an_item_using_an_index()
		{
			var sut = new IndexedList<ShopItem>();
			
			var item = new ShopItem { Id = 1, Name = "Megaphone", Price = 200m }; 
			
			sut.Add(item);

			var result = sut.GetItem(0);

			Assert.That(result, Is.EqualTo(item));
		}
Ejemplo n.º 17
0
        public void Load(List <ModuleDefinition> modules)
        {
            var types = modules.SelectMany(x => x.Types).Where(x => x.Interfaces.Any()).ToList();

            foreach (var typeDefinition in types)
            {
                foreach (var interfce in typeDefinition.Interfaces)
                {
                    _typesByInterfaceImplemented.Add(interfce.InterfaceType.GetKey(), typeDefinition);
                }
            }
        }
Ejemplo n.º 18
0
        public static void CompareValue <T>(T val1, T val2, string propName, IndexedList <Variance> newVariances)
        {
            var v = new Variance
            {
                Name = propName,
                valA = val1,
                valB = val2
            };

            if (v.valA == null && v.valB == null)
            {
                return;
            }

            if (v.valA == null || v.valB == null)
            {
                newVariances.Add(v);
            }
            else if (!v.valA.Equals(v.valB))
            {
                newVariances.Add(v);
            }
        }
Ejemplo n.º 19
0
        public void should_be_able_to_get_an_item_using_an_index()
        {
            var sut = new IndexedList <ShopItem>();

            var item = new ShopItem {
                Id = 1, Name = "Megaphone", Price = 200m
            };

            sut.Add(item);

            var result = sut.GetItem(0);

            Assert.That(result, Is.EqualTo(item));
        }
Ejemplo n.º 20
0
        public void Add(Position position)
        {
            if (!_deviceCache.DeviceExists(position.Imei, out var device))
            {
                return;
            }

            // ignore disabled device positions
            if (!device.Enabled)
            {
                return;
            }

            _positions.Add(position.Imei, position);
            RaiseOnPositionRegistered(new PositionAddedEventArgs(position.Imei, position));
        }
Ejemplo n.º 21
0
        private void IndexDelegateInvocation(Instruction instruction, MethodReference invokedDelegate, MethodDefinition parentMethod)
        {
            //var instructionKey = InstructionKeyService.GetInstructionKey(instruction, parentMethod);
            var targetKey = invokedDelegate.DeclaringType.GetKey() + "::.ctor(System.Object,System.IntPtr)>>1";

            var assignmentTrees = _assignmentGraphWalker.PerformBacktrackingSearch(instruction,
                                                                                   parentMethod,
                                                                                   new DefaultSourceDetector(new HashSet <string>()
            {
                targetKey
            }),
                                                                                   new List <GoToInstancePattern>()
            {
                new GoToInstancePattern()
                {
                    TypeMustHavePattern   = invokedDelegate.DeclaringType.FullName,
                    MemberMustHavePattern = "Invoke",
                    TryInstance           = TryInstance.Only
                }
            },
                                                                                   new List <string>());

            foreach (var result in assignmentTrees)
            {
                foreach (var node in result.FoundNodes)
                {
                    if (node.Triple.From.Instruction.OpCode.Name == "ldvirtftn")
                    {
                        var methodRef = (MethodReference)node.Triple.From.Instruction.Operand;
                        MethodDefinition assignedMethod = null;
                        var resolved = ResolveService.TryResolve(methodRef, out assignedMethod);
                        if (resolved)
                        {
                            var indexedDelegate = new IndexedDelegate();
                            indexedDelegate.AssignedMethod = assignedMethod;
                            indexedDelegate.MethodAssignmentInstruction = node.Triple.From.Instruction;
                            string key = GetDelegateKey(parentMethod, invokedDelegate);
                            _delegateMethods.Add(key, indexedDelegate);
                        }
                    }
                }
            }
        }
Ejemplo n.º 22
0
        public void TestAddNullKey()
        {
            IndexedList<string, SiteLink> list = new IndexedList<string, SiteLink>(siteLink => siteLink.SiteId) {
                new SiteLink("enwiki", "Foo")
            };

            Assert.Throws<ArgumentNullException>(() => list.Add(new SiteLink()));
        }
Ejemplo n.º 23
0
 private void AddLexerRule(ILexerRule lexerRule)
 {
     _lexerRules.Add(lexerRule);
 }
Ejemplo n.º 24
0
        public void Test1()
        {
            var list = new IndexedList <ItemMetadata>();

            list.AddIndex("BlobRef", (item) => item.BlobRef);
            list.AddIndex("Name", (item) => item.Name);
            list.AddIndex("Value", (item) => item.Value);

            var rand = new Random(2654);

            var chances = new List <int> {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3
            };
            var tags = new Dictionary <string, List <string> >();

            tags.Add("Tag", new List <string> {
                "Cuba", "pool", "beach", "kids"
            });
            tags.Add("Camera", new List <string> {
                "AndrewsPhone", "JosPhone", "LydiasPhone", "AllansCamera", "PoolesCamera", "JosPhone", "LydiasPhone", "AllansCamera", "PoolesCamera", "JosPhone", "LydiasPhone", "AllansCamera", "PoolesCamera"
            });

            var rememberedBlobRef = "";

            var sw = new Stopwatch();

            sw.Start();

            for (var i = 1; i <= 1_000_000; ++i)
            {
                var blobRef = Guid.NewGuid().ToString();
                list.Add(new ItemMetadata()
                {
                    BlobRef = blobRef,
                    Name    = "BlobRef",
                    Value   = $"{DateTime.UtcNow.AddDays(rand.Next(-10, 20)).AddHours(rand.Next(-20, 20))}"
                });

                // remember a random blobRef for lookup later
                if (i == 1000)
                {
                    rememberedBlobRef = blobRef;
                }

                var randomWeightedChance = chances[rand.Next(0, chances.Count)];
                for (var j = 0; j < randomWeightedChance; j++)
                {
                    var randomTag      = tags.ElementAt(rand.Next(0, tags.Count));
                    var randomTagValue = randomTag.Value.ElementAt(rand.Next(0, randomTag.Value.Count));

                    list.Add(new ItemMetadata()
                    {
                        BlobRef = blobRef,
                        Name    = randomTag.Key,
                        Value   = randomTagValue
                    });
                }
            }

            var elapsed = sw.Elapsed.TotalMilliseconds;

            Debug.WriteLine($"list loaded {elapsed}ms");
            Assert.That(list.Count, Is.EqualTo(1_239_040));
            sw.Restart();

            var foundBlobRefMatches = list.FindBySingleIndex(new IndexSearch("BlobRef", rememberedBlobRef));

            elapsed = sw.Elapsed.TotalMilliseconds;
            Debug.WriteLine($"lookup via blobRef index should return at least 1 item in {elapsed}ms");
            Assert.That(foundBlobRefMatches.Count(), Is.EqualTo(1));
            sw.Restart();

            var allitemsWithNameTag = list.FindBySingleIndex(new IndexSearch("Name", "Tag"));

            elapsed = sw.Elapsed.TotalMilliseconds;
            Debug.WriteLine($"indexed search of all items with a Name:Tag in {elapsed}ms");
            Assert.That(allitemsWithNameTag.Count(), Is.EqualTo(119_587));
            sw.Restart();

            var allitemsWithNameAndValue = list.FindByIntersection(new IndexSearch("Name", "Camera"), new IndexSearch("Value", "AndrewsPhone"));

            elapsed = sw.Elapsed.TotalMilliseconds;
            Debug.WriteLine($"indexed search of all items with Name:Tag and Value: in {elapsed}ms");
            Assert.That(allitemsWithNameAndValue.Count(), Is.EqualTo(9321));
            sw.Restart();

            var allitemsWithNameBlobRef = list.FindByIndexEvaluateValues(new IndexSearch("Name", "BlobRef"), (v) => (DateTime.Parse(v.Value).Day == DateTime.UtcNow.Day));

            elapsed = sw.Elapsed.TotalMilliseconds;
            Debug.WriteLine($"indexed search via Name AND Value matching an evaluated predicate {elapsed}ms");
            Assert.That(allitemsWithNameBlobRef.Count(), Is.EqualTo(33_166));
        }
Ejemplo n.º 25
0
 public int Add(TValue value)
 {
     return(list.Add(value));
 }