public void BinarySearch_Equal() { var list = TypicalSortedList(); var result = ListExt.BinarySearch(list, MEDIUM); Assert.Equal(1, result); }
/// <summary> /// set un nouveau collider dans l'array /// </summary> private void SetNewCollider(Vector3 otherNormal) { otherNormal = otherNormal.normalized; if (ListExt.IsInArray(colliderNormalArray, otherNormal)) { return; } //avant de commencer, vérifie encore si il y a une normal identique for (int i = 0; i < colliderNormalArray.Length; i++) { if (UtilityFunctions.IsClose(colliderNormalArray[i].x, otherNormal.x, debugCloseValueNormal) && UtilityFunctions.IsClose(colliderNormalArray[i].y, otherNormal.y, debugCloseValueNormal)) { //Debug.Log("trop proche d'une autre !"); return; } } for (int i = 0; i < colliderNormalArray.Length; i++) { if (colliderNormalArray[i] == Vector3.zero) { colliderNormalArray[i] = otherNormal; return; } } }
public void BinarySearch_FromLowest() { var list = TypicalSortedList(); var result = ListExt.BinarySearch(list, TOO_LOW); Assert.Equal(~0, result); }
public void BinarySearch_None() { var list = TypicalSortedList(); var result = ListExt.BinarySearch(list, TOO_HIGH); Assert.Equal(~3, result); }
/// <summary>Quickly makes a copy of a list, as an array, in random order.</summary> public static T[] Randomized <T>(this IList <T> list) { T[] copy = new T[list.Count]; list.CopyTo(copy, 0); ListExt.Randomize(copy); return(copy); }
public static void AddRolePairFightCount(KuaFu5v5FuBenData KuaFu5v5FuBenData) { int roleId = 0; int roleId2 = 0; if (KuaFu5v5FuBenData.ZhanDuiDict.Count >= 2) { foreach (int id in KuaFu5v5FuBenData.ZhanDuiDict.Keys) { if (roleId == 0) { roleId = id; } else { roleId2 = id; } } long rolePairKey = ListExt.MakeRolePairKey(roleId, roleId2); lock (TianTi5v5Service.RolePairFightCountDict) { int fightCount; if (!TianTi5v5Service.RolePairFightCountDict.TryGetValue(rolePairKey, out fightCount)) { TianTi5v5Service.RolePairFightCountDict[rolePairKey] = 1; } else { TianTi5v5Service.RolePairFightCountDict[rolePairKey] = fightCount + 1; } } } }
public void BinarySearch_Typical() { var list = TypicalSortedList(); var result = ListExt.BinarySearch(list, TYPICAL_NOT_EXISTS); Assert.Equal(~2, result); }
public void TestAddRange() { var list = _newList(); list.AddRange(Range.Inclusive(1, 3)); list.AddRange(Enumerable.Range(5, 3)); ExpectList(list, 1, 2, 3, 5, 6, 7); list.AddRange(Range.Inclusive(10, 11)); list.AddRange(Enumerable.Range(20, 2)); ExpectList(list, 1, 2, 3, 5, 6, 7, 10, 11, 20, 21); list.AddRange(Range.Inclusive(30, 30)); list.AddRange(Enumerable.Range(40, 1)); ExpectList(list, 1, 2, 3, 5, 6, 7, 10, 11, 20, 21, 30, 40); list.AddRange(Range.ExcludeHi(0, 0)); list.AddRange(Enumerable.Repeat(0, 0)); ExpectList(list, 1, 2, 3, 5, 6, 7, 10, 11, 20, 21, 30, 40); list.AddRange(Range.Only(-99)); if (list.First() == -99) { // It's a sorted list. list.AddRange(ListExt.Single(4)); ExpectList(list, -99, 1, 2, 3, 4, 5, 6, 7, 10, 11, 20, 21, 30, 40); list.AddRange(Enumerable.Range(-2, 3)); ExpectList(list, -99, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 20, 21, 30, 40); list.AddRange(Enumerable.Range(12, 8)); ExpectList(list, -99, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 30, 40); } else { ExpectList(list, 1, 2, 3, 5, 6, 7, 10, 11, 20, 21, 30, 40, -99); } }
/// <summary> /// Extended set foreground color. /// </summary> /// <param name="a">2;r;g;b | 5;clr.</param> private static void FrClr1Ex(IList <string> a) { int n = ValExt.Int(a, 1); int FrClr = n == 2 ? Cmd.RgbColor(ValExt.Int(a, 2), ValExt.Int(a, 3), ValExt.Int(a, 4)) : (ValExt.Int(a, 1) & 0xF); Cmd.ForegroundColor = (FrClr | Bld) & Lght; ListExt.ShiftN(a, 4); }
/// <summary> /// Extended set background color. /// </summary> /// <param name="a">2;r;g;b | 5;clr.</param> private static void BckClr1Ex(IList <string> a) { int n = ValExt.Int(a, 1); int c = n == 2 ? Cmd.RgbColor(ValExt.Int(a, 2), ValExt.Int(a, 3), ValExt.Int(a, 4)) : (ValExt.Int(a, 2) & 0xF); Cmd.BackgroundColor = c; ListExt.ShiftN(a, 5); }
private void AddShapeCore(Shape newShape, bool @do) { newShape.OnBeingAdded(this); _core.Shapes.Add(newShape); if (AfterShapesAdded != null && @do) { AfterShapesAdded(ListExt.Single(newShape)); } }
public static LNode use_symbols(LNode input, IMacroContext context) { var args_body = context.GetArgsAndBody(true); // Decode options (TODO: invent a simpler approach) string prefix = "sy_"; var inherited = new HashSet <Symbol>(); foreach (var pair in MacroContext.GetOptions(args_body.A)) { if (pair.Key.Name == "prefix" && pair.Value.IsId) { prefix = pair.Value.Name.Name; } else if (pair.Key.Name == "inherit" && pair.Value.Value is Symbol) { inherited.Add((Symbol)pair.Value.Value); } else if (pair.Key.Name == "inherit" && (pair.Value.Calls(S.Braces) || pair.Value.Calls(S.Tuple)) && pair.Value.Args.All(n => n.Value is Symbol)) { foreach (var arg in pair.Value.Args) { inherited.Add((Symbol)arg.Value); } } else { context.Sink.Write(Severity.Warning, pair.Value, "Unrecognized parameter. Expected prefix:id or inherit:{@@A; @@B; ...})"); } } // Replace all symbols while collecting a list of them var symbols = new Dictionary <Symbol, LNode>(); VList <LNode> output = args_body.B.SmartSelect(stmt => stmt.ReplaceRecursive(n => { var sym = n.Value as Symbol; if (n.IsLiteral && sym != null) { return(symbols[sym] = LNode.Id(prefix + EcsNodePrinter.SanitizeIdentifier(sym.Name))); } return(null); })); // Return updated code with variable declaration at the top for all non-inherit symbols used. var _Symbol = F.Id("Symbol"); var vars = (from sym in symbols where !inherited.Contains(sym.Key) select F.Call(S.Assign, sym.Value, F.Call(S.Cast, F.Literal(sym.Key.Name), _Symbol))).ToList(); if (vars.Count > 0) { output.Insert(0, F.Call(S.Var, ListExt.Single(_Symbol).Concat(vars)) .WithAttrs(input.Attrs.Add(F.Id(S.Static)).Add(F.Id(S.Readonly)))); } return(F.Call(S.Splice, output)); }
public virtual IList Execute(CommandContext commandContext) { EnsureUtil.EnsureNotNull("deploymentId", DeploymentId); foreach (var checker in commandContext.ProcessEngineConfiguration.CommandCheckers) { checker.CheckReadDeployment(DeploymentId); } return(ListExt.ConvertToIlist(context.Impl.Context.CommandContext.ResourceManager.FindResourcesByDeploymentId(DeploymentId))); }
public void BinarySearch_EqualWithOne() { var list = new List <int>() { MEDIUM }; var result = ListExt.BinarySearch(list, MEDIUM); Assert.Equal(0, result); }
public virtual IList <T> GetDeployedArtifacts <T>(Type clazz) { if (deployedArtifacts == null) { return(null); } else { return(ListExt.ConvertToListT <T>(deployedArtifacts[clazz])); } }
public static decimal MySum(object value) { if (!ListExt.IsList(value)) { return(Stimulsoft.Base.Helpers.StiValueHelper.TryToDecimal(value)); } return(Stimulsoft.Data.Functions.Funcs.SkipNulls(ListExt.ToList(value)) .TryCastToDecimal() .Sum()); }
private int GetBlockIndex(int charIndex) { int i = ListExt.BinarySearch((IList <Pair <int, uint> >) _blkOffsets, new Pair <int, uint>(charIndex, 0), delegate(Pair <int, uint> a, Pair <int, uint> b) { return(a.A.CompareTo(b.A)); }); if (i < 0) { i = ~i - 1; } return(i); }
private async void GenegateField() { this.Items = new ListExt <BaseElem>(); List <int> tmp_count = new List <int>(); await Task.Run(() => { for (int h = 0; h < this.Height; h++) { for (int w = 0; w < this.Width; w++) { Coord tmp = new Coord(w, h); this.Items.Add(this.BindElem(new EmptyElem(tmp))); tmp_count.Add(this.Decrypt(tmp)); } } }); await Task.Run(() => { for (int j = 0; j < 9; j++) { for (int i = 0, b = this.Width * this.Height; i < this.Width * this.Height; i++, b--) { int rand = new Random().Next(b); int save = tmp_count[rand]; tmp_count[rand] = tmp_count[b - 1]; tmp_count[b - 1] = save; } } }); List <int> tmp_list = new List <int>(); await Task.Run(() => { for (int i = 0; i < this.Bombs; i++) { App.Current.Dispatcher.Invoke((Action) delegate { int index = i * ((this.Width * this.Height) / this.Bombs); if (index >= (this.Width * this.Height) && index < 0) { index = (this.Width * this.Height) - 1; } this.Items[tmp_count[index]] = this.BindElem(new BombElem(this.Items[tmp_count[index]].Coordinats)); }); } }); this.OnPropertyChanged("Items"); }
/// <summary> /// ici reset tout à false /// </summary> private void ResetNormalAndCollision() { ListExt.ClearArray(colliderNormalArray); ListExt.ClearArray(objectInCollision); if (collisionType != CollisionType.InAir) { lastCollisionTypePersist = collisionType; normalSumCollidePrevious = normalSumCollide; } collisionType = CollisionType.InAir; }
public void AddShape(Shape newShape) { _undoStack.Do(@do => { if (@do) { AddShapeCore(newShape, true); } else { RemoveShapesCore(ListExt.Single(newShape), @do); } }, true); }
public override void Insert(int index, T item) { if ((uint)index > (uint)_list.Count) { throw new ArgumentOutOfRangeException("index"); } if (_owner != null) { var chgList = ListExt.Single(item); _owner.OnListChanging(this, new ListChangeInfo <T>(NotifyCollectionChangedAction.Add, index, 1, chgList)); } _list.Insert(index, item); }
public void Resize(int newSize) { int count = this.Count; if (newSize < count) { this.RemoveRange(newSize, count - newSize); } else if (newSize > count) { this.InsertRange(count, (IListSource <T>)ListExt.Repeat(default(T), newSize - count)); } }
public virtual void InsertRange(int index, IEnumerable <T> items) { var items2 = items as IReadOnlyCollection <T>; if (items2 != null) { ListExt.InsertRange(this, index, items2); } else { ListExt.InsertRange(this, index, items.Buffered()); } }
public override bool TrySet(int index, T value) { if ((uint)index < (uint)_list.Count) { if (_owner != null) { var chgList = ListExt.Single(value); _owner.OnListChanging(this, new ListChangeInfo <T>(NotifyCollectionChangedAction.Replace, index, 0, chgList)); } return(_list.TrySet(index, value)); } return(false); }
public static bool CanAddFuBenRole(int x, int y) { long rolePairKey = ListExt.MakeRolePairKey(x, y); lock (TianTi5v5Service.RolePairFightCountDict) { int fightCount; if (!TianTi5v5Service.RolePairFightCountDict.TryGetValue(rolePairKey, out fightCount) || fightCount < TianTi5v5Service.Persistence.MaxRolePairFightCount) { return(true); } } return(false); }
public async Task EmptyRun() { using var tmpFolder = Utility.GetTempFolder(); using var dataFolder = Utility.SetupDataFolder(tmpFolder, GameRelease.Oblivion); var output = Utility.TypicalOutputFile(tmpFolder); await Runner.Run( workingDirectory : tmpFolder.Dir.Path, outputPath : output, dataFolder : dataFolder.Dir.Path, loadOrder : Utility.TypicalLoadOrder(GameRelease.Oblivion, dataFolder.Dir), release : GameRelease.Oblivion, patchers : ListExt.Empty <IPatcherRun>()); Assert.False(File.Exists(output)); }
/// <summary> /// set un nouveau gameObject dans l'array /// </summary> /// <param name="other"></param> private void SetNewObjectCollision(GameObject other) { //ne rien faire si l'objet est déja dans la list if (ListExt.IsInArray(objectInCollision, other)) { return; } //charcher un emplacement vide for (int i = 0; i < colliderNormalArray.Length; i++) { if (objectInCollision[i] == null) { objectInCollision[i] = other; return; } } }
public override IEnumerable <ITask> Prerequisites(IEnumerable <ITask> concurrentTasks) { var clash = concurrentTasks.FirstOrDefault(task => { // no clash if different AppDomain (we can't access private members across domains anyway) if (RemotingServices.IsTransparentProxy(task)) { return(false); } var utt = task as UnitTestTask; return(utt != null && utt._instance == _instance); }); if (clash == null) { return(null); } return(ListExt.Single(clash)); }
internal void addTask(TaskWrapper taskWrapper) { if (taskWrapper.Periodic > 0) { lock (PreiodictTaskList) { ListExt.BinaryInsertAsc(PreiodictTaskList, taskWrapper, taskWrapper); } } else { lock (TaskQueue) { TaskQueue.AddLast(taskWrapper); taskWrapper.canExecute = true; } } }
public void Sort(int index, int count, Comparison <T> comp) { Debug.Assert((uint)index <= (uint)_count); Debug.Assert((uint)count <= (uint)_count - (uint)index); if (!IsDivided) { InternalList.Sort(_array, _start + index, count, comp); } else if (index == 0 && count == Count) { Sort(comp); } else { // Use a slower IList<T> sort because the array sort requires contiguous input ListExt.Sort(AsDList(), index, count, comp); } }