Example #1
1
        private static IList<int> Merge(IList<int> left, IList<int> right)
        {
            var result = new List<int>();

            while (left.Any() && right.Any())
            {
                if (left[0] < right[0])
                {
                    result.Add(left[0]);
                    left.Remove(left[0]);
                }
                result.Add(right[0]);
                right.Remove(right[0]);
            }

            while (left.Any())
            {
                result.Add(left[0]);
                left.Remove(left[0]);
            }
            while (right.Any())
            {
                result.Add(right[0]);
                right.Remove(right[0]);
            }

            return result;
        }
 protected static void GuerillaPreProcessMethod(BinaryReader binaryReader, IList<tag_field> fields)
 {
     var field = fields.Last(x => x.type != field_type._field_terminator);
     fields.Remove(field);
     field = fields.Last(x => x.type != field_type._field_terminator);
     fields.Remove(field);
 }
        public BidType AskForBid(Contract currentContract, IList<BidType> allowedBids, IList<BidType> previousBids)
        {
            if (this.AlwaysPass)
            {
                return BidType.Pass;
            }

            allowedBids.Remove(BidType.Double);
            allowedBids.Remove(BidType.ReDouble);
            return allowedBids.RandomElement();
        }
Example #4
1
 public IList<ClusterPrototype> MergeClustersIfRequired(IList<ClusterPrototype> clusters)
 {
     var clustersToIterateOver = new List<ClusterPrototype>(clusters);
     foreach (var cluster in clustersToIterateOver) {
         foreach (var otherCluster in new List<ClusterPrototype>(clusters)) {
             if (cluster != otherCluster && this.IsMergeRequired(cluster, otherCluster)) {
                 clusters.Remove(cluster);
                 clusters.Remove(otherCluster);
                 clusters.Add(ClusterPrototype.Merge(cluster, otherCluster));
             }
         }
     }
     return clusters;
 }
Example #5
1
 public static bool remove(IList collection, object value)
 {
     bool b = collection.Contains(value);
     if (b)
         collection.Remove(value);
     return b;
 }
 private void ProcessFactories(XmlNode node, IList factories)
 {
    foreach ( XmlNode child in node.ChildNodes )
    {
       Type type;
       switch ( child.LocalName )
       {
       case "add":
          type = Type.GetType(child.Attributes["type"].Value);
          if ( !factories.Contains(type) )
             factories.Add(type);
          break;
       case "remove":
          type = Type.GetType(child.Attributes["type"].Value);
          if ( factories.Contains(type) )
             factories.Remove(type);
          break;
       case "clear":
          factories.Clear();
          break;
       default:
          // gives obsolete warning but needed for .NET 1.1 support
          throw new ConfigurationException(string.Format("Unknown element '{0}' in section '{0}'", child.LocalName, node.LocalName));
       }
    }
 }
Example #7
1
        IEnumerable<ModuleDefMD> SortGraph(IEnumerable<ModuleDefMD> roots, IList<DependencyGraphEdge> edges)
        {
            var visited = new HashSet<ModuleDefMD>();
            var queue = new Queue<ModuleDefMD>(roots);
            do {
                while (queue.Count > 0) {
                    var node = queue.Dequeue();
                    visited.Add(node);

                    Debug.Assert(!edges.Where(edge => edge.To == node).Any());
                    yield return node;

                    foreach (DependencyGraphEdge edge in edges.Where(edge => edge.From == node).ToList()) {
                        edges.Remove(edge);
                        if (!edges.Any(e => e.To == edge.To))
                            queue.Enqueue(edge.To);
                    }
                }
                if (edges.Count > 0) {
                    foreach (var edge in edges) {
                        if (!visited.Contains(edge.From)) {
                            queue.Enqueue(edge.From);
                            break;
                        }
                    }
                }
            } while (edges.Count > 0);
        }
Example #8
1
 public static void RemoveMany(IList list, IEnumerable itemsToRemove)
 {
     foreach (var item in itemsToRemove)
     {
         list.Remove(item);
     }
 }
Example #9
1
        private static void CheckActionList(IList<IBfsAction> actions, IBfsDataBlock block)
        {
            if (actions == null)
                return;

            for( int index = 0; index < actions.Count; index++)
            {
                IBfsAction action = actions[index];

                if (action is BfsActionUnresolvedAssignment)
                {
                    BfsActionUnresolvedAssignment unresolved = action as BfsActionUnresolvedAssignment;
                    BfsActionAssignment assignment = new BfsActionAssignment();
                    assignment.Expression = unresolved.Expression;
                    assignment.SourceRange = unresolved.SourceRange;
                    if (block.LocalFields.ContainsKey(unresolved.UnresolvedVariableName))
                        assignment.LocalVariable = block.LocalFields[unresolved.UnresolvedVariableName];
                    else
                        BfsCompiler.ReportError(assignment.SourceRange,
                            "Could not find local variable: '"+unresolved.UnresolvedVariableName+"'");

                    actions.Insert(index, assignment);
                    actions.Remove(action);
                }
            }
        }
Example #10
1
        private static void LargestStock(IList<double> cuts, IList<Board> stockList)
        {
            var longest = stockList.OrderByDescending(x => x.Length).First();
            var longestBoard = longest.Length;
            var boardCost = longest.Price;

            var scraps = new List<double>();
            var stockUsed = new List<Board>();

            while (cuts.Any())
            {
                var longestCut = cuts.OrderByDescending(x => x).First();
                cuts.Remove(longestCut);
                if (scraps.Any(x => x > longestCut))
                {
                    scraps = scraps.CutFromScrap(longestCut);
                }
                else
                {
                    stockUsed.Add(longest);
                    scraps.Add(longestBoard - longestCut - kerf);
                }
            }

            Console.WriteLine("Total number of boards used: {0}", stockUsed.Count());
            Console.WriteLine("Total Cost: {0}", stockUsed.Count() * boardCost);
            OutputWaste(scraps, stockUsed.Count() * longestBoard);
        }
Example #11
1
        // when a ball hits an enemy both are destroyed
        public bool FireballEnemyCollisionTest(IList<IEnemy> enemies)
        {
            Rectangle fbRectangle = fireball.GetRectangle();
            Rectangle enemyRectangle;
            Rectangle intersectionRectangle;

            Queue<IEnemy> doomedEnemies = new Queue<IEnemy>();

            foreach (IEnemy enemy in enemies)
            {
                enemyRectangle = enemy.GetRectangle();
                intersectionRectangle = Rectangle.Intersect(fbRectangle, enemyRectangle);

                if (!intersectionRectangle.IsEmpty)
                {
                    // hud score method needed
                    doomedEnemies.Enqueue(enemy);
                }
            }

            while (doomedEnemies.Count() > 0)
            {
                IEnemy e = doomedEnemies.Dequeue();
                enemies.Remove(e);
                return true;
            }
            return false;
        }
Example #12
1
        public RTAAPrefixPresenter(IRealTimeAdherenceModel model)
        {
            _model = model;
            _newAddedSet = new List<AdherenceEvent>(50);
            _removedSet = new List<AdherenceEvent>(50);
            WhenAdding = o =>
                             {
                                 IsDirty = true;
                                 var e = new AdherenceEvent
                                             {
                                                 Text = o.Text,
                                                 Start = o.Start.RemoveSeconds(),
                                                 End = o.End.Second == 0 ? o.End : o.End.AddSeconds(60 - o.End.Second),
                                                 Remark = "added",
                                                 Reason = SelectedAbsence
                                             };

                                 _newAddedSet.Add(e);
                                 return e;
                             };
            WhenChanged = o =>
                              {
                                  IsDirty = true;
                              };
            WhenRemoving = o =>
                               {
                                   IsDirty = true;
                                   _newAddedSet.Remove(o);
                                   _removedSet.Add(o);
                               };
        }
Example #13
1
        public static void CalculateTime(IList list, int k)
        {
            // Add
            var startAdding = DateTime.Now;
            string test = "Test string";
            for (int i = 0; i < k; i++)
            {
                list.Add(test);
            }
            var finishAdding = DateTime.Now;
            Console.WriteLine("Addition time (" + k + " elements) : " + list.GetType() + "  " + (finishAdding - startAdding));
            // Search
            var startSearch = DateTime.Now;
            for (int i = 0; i < k; i++)
            {
                bool a = list.Contains(test);
            }
            var finishSearch = DateTime.Now;
            Console.WriteLine("Search time (" + k + " elements) : " + list.GetType() + "  " + (finishSearch - startSearch));

            // Remove
            k = 1000;
            var startRemoving = DateTime.Now;
            for (int i = 0; i < k; i++)
            {
                list.Remove(test);
            }
            var finishRemoving = DateTime.Now;
            Console.WriteLine("Removal time (" + k + " elements) : " + list.GetType() + "  " + (finishRemoving - startRemoving) + "\n");
        }
Example #14
1
        public static IList<int> Merge(IList<int> left, IList<int> right)
        {
            IList<int> result = new List<int>();

            while (left.Any() && right.Any())
            {
                if (left[0] < right[0])
                {
                    result.Add(left[0]);
                    left.Remove(left[0]);
                }
                else
                {
                    result.Add(right[0]);
                    right.Remove(right[0]);
                }
            }

            while (left.Any())
            {
                result.Add(left[0]);
                left.RemoveAt(0);
            }
            while (right.Any())
            {
                result.Add(right[0]);
                right.RemoveAt(0);
            }

            return result;
        }
Example #15
0
        public List<PropertySpecification> ParseColumns(ref IList<string> rows)
        {
            // pick off the heading line
            string line0 = rows[0];
            var headings = rows[0].Split(',');
            rows.Remove(line0);

            List<PropertySpecification> propertySpecs = new List<PropertySpecification>();


            int rownum = 0;
            foreach (var line in rows)
            {
                if (line.Trim().Length == 0)
                    continue;
                var row = SplitLine(line);
                for (var columnid = 0; columnid < headings.Length; columnid++)
                {
                    try
                    {
                        string contents = row[columnid].Replace("\"", "");
                        var deduced = InferType(ColumnTypeCreate(contents));
                        PropertySpecification spec = propertySpecs.FirstOrDefault(s => s.Id == columnid);
                        if (spec == null)
                        {
                            propertySpecs.Add(new PropertySpecification
                            {
                                ColumnName = headings[columnid].Replace('"', ' ').Replace("/", string.Empty),
                                Id = columnid,
                                ColumnType = deduced,
                                Nullable = CheckForNullable(contents, deduced)
                            });
                        }
                        else
                        {
                            // elevate the type
                            if (spec.ColumnType < deduced && spec.ColumnType != CTEnum.String)
                            {
                                spec.ColumnType = deduced;
                            }
                            if (!spec.Nullable)
                            {
                                if (deduced != CTEnum.String && contents.Length == 0)
                                    Debug.WriteLine("Should be true");
                                spec.Nullable = CheckForNullable(contents, deduced);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        throw new Exception(string.Format("{0} - Row {1} - Column {2} - Value {3}", e.Message, line, rownum, row[columnid]));
                    }
                }
                rownum++;
                if (rownum == 57)
                    System.Diagnostics.Debug.WriteLine("56");
            }

            return propertySpecs;
        }
        public PartialViewResult EditContactClosedFilter(IList<ContactFilter> filters, ContactClosedFilter filter)
        {
            filters.Remove(filters.FirstOrDefault(cf => cf.Id == filter.Id));

            filters.Add(filter);
            return PartialView("DisplayTemplates/contactClosedFilter", filter);
        }
Example #17
0
        public override void Initialize()
        {
            _notes = new List<string>();
              _lock = new object();

              // homepage
              Get("/", fu.Static.File("index.html"));
              Get("/site.js", fu.Static.File("site.js"));

              // notes API
              Get("/notes", c => new JsonResult(_notes));

              Put("/notes", c =>
              {
            var note = c.Get<IFormData>()["note"];

            _notes.Add(note);
            return new JsonResult(note);
              });

              Delete("/notes/(.+)", c =>
              {
            var note = c.Match.Groups[1].Value;
            _notes.Remove(note);

            return new JsonResult(new { ok = true });
              });
        }
 public IList<IExecutableTask> ExtractTasksToHandle(ref IList<IExecutableTask> list)
 {
     List<IExecutableTask> executableTasks = list.Where(task => task is IUniversalSearchIndexTask).ToList();
     foreach (IExecutableTask executableTask in executableTasks)
         list.Remove(executableTask);
     return executableTasks;
 }
Example #19
0
        public Tuple<int, bool> EnemyCollisionTest(Luigi luigi, HUD hud, IList<IEnemy> enemies, int x, SoundEffects sound)
        {
            Rectangle luigiRectangle = myLuigi.GetRectangle();
            Rectangle enemyRectangle;
            bool enemyKilled = false;
            bool invincible = myLuigi.Invincible();
            int xpos = x;
            Rectangle intersectionRectangle;
            Queue<IEnemy> doomedEnemies = new Queue<IEnemy>();

            foreach (IEnemy enemy in enemies)
            {

                enemyRectangle = enemy.GetRectangle();
                intersectionRectangle = Rectangle.Intersect(luigiRectangle, enemyRectangle);

                if (!intersectionRectangle.IsEmpty)
                {

                    if (intersectionRectangle.Width >= intersectionRectangle.Height)
                    {
                        sound.Bump();
                        doomedEnemies.Enqueue(enemy);
                        hud.luigiEnemyKill(luigi);
                        enemyKilled = true;
                    }
                    else if (invincible)
                    {
                        doomedEnemies.Enqueue(enemy);
                    }
                    else
                    {
                        myLuigi.Hit();
                        if (luigiRectangle.X < enemyRectangle.X)
                        {
                            xpos = xpos - intersectionRectangle.Width;
                        }
                        else
                        {
                            xpos = xpos + intersectionRectangle.Width;

                        }
                        if (myLuigi.IsDead())
                        {
                            hud.lifeLostLuigi();
                        }
                    }

                }
            }

            while (doomedEnemies.Count() > 0)
            {
                IEnemy enemie = doomedEnemies.Dequeue();
                enemies.Remove(enemie);
            }

            return new Tuple<int,bool>(xpos, enemyKilled);
        }
Example #20
0
        public void ItemCollisionTest(SoundEffects sound, HUD hud, IList<IItem> items)
        {
            Rectangle luigiRectangle = myLuigi.GetRectangle();
            Rectangle itemRectangle;
            Rectangle intersectionRectangle;
            Queue<IItem> doomedItems = new Queue<IItem>();
            foreach (IItem item in items)
            {
                itemRectangle = item.GetRectangle();
                intersectionRectangle = Rectangle.Intersect(luigiRectangle, itemRectangle);
                if (!intersectionRectangle.IsEmpty)
                {
                    // todo
                    switch (item.GetItemName())
                    {
                        case "Coin":
                            //myLuigi.Coin();
                            hud.addCoinLuigi();
                            hud.increaseScoreLuigi(Constants.coinValue);
                            hud.achievements.CoinGet();
                            break;
                        case "Mushroom":
                            sound.Powerup();
                            myLuigi.Mushroom();
                            hud.increaseScoreLuigi(Constants.mushroomValue);
                            hud.achievements.MushroomGet();
                            break;
                        case "Fireflower":
                            sound.Powerup();
                            myLuigi.Fireflower();
                            hud.increaseScoreLuigi(Constants.fireflowerValue);
                            hud.achievements.FlowerGet();
                            break;
                        case "Oneup":
                            sound.OneUp();
                            hud.extraLifeLuigi();
                            hud.increaseScoreLuigi(Constants.oneUpValue);
                            break;
                        case "Star":
                            sound.Powerup();
                            myLuigi.Star();
                            hud.increaseScoreLuigi(Constants.starValue);
                            hud.achievements.StarGet();
                            break;
                        default:
                            // nothing
                            break;
                    }
                    doomedItems.Enqueue(item);

                }
            }
            while (doomedItems.Count() > 0)
            {
                IItem item = doomedItems.Dequeue();
                items.Remove(item);

            }
        }
        private void RmDir(string dirname, IList<Directory> directoryies)
        {
            var dirobj = directoryies.SingleOrDefault(dir => dir.Name.Equals(dirname));
            if(dirobj == null)
                new Exception("Directoryが存在しません");

            directoryies.Remove(dirobj);
        }
Example #22
0
		public static void Remove(IList<sFace> list,sFace face)
		{
			//if(face->l[1]) face->l[1]->l[0]=face->l[0];
			//if(face->l[0]) face->l[0]->l[1]=face->l[1];
			//if(face==list.root) list.root=face->l[1];
			//--list.count;
			list.Remove(face);
		}
Example #23
0
        public static object Poll(IList coll)
        {

            int idx = coll.Count - 1;
            object result = coll[idx];
            coll.Remove(idx);
            return result;
        }
        private void DealWithDisable(MonoBehaviour component, IList<RadicalCoroutine> lst)
        {
            if (lst.Count > 0)
            {
                var arr = lst.ToArray();
                var stoppableMode = (this.gameObject.activeInHierarchy) ? RadicalCoroutineDisableMode.StopOnDisable : RadicalCoroutineDisableMode.StopOnDeactivate;
                RadicalCoroutine routine;
                for (int i = 0; i < arr.Length; i++)
                {
                    routine = arr[i];
                    if (routine.DisableMode == RadicalCoroutineDisableMode.CancelOnDeactivate || routine.DisableMode.HasFlag(RadicalCoroutineDisableMode.CancelOnDisable))
                    {
                        routine.Cancel();
                        routine.OnFinished -= this.OnRoutineFinished;
                        lst.Remove(routine);
                    }
                    else
                    {
                        if (routine.DisableMode.HasFlag(stoppableMode))
                        {
                            routine.Stop();
                            if (routine.Finished)
                            {
                                routine.OnFinished -= this.OnRoutineFinished;
                                lst.Remove(routine);
                            }
                        }
                        if (!routine.DisableMode.HasFlag(RadicalCoroutineDisableMode.ResumeOnEnable))
                        {
                            routine.OnFinished -= this.OnRoutineFinished;
                            lst.Remove(routine);
                        }
                    }
                }
            }

            if(lst.Count == 0)
            {
                _routines.Remove(component);
                if(component is SPComponent)
                {
                    (component as SPComponent).OnEnabled -= this.OnComponentEnabled;
                    (component as SPComponent).OnDisabled -= this.OnComponentDisabled;
                }
            }
        }
        private static void DisposeFacelessFrames(IList<Frame> motionFrames, ImageProcess.Target[] portraits)
        {
            var noPortraitFrameQuery = from m in motionFrames
                                       where !portraits.Any(t => t.BaseFrame.guid.Equals(m.Guid))
                                       select m;

            Array.ForEach(noPortraitFrameQuery.ToArray(), mf => { motionFrames.Remove(mf); mf.Dispose(); });
        }
 public PartialViewResult EditContactReasonFilter(IList<ContactFilter> filters, ContactReasonFilter filter)
 {
     filters.Remove(filters.FirstOrDefault(cf => cf.Id == filter.Id));
     var contactReason = ContactReasons().FirstOrDefault(cr => cr.Value == filter.Value.ToString());
     filter.Description = contactReason.Text;
     filters.Add(filter);
     return PartialView("DisplayTemplates/contactReasonFilter", filter);
 }
Example #27
0
		/// <summary>
		/// Deletes an element from the datasource.
		/// </summary>
		/// <param name="table">The table from which the element should be deleted.</param>
		/// <param name="element">The element should be deleted.</param>
		public void DeleteElement(IList<XElement> table, XElement element)
		{
			//XElement orderToDelete = (from order in table
			//where order.Attribute(element.Attributes().FirstOrDefault().Name).Value == element.Attributes().FirstOrDefault().Value
			//select order).FirstOrDefault();
			table.Remove(element);
			//orderToDelete.Remove();
		}
Example #28
0
		void CheckPermissions(IList<NavigationItem> items)
		{
			for (int i = items.Count - 1; i >= 0; i--)
				if (!items[0].CheckPermission() || !HavePermission(items[i]))
					items.Remove(items[i]);
				else
					CheckPermissions(items[i].Childs);
		}
 private void Intersect(IList baseList, IList list)
 {
     foreach (string item in list)
     {
         if (baseList.Contains(item))
             baseList.Remove(item);
     }
 }
Example #30
0
 private void RemoveCategoryAndReorderSiblings(Category category, IList<Category> categories)
 {
     categories.Remove(category);
     for (int i = 0; i < categories.Count; i++)
     {
         categories[i].SetPosition(i);
     }
 }