public void CopyToTest() { var set = new IndexedSet <string>(); var array = new string[2]; Assert.IsEmpty(set); Assert.That(array, Is.All.Null); set.CopyTo(array, 0); Assert.IsEmpty(set); Assert.That(array, Is.All.Null); set.Add("A"); set.Add("B"); set.CopyTo(array, 0); Assert.That(set.Count, Is.EqualTo(2)); Assert.That(set, Contains.Item("A").And.Contains("B")); Assert.That(array.Length, Is.EqualTo(2)); Assert.That(array, Is.All.Not.Null); Assert.That(array, Contains.Item("A").And.Contains("B")); Assert.That(array[0], Is.EqualTo("A")); Assert.That(array[1], Is.EqualTo("B")); }
private void IndexedSetAdd() { for (int i = 0; i < count; i++) { indexedSet.Add(i); } }
static object Solve() { var n = int.Parse(Console.ReadLine()); var a = Read(); var qc = int.Parse(Console.ReadLine()); var qs = Array.ConvertAll(new bool[qc], _ => int.Parse(Console.ReadLine())); var set = new IndexedSet <int>(); foreach (var v in a) { set.Add(v); } set.Add(-1 << 30); set.Add(int.MaxValue); return(string.Join("\n", qs.Select(GetMin))); int GetMin(int bv) { var an2 = set.Root.SearchFirstNode(x => x >= bv); var an1 = an2.SearchPreviousNode(); return(Math.Min(an2.Item - bv, bv - an1.Item)); } }
public void AddTest() { var set = new IndexedSet <string>(); Assert.True(set.Add("A")); Assert.Contains("A", set); Assert.False(set.Add("A")); Assert.Contains("A", set); }
private static void Test2() { Random rand = new Random(0); int size = 20000; IndexedSet <int> set = new IndexedSet <int>(); HashSet <int> hashSet = new HashSet <int>(); List <int> list = new List <int>(); while (true) { set.Clear(); hashSet.Clear(); int n = rand.Next(100); for (int i = 0; i < n; i++) { int item = rand.Next(100); hashSet.Add(item); set.Add(item); } n = rand.Next(100); for (int i = 0; i < n; i++) { list.Add(rand.Next(100)); } try { hashSet.SymmetricExceptWith(list); set.SymmetricExceptWith(list); //Assert.Equal(set.Count, hashSet.Count); } catch (Exception ex) { } } }
public void Test1() { Random rand = new Random(0); int size = 20000; IndexedSet <int> set = new IndexedSet <int>(); HashSet <int> hashSet = new HashSet <int>(); List <int> list = new List <int>(); while (size-- > 0) { Debug.WriteLine(size); set.Clear(); hashSet.Clear(); list.Clear(); int n = rand.Next(100); for (int i = 0; i < n; i++) { int item = rand.Next(100); hashSet.Add(item); set.Add(item); } n = rand.Next(100); for (int i = 0; i < n; i++) { list.Add(rand.Next(100)); } hashSet.SymmetricExceptWith(list); set.SymmetricExceptWith(list); Assert.Equal(set.Count, hashSet.Count); } }
public void ExceptWithTest() { var firstSet = new IndexedSet <string>(); var secondSet = new IndexedSet <string>(); firstSet.Add("A"); secondSet.Add("A"); secondSet.Add("B"); secondSet.ExceptWith(firstSet); Assert.That(secondSet.Count, Is.EqualTo(1)); Assert.False(secondSet.Contains("A")); Assert.True(secondSet.Contains("B")); }
/// <summary> /// Associates a Graphic with a Canvas and stores this association in the registry. /// </summary> /// <param name="c">The canvas being associated with the Graphic.</param> /// <param name="graphic">The Graphic being associated with the Canvas.</param> public static void RegisterGraphicForCanvas(Canvas c, Graphic graphic) { if (c == null || graphic == null) { return; } IndexedSet <Graphic> graphics; instance.m_Graphics.TryGetValue(c, out graphics); if (graphics != null) { graphics.AddUnique(graphic); RegisterRaycastGraphicForCanvas(c, graphic); return; } // Dont need to AddUnique as we know its the only item in the list graphics = new IndexedSet <Graphic>(); graphics.Add(graphic); instance.m_Graphics.Add(c, graphics); RegisterRaycastGraphicForCanvas(c, graphic); }
public void UnionWithTest() { var firstSet = new IndexedSet <string>(); var secondSet = new IndexedSet <string>(); firstSet.UnionWith(secondSet); Assert.IsEmpty(firstSet); Assert.IsEmpty(secondSet); firstSet.Add("A"); firstSet.UnionWith(secondSet); Assert.That(firstSet.Count, Is.EqualTo(1)); Assert.That(firstSet[0], Is.EqualTo("A")); Assert.IsEmpty(secondSet); secondSet.Add("A"); firstSet.UnionWith(secondSet); Assert.That(firstSet.Count, Is.EqualTo(1)); Assert.That(firstSet[0], Is.EqualTo("A")); Assert.That(secondSet.Count, Is.EqualTo(1)); Assert.That(secondSet[0], Is.EqualTo("A")); secondSet.Add("B"); Assert.That(firstSet.Count, Is.EqualTo(1)); Assert.That(firstSet[0], Is.EqualTo("A")); Assert.That(secondSet.Count, Is.EqualTo(2)); Assert.That(secondSet[0], Is.EqualTo("A")); Assert.That(secondSet[1], Is.EqualTo("B")); firstSet.UnionWith(secondSet); Assert.That(firstSet.Count, Is.EqualTo(2)); Assert.That(firstSet[0], Is.EqualTo("A")); Assert.That(firstSet[1], Is.EqualTo("B")); Assert.That(secondSet.Count, Is.EqualTo(2)); Assert.That(secondSet[0], Is.EqualTo("A")); Assert.That(secondSet[1], Is.EqualTo("B")); }
private bool InternalRegisterCanvasElementForLayoutRebuild(ICanvasElement element) { if (m_LayoutRebuildQueue.Contains(element)) { return(false); } m_LayoutRebuildQueue.Add(element); return(true); }
private void InternalRegisterCanvasElementForGraphicRebuild(ICanvasElement element) { if (m_PerformingGraphicUpdate) { Debug.LogError(string.Format("Trying to add {0} for graphic rebuild while we are already inside a graphic rebuild loop. This is not supported.", element)); return; } m_GraphicRebuildQueue.Add(element); }
public void RemoveTest() { var set = new IndexedSet <string>(); Assert.False(set.Remove("A")); set.Add("A"); Assert.True(set.Remove("A")); Assert.Zero(set.Count); Assert.False(set.Contains("A")); }
public void SimpleIndexedSetTest() { const double FirstElement = 17; const double SecondElement = Math.PI; const double ThirdElement = 6.23123438874; const double FourthElement = 43; var indexedSet = new IndexedSet <double>(new[] { FirstElement, SecondElement }); Assert.Equal(2, indexedSet.Count); Assert.True(indexedSet.Contains(FirstElement)); var elements = indexedSet.Elements.ToArray(); Assert.Equal(SecondElement, elements[1]); Assert.Equal(SecondElement, indexedSet.GetElementByIndex(1)); int secondElementIndex; Assert.True(indexedSet.TryGetIndex(Math.PI, out secondElementIndex)); Assert.Equal(1, secondElementIndex); indexedSet.Add(ThirdElement); Assert.Equal(3, indexedSet.Count); Assert.True(indexedSet.Contains(ThirdElement)); int fourthElementIndex; Assert.Throws <ArgumentException>(() => indexedSet.Add(ThirdElement)); Assert.Throws <ArgumentOutOfRangeException>(() => indexedSet.GetElementByIndex(3)); Assert.False(indexedSet.TryGetIndex(FourthElement, out fourthElementIndex)); indexedSet.Add(ThirdElement, false); indexedSet.Add(FourthElement); Assert.Equal(FourthElement, indexedSet.GetElementByIndex(3)); indexedSet.Clear(); Assert.Equal(0, indexedSet.Count); Assert.Throws <ArgumentException>(() => new IndexedSet <double>(new[] { FirstElement, SecondElement, SecondElement })); }
public void IndexOfTest() { var set = new IndexedSet <string>(); Assert.That(set.IndexOf(null), Is.EqualTo(-1)); Assert.That(set.IndexOf("A"), Is.EqualTo(-1)); set.Add("A"); Assert.Zero(set.IndexOf("A")); set[0] = "B"; Assert.Zero(set.IndexOf("B")); }
public void ClearTest() { var set = new IndexedSet <string>(); set.Clear(); Assert.Zero(set.Count); Assert.True(set.Add("A")); Assert.That(set.Count, Is.EqualTo(1)); set.Clear(); Assert.Zero(set.Count); }
public void CountTest() { var set = new IndexedSet <int>(); Assert.Zero(set.Count); for (var i = 0; i < 10; i++) { Assert.That(set.Count, Is.EqualTo(i)); set.Add(i); Assert.That(set.Count, Is.EqualTo(i + 1)); } }
public void SetEqualsTest() { var firstSet = new IndexedSet <string>(); var secondSet = new IndexedSet <string>(); Assert.True(firstSet.SetEquals(secondSet)); Assert.True(secondSet.SetEquals(firstSet)); firstSet.Add("A"); Assert.False(firstSet.SetEquals(secondSet)); Assert.False(secondSet.SetEquals(firstSet)); secondSet.Add("A"); Assert.True(firstSet.SetEquals(secondSet)); Assert.True(secondSet.SetEquals(firstSet)); firstSet.Add("B"); Assert.False(firstSet.SetEquals(secondSet)); Assert.False(secondSet.SetEquals(firstSet)); }
private bool InternalRegisterCanvasElementForGraphicRebuild(ICanvasElement element) { if (m_PerformingGraphicUpdate) { Debug.LogError($"Trying to add {element} for graphic rebuild while we are already inside a graphic rebuild loop. This is not supported."); return(false); } if (m_GraphicRebuildQueue.Contains(element)) { return(false); } m_GraphicRebuildQueue.Add(element); return(true); }
public void IsSupersetOfTest() { var firstSet = new IndexedSet <string>(); var secondSet = new IndexedSet <string>(); Assert.True(firstSet.IsSupersetOf(secondSet)); Assert.True(secondSet.IsSupersetOf(firstSet)); firstSet.Add("A"); Assert.True(firstSet.IsSupersetOf(secondSet)); Assert.False(secondSet.IsSupersetOf(firstSet)); secondSet.Add("A"); Assert.True(firstSet.IsSupersetOf(secondSet)); Assert.True(secondSet.IsSupersetOf(firstSet)); firstSet.Add("B"); Assert.True(firstSet.IsSupersetOf(secondSet)); Assert.False(secondSet.IsSupersetOf(firstSet)); }
public void IndexTest() { var set = new IndexedSet <string>(); Assert.Throws <ArgumentOutOfRangeException>(() => { var _ = set[0]; }); set.Add("A"); Assert.IsNotEmpty(set); Assert.That(set.Count, Is.EqualTo(1)); Assert.That(set[0], Is.EqualTo("A")); }
static void Main(string[] args) { ParallelTest(); //Test2(); //Benchmark(); IndexedSet <string> set = new IndexedSet <string>(); set.Add("two"); set.Add("one"); set.Add("zero"); string first = set[0]; //sd.Add(1, "1"); //sd.Add(2, "2"); //foreach (var item in sd.Keys) //{ //} //IndexedDictionary<int, string> dictionary = new IndexedDictionary<int, string>(); //dictionary.Add(1, "5"); //dictionary.Add(5, "1"); //IDictionary d = dictionary; //foreach (DictionaryEntry item in d) //{ //} //foreach (DictionaryEntry item in d) //{ //} //foreach (var item in dictionary.Values) //{ //} }
public static void RegisterGraphicForCanvas(Canvas c, Graphic graphic) { if (!(c == null)) { instance.m_Graphics.TryGetValue(c, out IndexedSet <Graphic> value); if (value != null) { value.Add(graphic); return; } value = new IndexedSet <Graphic>(); value.Add(graphic); instance.m_Graphics.Add(c, value); } }
/// <summary> /// /// <para> /// Store a link between the given canvas and graphic in the registry. /// </para> /// /// </summary> /// <param name="c">Canvas to register.</param><param name="graphic">Graphic to register.</param> public static void RegisterGraphicForCanvas(Canvas c, Graphic graphic) { if ((Object) c == (Object) null) return; IndexedSet<Graphic> indexedSet; GraphicRegistry.instance.m_Graphics.TryGetValue(c, out indexedSet); if (indexedSet != null) { indexedSet.AddUnique(graphic); } else { indexedSet = new IndexedSet<Graphic>(); indexedSet.Add(graphic); GraphicRegistry.instance.m_Graphics.Add(c, indexedSet); } }
public static void RegisterGraphicForCanvas(Canvas c, Graphic graphic) { if (!(c == null)) { IndexedSet <Graphic> indexedSet; GraphicRegistry.instance.m_Graphics.TryGetValue(c, out indexedSet); if (indexedSet != null) { indexedSet.AddUnique(graphic); } else { indexedSet = new IndexedSet <Graphic>(); indexedSet.Add(graphic); GraphicRegistry.instance.m_Graphics.Add(c, indexedSet); } } }
public static void RegisterGraphicForCanvas(Canvas c, Graphic graphic) { if (c == null) return; IndexedSet<Graphic> graphics; instance.m_Graphics.TryGetValue(c, out graphics); if (graphics != null) { graphics.AddUnique(graphic); return; } // Dont need to AddUnique as we know its the only item in the list graphics = new IndexedSet<Graphic>(); graphics.Add(graphic); instance.m_Graphics.Add(c, graphics); }
private static void Test() { int tid = ++threadId; Random rand = new Random(); IndexedSet <int> set = new IndexedSet <int>(); int counter = 0; while (true) { set.Clear(); int size = rand.Next(20000); HashSet <int> hashSet = new HashSet <int>(); for (int i = 0; i < size; i++) { int x = rand.Next(3000); set.Add(x); hashSet.Add(x); } int size2 = rand.Next(5000); for (int i = 0; i < size2; i++) { int x = rand.Next(300); set.Remove(x); hashSet.Remove(x); } if (set.Count != hashSet.Count) { throw new Exception(); } List <int> list = new List <int>(hashSet); list.Sort(); for (int i = 0; i < set.Count; i++) { if (set[i] != list[i]) { throw new Exception(); } } Console.WriteLine($"{tid} success {++counter}"); } }
public static void RegisterGraphicForCanvas(Canvas c, Graphic graphic) { if (c == null) { return; } IndexedSet <Graphic> graphics; instance.m_Graphics.TryGetValue(c, out graphics); if (graphics != null) { graphics.Add(graphic); return; } graphics = new IndexedSet <Graphic>(); graphics.Add(graphic); instance.m_Graphics.Add(c, graphics); }
static void Main() { var n = int.Parse(Console.ReadLine()); var set = new IndexedSet <int>(); Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); while (n-- > 0) { var q = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); if (q[0] == 0) { set.Add(q[1]); Console.WriteLine(set.Count); } else if (q[0] == 1) { Console.WriteLine(set.Contains(q[1]) ? 1 : 0); } else if (q[0] == 2) { set.Remove(q[1]); } else { foreach (var x in set.GetItems(x => x >= q[1], x => x <= q[2])) { Console.WriteLine(x); } } } Console.Out.Flush(); }
static object Solve() { var(n, qc) = Read2(); var c = Read(); var qs = new bool[qc] .Select((_, id) => { var a = Read(); return(id, l: a[0] - 1, r: a[1] - 1); }) .GroupBy(q => q.r) .ToDictionary(g => g.Key, g => g.ToArray()); // 各色に対して、最も右のインデックス var ris = Array.ConvertAll(new bool[n + 1], _ => - 1); var set = new IndexedSet <int>(); var counts = new int[qc]; for (int i = 0; i < n; i++) { if (ris[c[i]] != -1) { set.Remove(ris[c[i]]); } ris[c[i]] = i; set.Add(i); if (qs.ContainsKey(i)) { foreach (var(id, l, _) in qs[i]) { var li = set.GetFirstIndex(x => x >= l); counts[id] = set.Count - li; } } } return(string.Join("\n", counts)); }
/** * Given an Iterable of Coord (such as a List or Set), a distance to expand outward by (using this Radius), and the * bounding height and width of the map, gets a "thickened" group of Coord as a Set where each Coord in points has * been expanded out by an amount no greater than distance. As an example, you could call this on a line generated * by Bresenham, OrthoLine, or an LOS object's getLastPath() method, and expand the line into a thick "brush stroke" * where this Radius affects the shape of the ends. This will never produce a Coord with negative x or y, a Coord * with x greater than or equal to width, or a Coord with y greater than or equal to height. * @param distance the distance, as measured by this Radius, to expand each Coord on points up to * @param width the bounding width of the map (exclusive) * @param height the bounding height of the map (exclusive) * @param points an Iterable (such as a List or Set) of Coord that this will make a "thickened" version of * @return a Set of Coord that covers a wider area than what points covers; each Coord will be unique (it's a Set) */ public static IndexedSet <Coord> Expand(this Radius r, int distance, int width, int height, IEnumerable <Coord> points) { if (points is null) { return(null); } List <Coord> around = PointsInside(r, Coord.Get(distance, distance), distance, false, width, height); IndexedSet <Coord> expanded = new IndexedSet <Coord>(); int tx, ty; foreach (Coord pt in points) { foreach (Coord ar in around) { tx = pt.X + ar.X - distance; ty = pt.Y + ar.Y - distance; if (tx >= 0 && tx < width && ty >= 0 && ty < height) { expanded.Add(Coord.Get(tx, ty)); } } } return(expanded); }
public void RefreshSelectedRoleBindings() { var roleMap = m_roleSetButtonList[m_selectedRoleIndex].roleMap; var bindingTable = roleMap.BindingTable; // update bound device list and keep the original order for (int i = 0, imax = m_boundDevices.Count; i < imax; ++i) { m_tempDevices.Add(m_boundDevices[i]); } for (int i = 0, imax = bindingTable.Count; i < imax; ++i) { var boundDevice = bindingTable.GetKeyByIndex(i); if (!m_tempDevices.Remove(boundDevice)) { m_boundDevices.Add(boundDevice); } } for (int i = 0, imax = m_tempDevices.Count; i < imax; ++i) { m_boundDevices.Remove(m_tempDevices[i]); } m_tempDevices.Clear(); if (m_bindingList.Count == 0) { m_bindingList.Add(m_bindingItem); m_bindingItem.onEditPress += StartEditBinding; m_bindingItem.onRemovePress += RemoveBinding; } var bindingIndex = 0; for (int max = m_boundDevices.Count; bindingIndex < max; ++bindingIndex) { BindingInterfaceRoleSetBindingItem item; if (bindingIndex >= m_bindingList.Count) { var itemObj = Instantiate(m_bindingItem.gameObject); itemObj.transform.SetParent(m_bindingItem.transform.parent, false); // set child index to secnd last, last index is for add item itemObj.transform.SetSiblingIndex(itemObj.transform.parent.childCount - 2); m_bindingList.Add(item = itemObj.GetComponent <BindingInterfaceRoleSetBindingItem>()); item.onEditPress += StartEditBinding; item.onRemovePress += RemoveBinding; } else { item = m_bindingList[bindingIndex]; } item.gameObject.SetActive(true); item.deviceSN = m_boundDevices[bindingIndex]; item.isEditing = isEditing && item.deviceSN == m_editingDevice; item.isHeighLight = hasHeightLight && item.deviceSN == m_heighLightDevice; item.RefreshDisplayInfo(roleMap); } // FIXME: issue in 2017.2.0b2, item won't refresh at the first time, force refresh m_bindingItem.transform.parent.gameObject.SetActive(false); m_bindingItem.transform.parent.gameObject.SetActive(true); for (int max = m_bindingList.Count; bindingIndex < max; ++bindingIndex) { m_bindingList[bindingIndex].gameObject.SetActive(false); } }
protected virtual void ProcessRaycast() { if (m_processedFrame == Time.frameCount) { return; } m_processedFrame = Time.frameCount; // use another list to iterate raycasters // incase that raycasters may changed during this process cycle for (int i = 0, imax = raycasters.Count; i < imax; ++i) { var r = raycasters[i]; if (r != null) { processingRaycasters.Add(r); } } for (var i = processingRaycasters.Count - 1; i >= 0; --i) { var raycaster = processingRaycasters[i]; if (raycaster == null) { continue; } raycaster.Raycast(); var result = raycaster.FirstRaycastResult(); // prepare raycaster value var scrollDelta = raycaster.GetScrollDelta(); var raycasterPos = raycaster.transform.position; var raycasterRot = raycaster.transform.rotation; var hoverEventData = raycaster.HoverEventData; if (hoverEventData == null) { continue; } // gen shared data and put in hover event hoverEventData.Reset(); hoverEventData.delta = Vector2.zero; hoverEventData.scrollDelta = scrollDelta; hoverEventData.position = ScreenCenterPoint; hoverEventData.pointerCurrentRaycast = result; hoverEventData.position3DDelta = raycasterPos - hoverEventData.position3D; hoverEventData.position3D = raycasterPos; hoverEventData.rotationDelta = Quaternion.Inverse(hoverEventData.rotation) * raycasterRot; hoverEventData.rotation = raycasterRot; // copy data to other button event for (int j = 0, jmax = raycaster.ButtonEventDataList.Count; j < jmax; ++j) { var buttonEventData = raycaster.ButtonEventDataList[j]; if (buttonEventData == null || buttonEventData == hoverEventData) { continue; } buttonEventData.Reset(); buttonEventData.delta = Vector2.zero; buttonEventData.scrollDelta = scrollDelta; buttonEventData.position = ScreenCenterPoint; buttonEventData.pointerCurrentRaycast = result; buttonEventData.position3DDelta = hoverEventData.position3DDelta; buttonEventData.position3D = hoverEventData.position3D; buttonEventData.rotationDelta = hoverEventData.rotationDelta; buttonEventData.rotation = hoverEventData.rotation; } ProcessPress(hoverEventData); ProcessMove(hoverEventData); ProcessDrag(hoverEventData); // other buttons event for (int j = 1, jmax = raycaster.ButtonEventDataList.Count; j < jmax; ++j) { var buttonEventData = raycaster.ButtonEventDataList[j]; if (buttonEventData == null || buttonEventData == hoverEventData) { continue; } buttonEventData.pointerEnter = hoverEventData.pointerEnter; ProcessPress(buttonEventData); ProcessDrag(buttonEventData); } // scroll event if (result.isValid && !Mathf.Approximately(scrollDelta.sqrMagnitude, 0.0f)) { var scrollHandler = ExecuteEvents.GetEventHandler <IScrollHandler>(result.gameObject); ExecuteEvents.ExecuteHierarchy(scrollHandler, hoverEventData, ExecuteEvents.scrollHandler); } } if (isActiveAndEnabled) { for (var i = processingRaycasters.Count - 1; i >= 0; --i) { var r = processingRaycasters[i]; if (!raycasters.Contains(r)) { CleanUpRaycaster(r); } } } else { for (var i = processingRaycasters.Count - 1; i >= 0; --i) { CleanUpRaycaster(processingRaycasters[i]); } } processingRaycasters.Clear(); }