public IEnemy[] GetOrderedByHealth() { var newLegion = new OrderedSet <IEnemy>(CompareElements); newLegion.AddMany(this.legion); return(newLegion.ToArray()); }
protected override void ResolveEmbeddedFilesFromExternalSourceDirectives( SyntaxTree tree, SourceReferenceResolver resolver, OrderedSet <string> embeddedFiles, DiagnosticBag diagnostics) { foreach (LineDirectiveTriviaSyntax directive in tree.GetRoot().GetDirectives( d => d.IsActive && !d.HasErrors && d.Kind() == SyntaxKind.LineDirectiveTrivia)) { var path = (string?)directive.File.Value; if (path == null) { continue; } string?resolvedPath = resolver.ResolveReference(path, tree.FilePath); if (resolvedPath == null) { diagnostics.Add( MessageProvider.CreateDiagnostic( (int)ErrorCode.ERR_NoSourceFile, directive.File.GetLocation(), path, CSharpResources.CouldNotFindFile)); continue; } embeddedFiles.Add(resolvedPath); } }
public override void CollectFields(OrderedSet <string> fields) { foreach (ParseGraphNode node in nodes) { node.CollectFields(fields); } }
public static OrderedSet<int> Create(int[] item_i) { OrderedSet<int> orderedSet = new OrderedSet<int>(); for (int i = 0; i < item_i.Length; i++) orderedSet.Add(item_i[i]); return orderedSet; }
static void Main(string[] args) { OrderedSet<int> orderedSet = new OrderedSet<int>(); orderedSet.Add(5); orderedSet.Add(3); orderedSet.Add(7); orderedSet.Add(1); orderedSet.Add(4); orderedSet.Add(6); orderedSet.Add(8); orderedSet.Add(2); foreach (var i in orderedSet) { Console.WriteLine(i); } Console.WriteLine($"Number of elements (should be 7): {orderedSet.Count}"); Console.WriteLine($"Check if set contains 3 (it should): {orderedSet.Contains(3)}"); Console.WriteLine($"Try removing 3 (should succeed): {orderedSet.Remove(3)}"); Console.WriteLine($"Try removing 3 (should fail): {orderedSet.Remove(3)}"); Console.WriteLine($"Try removing 5 (should succeed): {orderedSet.Remove(5)}"); Console.WriteLine($"Check if set contains 5 (it should not): {orderedSet.Contains(5)}"); Console.WriteLine($"Number of elements (should be 5): {orderedSet.Count}"); foreach (var i in orderedSet) { Console.WriteLine(i); } }
public override void Run(List<Point> points, List<Line> lines, List<Polygon> polygons, ref List<Point> outPoints, ref List<Line> outLines, ref List<Polygon> outPolygons) { segments = new List<Line>(); for (int i = 0; i < lines.Count; ++i) //cuz it'll be edited during the run segments.Add(new Line(new Point(lines[i].Start.X,lines[i].Start.Y),new Point(lines[i].End.X,lines[i].End.Y))); OrderedSet<Event> Q = new OrderedSet<Event>(comparerEventX); OrderedSet<Event> L = new OrderedSet<Event>(comparerEventY); initializeEvents(Q); while (Q.Count > 0) { Event curEvent = Q.First(); Q.RemoveFirst(); handleEvent(curEvent, L,Q, outPoints); } Dictionary<PointComparer, int> hashP = new Dictionary<PointComparer, int>(); for (int i = 0; i < lines.Count; ++i) { if(hashP.ContainsKey(new PointComparer(lines[i].Start))) hashP[new PointComparer(lines[i].Start)]++; else hashP[new PointComparer(lines[i].Start)] = 1; if (hashP.ContainsKey(new PointComparer(lines[i].End))) hashP[new PointComparer(lines[i].End)]++; else hashP[new PointComparer(lines[i].End)] = 1; } foreach(KeyValuePair<PointComparer,int> v in hashP) if(v.Value>1) outPoints.Add(v.Key.p); }
public IGeometry Union() { PointLocator locater = new PointLocator(); // use a set to eliminate duplicates, as required for union var exteriorCoords = new OrderedSet<Coordinate>(); foreach (IPoint point in PointExtracter.GetPoints(_pointGeom)) { Coordinate coord = point.Coordinate; Location loc = locater.Locate(coord, _otherGeom); if (loc == Location.Exterior) { exteriorCoords.Add(coord); } } // if no points are in exterior, return the other geom if (exteriorCoords.Count == 0) { return _otherGeom; } // make a puntal geometry of appropriate size ICoordinateSequence coords = _geomFact.CoordinateSequenceFactory.Create(exteriorCoords.ToArray()); IGeometry ptComp = coords.Count == 1 ? (IGeometry)_geomFact.CreatePoint(coords.GetCoordinate(0)) : _geomFact.CreateMultiPoint(coords); // add point component to the other geometry return GeometryCombiner.Combine(ptComp, _otherGeom); }
public IGeometry Union() { PointLocator locater = new PointLocator(); // use a set to eliminate duplicates, as required for union var exteriorCoords = new OrderedSet <Coordinate>(); foreach (IPoint point in PointExtracter.GetPoints(_pointGeom)) { Coordinate coord = point.Coordinate; Location loc = locater.Locate(coord, _otherGeom); if (loc == Location.Exterior) { exteriorCoords.Add(coord); } } // if no points are in exterior, return the other geom if (exteriorCoords.Count == 0) { return(_otherGeom); } // make a puntal geometry of appropriate size ICoordinateSequence coords = _geomFact.CoordinateSequenceFactory.Create(exteriorCoords.ToArray()); IGeometry ptComp = coords.Count == 1 ? (IGeometry)_geomFact.CreatePoint(coords.GetCoordinate(0)) : _geomFact.CreateMultiPoint(coords); // add point component to the other geometry return(GeometryCombiner.Combine(ptComp, _otherGeom)); }
static void Add(string[] parameters, OrderedDictionary <decimal, OrderedSet <Product> > products, Dictionary <string, OrderedBag <Product> > productByTypes) { string name = parameters[1]; decimal price = decimal.Parse(parameters[2]); string type = parameters[3]; var newProduct = new Product(name, price, type); if (!products.ContainsKey(price)) { products[price] = new OrderedSet <Product>(new ProductComparerByName()); } if (!products[price].Contains(newProduct)) { products[price].Add(newProduct); Console.WriteLine("Ok: Product {0} added successfully", newProduct.ProductName); if (!productByTypes.ContainsKey(type)) { productByTypes[type] = new OrderedBag <Product>(new ProductComparerByPrice()); } productByTypes[type].Add(newProduct); } else { Console.WriteLine("Error: Product {0} already exists", newProduct.ProductName); } }
public IList<PatternStart> RandomizeColoring() { //original color Dictionary<PatternStart, IList<Color>> startToColor = new Dictionary<PatternStart, IList<Color>>(); //keep track of the active patterns. Will contain new color List<PatternStart> active = new List<PatternStart>(); foreach (var start in _patternStarts) { IList<Color> colors = EffectsToColors(start.SampleEffect.ColorEffects); startToColor[start] = colors; OrderedSet<Color> distinct = new OrderedSet<Color>(); distinct.AddAll(colors); IDictionary<Color, Color> oldToNew = OldToNew(startToColor, active); Color randBase = distinct.FirstOrDefault(oldToNew.ContainsKey); IList<Color> newColors = randBase == default(Color) ? ColorPicker.PickColors(distinct.Count) : ColorPicker.PickColors(randBase, distinct.Count); IEnumerator<Color> newEnum = newColors.GetEnumerator(); IEnumerator<Color> oldEnum = distinct.GetEnumerator(); while(oldEnum.MoveNext()) { newEnum.MoveNext(); if (!oldToNew.ContainsKey(oldEnum.Current)) { oldToNew[oldEnum.Current] = newEnum.Current; } } start.ApplyColors(colors.Select(c=>oldToNew[c]).ToList()); active.RemoveAll(s => s.EndTime <= start.StartTime); active.Add(start); } return _patternStarts; }
private void checkIntersection(Event upper,Event lower, OrderedSet<Event> Q,List<Point> outPoints) { Line a = new Line(upper.point,segments[upper.segIdx].End); Line b = new Line(lower.point,segments[lower.segIdx].End); if (HelperMethods.CheckTurn(new Line(a.Start, a.End), b.Start) == HelperMethods.CheckTurn(new Line(a.Start, a.End), b.End) || (HelperMethods.CheckTurn(new Line(b.Start, b.End), a.Start) == HelperMethods.CheckTurn(new Line(b.Start, b.End), a.End))) return; double aa, bb, cc, dd; Point interPoint; if (Math.Abs(a.Start.X - a.End.X) < Constants.Epsilon) { bb = (b.Start.Y - b.End.Y) / (b.Start.X - b.End.X); dd = b.Start.Y - b.Start.X * bb; interPoint = new Point(a.Start.X, (bb * a.Start.X + dd)); } else if (Math.Abs(b.Start.X - b.End.X) < Constants.Epsilon) { aa = (a.Start.Y - a.End.Y) / (a.Start.X - a.End.X); cc = a.Start.Y - a.Start.X * aa; interPoint = new Point(b.Start.X, (aa * a.Start.X + cc)); } else { aa = (a.Start.Y - a.End.Y) / (a.Start.X - a.End.X); bb = (b.Start.Y - b.End.Y) / (b.Start.X - b.End.X); cc = a.Start.Y - a.Start.X * aa; dd = b.Start.Y - b.Start.X * bb; double interX = (dd - cc) / (aa - bb); interPoint = new Point(interX, (aa * interX + cc)); } Q.Add(new Event(interPoint, PointType.Intersection,-1 ,upper,lower)); outPoints.Add(interPoint); }
static void Main(string[] args) { var set = new OrderedSet<int>(); set.Add(17); set.Add(17); set.Add(9); set.Add(12); set.Add(19); set.Add(6); set.Add(25); Console.WriteLine("Set contains 12: {0}", set.Contains(12)); Console.WriteLine("Set contains 123: {0}", set.Contains(123)); Console.WriteLine("Number of elements: {0}",set.Count); Console.WriteLine("========="); foreach (var element in set) { Console.WriteLine(element); } Console.WriteLine("Remove 17:"); set.Remove(17); Console.WriteLine(string.Join(" -> ", set.ToList())); Console.WriteLine("========="); Console.WriteLine("Set contains 17: {0}", set.Contains(17)); Console.WriteLine("Number of elements: {0}", set.Count); Console.WriteLine("========="); }
public BunnyWarsStructure() { this.rooms = new OrderedSet<int>(); this.roomsById = new OrderedDictionary<int, Dictionary<int, List<Bunny>>>(); this.bunniesByTeam = new Dictionary<int, SortedSet<Bunny>>(); this.bunniesByName = new OrderedDictionary<string, Bunny>(new SuffixBunnyComparator()); }
public OrderedSet <string> GetFields() { OrderedSet <string> fields = new OrderedSet <string>(); CollectFields(fields); return(fields); }
internal int LoadIndexed(EndianBinaryReader input, OrderedSet <GcmfVertex> vertexPool, uint vertexFlags) { int nIntsRead = 0; int stripLength = input.ReadInt32(); nIntsRead++; for (int i = 0; i < stripLength; i++) { int vertexOff = input.ReadInt32(); nIntsRead++; if ((vertexOff % 0x40) != 0) { throw new InvalidGmaFileException("[GcmfTriangleStripType2] vertexOff not multiple of 0x40."); } int vertexIdx = vertexOff / 0x40; if (vertexIdx >= vertexPool.Count) { throw new InvalidGmaFileException("[GcmfTriangleStripType2] vertexIdx out of range."); } vertexPool[vertexIdx].AssignVertexFlagsIndexed(vertexFlags); Items.Add(vertexPool[vertexIdx]); } return(nIntsRead); }
static SNode SetNode(int list) { char[] possiblesList = list.ToString().ToCharArray(); OrderedSet <int> possibles = new OrderedSet <int>(); foreach (char c in possiblesList) { int i = 0; int.TryParse(c.ToString(), out i); possibles.Add(i); } if (possibles.Count == 0) { return(new SNode(sudokuNumbers)); } else if (possibles.Count == 1) { return(new SNode(possibles[0])); } else { return(new SNode(possibles)); } }
public Scoreboard(int maxEntriesToKeep = 10) { this.users = new Dictionary <string, string>(); this.games = new Dictionary <string, string>(); this.scores = new Dictionary <string, OrderedBag <ScoreboardEntry> >(); this.prefixNames = new OrderedSet <string>(string.CompareOrdinal); }
private static void Add(string[] commandArgs) { var playerName = commandArgs[1]; var playerType = commandArgs[2]; var playerAge = int.Parse(commandArgs[3]); var playerRank = int.Parse(commandArgs[4]); var player = new Player(playerName, playerType, playerAge); ranking.Insert(playerRank - 1, player); if (!playersByType.ContainsKey(playerType)) { playersByType[playerType] = new OrderedSet <Player>(); } var typePlayers = playersByType[playerType]; typePlayers.Add(player); if (typePlayers.Count > 5) { typePlayers.RemoveLast(); } output.AppendLine($"Added player {playerName} to position {playerRank}"); }
public void DirectRightAndLeftCheckExistingObject() { OrderedSet <ClassTester> tree = new OrderedSet <ClassTester>((x, y) => { return(x.compareByValue.CompareTo(y.compareByValue)); }); tree.Add(new ClassTester(10, 2)); tree.Add(new ClassTester(-10, 1)); tree.Add(new ClassTester(20, 3)); tree.Add(new ClassTester(-20, 0)); OrderedSet <ClassTester> expectedOutputTree = new OrderedSet <ClassTester>((x, y) => { return(x.compareByValue.CompareTo(y.compareByValue)); }); expectedOutputTree.Add(new ClassTester(10, 2)); expectedOutputTree.Add(new ClassTester(-10, 1)); expectedOutputTree.Add(new ClassTester(20, 3)); expectedOutputTree.Add(new ClassTester(-20, 0)); var outputRL = tree.DirectRightAndLeft(new ClassTester(-20, 2)); var expectedOutputRL = new KeyValuePair <ClassTester, ClassTester>(new ClassTester(-10, 1), null); Assert.AreEqual(outputRL.Key.compareByValue, expectedOutputRL.Key.compareByValue, "Right element is incorrect"); Assert.AreEqual(outputRL.Key.otherProperties, expectedOutputRL.Key.otherProperties, "Right element is incorrect"); Assert.AreEqual(outputRL.Value, expectedOutputRL.Value, "Left element is incorrect"); Assert.AreEqual(outputRL.Value, expectedOutputRL.Value, "Left element is incorrect"); Assert.AreEqual(expectedOutputTree.Count, tree.Count, "Tree size is incorrect!"); for (int i = 0; i < expectedOutputTree.Count; i++) { Assert.AreEqual(expectedOutputTree[i], tree[i], "Tree Element at index " + i + " is incorrect"); } }
public void GetEmptyRangeSuccessfully() { var set = new OrderedSet <int>(); var subSet = set.GetRange(0, 0); Assert.Equal(subSet.Count, 0); }
public void CopyIEnumerableToSetTest() { List<string> originalCollection = new List<string> { "Granville", "John", "Granville", "Betty" }; OrderedSet<string> actual = new OrderedSet<string>(originalCollection); Assert.AreEqual(3, actual.Count); }
public ICollection <ConfigItem> Get(ConfigurationType typesToReturn) { lock (_lockObject) { OrderedSet <ConfigItem> list = new OrderedSet <ConfigItem>(); foreach (ConfigItem item in _configItems.Values) { if (item.IsEditable) { if ((typesToReturn & ConfigurationType.Global) == ConfigurationType.Global) { list.Add(new ConfigItem(item)); } } else { if ((typesToReturn & ConfigurationType.System) == ConfigurationType.System) { list.Add(new ConfigItem(item)); } } } return(list); } }
public void isUnique() { var orderedset = new OrderedSet <int>(); orderedset.add(1); orderedset.add(2); orderedset.add(3); Assert.AreEqual(orderedset.isUnique(i => i), true); Assert.AreEqual(orderedset.isUnique(i => i > 1), false); var x = new Sequence <object>() { new Set <int> { 1, 2, 3 }, new Sequence <double> { 2.2, 3.0 }, new Bag <string> { "test" } }.flatten <object>(); var y = new Sequence <Sequence <int> >() { new Sequence <int> { 1, 2 }, new Sequence <int> { 4, 6 } }.flatten <int>(); var z = 3; }
public BunnyWarsStructure() { this._bunnyByName = new Dictionary <string, Bunny>(); this._bunnyByRoomByTeam = new OrderedDictionary <int, LinkedList <Bunny>[]>(); this._bunnyByTeam = new OrderedDictionary <int, OrderedSet <Bunny> >(); this._bySuffix = new OrderedSet <Bunny>(SuffixComparator); }
public void flatten() { var orderedset = new OrderedSet <OrderedSet <int> >(); var result = orderedset.flatten <int>(); Assert.AreEqual(result.size(), 0); orderedset.add(new OrderedSet <int> { 1, 2 }); result = orderedset.flatten <int>(); Assert.AreEqual(orderedset.size(), 1); Assert.AreEqual(result.size(), 2); orderedset.add(new OrderedSet <int> { 3, 4 }); result = orderedset.flatten <int>(); Assert.AreEqual(orderedset.size(), 2); Assert.AreEqual(result.size(), 4); //orderedset.add(new OrderedSet<int> { 1, 2 }); //Assert.AreEqual(orderedset.size(), 2);//addUnique should not add {1,2}, because it is already there //Assert.AreEqual(result.size(), 4); }
private OrderedSet <CachedUserAccountInfo> GetAllCachedUserAccounts() { OrderedSet <CachedUserAccountInfo> userAccounts = null; _objectCacheDao.GetObject(CACHE_NAAS_USER_ACCOUNTS, true, out userAccounts); return(userAccounts); }
public bool Equals(OrderedSet <T> secondary) { // Check if both empty sets if (this.Count == 0 && secondary.Count == 0) { return(true); } // Check if counts don't match if (this.Count != secondary.Count) { return(false); } // Check if contents are the same for (int index = 0; index < this.Count; index++) { if (!this[index].Equals(secondary[index])) { return(false); } } // There were not any differences, thus return true that the sets are the same return(true); }
static void Main(string[] args) { var set = new OrderedSet<int>(); set.Add(17); set.Add(9); set.Add(12); set.Add(19); set.Add(6); set.Add(25); foreach (var item in set) { Console.WriteLine(item); } Console.WriteLine(); set.Remove(9); foreach (var item in set) { Console.WriteLine(item); } Console.WriteLine(set.Contains(9)); Console.WriteLine(); set.Add(25); set.Add(25); set.Add(25); set.Add(25); foreach (var item in set) { Console.WriteLine(item); } }
static OrderedSet <Graph.State> MoveR(OrderedSet <Graph.State> initialStates, CharSet c) { var reachable = new Dictionary <Graph.State, bool>(); foreach (var state in initialStates) { foreach (var transition in state.FromTransitions) { if (transition.Label == null) { continue; } if (!transition.Label.Intersects(c)) { continue; } reachable[transition.FromState] = true; } } var result = new Graph.State[reachable.Count]; reachable.Keys.CopyTo(result, 0); return(OrderedSet <Graph.State> .New(result)); }
public void ContainsTest() { OrderedSet<int> actual = new OrderedSet<int> {12, 19, 1, 23}; Assert.IsTrue(actual.Contains(19)); Assert.IsFalse(actual.Contains(99)); }
static void Main(string[] args) { int numberOfFrames = int.Parse(Console.ReadLine()); used = new bool[numberOfFrames]; combinations = new OrderedSet<string>(); frames = new Frame[numberOfFrames]; for (int i = 0; i < numberOfFrames; i++) { string inputString = Console.ReadLine(); frames[i] = new Frame(inputString[0], inputString[2]); } Recursive(0, new Frame[numberOfFrames], 0); StringBuilder sb = new StringBuilder(); sb.AppendLine(combinations.Count.ToString()); foreach (var item in combinations) { sb.AppendLine(item.ToString()); } Console.Write(sb.ToString()); }
private OrderedSet <CachedUserAccountInfo> GetAllUserAccounts(bool forceFreshFromNaas) { OrderedSet <CachedUserAccountInfo> userAccounts = null; if (!forceFreshFromNaas) { if (_objectCacheDao.GetObject(CACHE_NAAS_USER_ACCOUNTS, false, out userAccounts)) { return(userAccounts); } } const int getBatchCount = 1000; NAAS_USRMGR.GetUserList getUserList = new NAAS_USRMGR.GetUserList(); getUserList.adminName = _usermgrRuntimeCredential.UserName; getUserList.credential = _usermgrRuntimeCredential.Password; getUserList.domain = _usermgrRuntimeCredentialDomain; getUserList.userId = string.Empty; getUserList.status = string.Empty; getUserList.affiliate = string.Empty; userAccounts = new OrderedSet <CachedUserAccountInfo>(); for (int i = 0; ;) { int length = GetAllUserAccounts(getUserList, i, getBatchCount, userAccounts); if (length <= 0) { break; } i += length; } _objectCacheDao.CacheObject(userAccounts, CACHE_NAAS_USER_ACCOUNTS, _cacheNaasUsernamesDuration); return(userAccounts); }
public void OrderedSet_Supports_AddingValues() { var set = new OrderedSet <string>(); set.Add("foo"); Assert.Single(set); }
internal void LoadIndexedData(EndianBinaryReader input, OrderedSet <GcmfVertex> vertexPool, HeaderSectionInfo headerSectionInfo) { if ((headerSectionInfo.SectionFlags & 0x01) != 0 && headerSectionInfo.Chunk1Size == 0) { throw new InvalidGmaFileException("GcmfMeshType2: Chunk1, but chunk1Size == 0?"); } if ((headerSectionInfo.SectionFlags & 0x01) == 0 && headerSectionInfo.Chunk1Size != 0) { throw new InvalidGmaFileException("GcmfMeshType2: No chunk1, but chunk1Size != 0?"); } if ((headerSectionInfo.SectionFlags & 0x01) != 0) { Obj1StripsCcw.LoadIndexed(input, headerSectionInfo.Chunk1Size, vertexPool, headerSectionInfo.VertexFlags); } if ((headerSectionInfo.SectionFlags & 0x02) != 0 && headerSectionInfo.Chunk2Size == 0) { throw new InvalidGmaFileException("GcmfMeshType2: Chunk2, but chunk2Size == 0?"); } else if ((headerSectionInfo.SectionFlags & 0x02) == 0 && headerSectionInfo.Chunk2Size != 0) { throw new InvalidGmaFileException("GcmfMeshType2: No chunk2, but chunk2Size != 0?"); } if ((headerSectionInfo.SectionFlags & 0x02) != 0) { Obj1StripsCw.LoadIndexed(input, headerSectionInfo.Chunk2Size, vertexPool, headerSectionInfo.VertexFlags); } if ((headerSectionInfo.SectionFlags & 0xFC) != 0) { throw new InvalidGmaFileException("GcmfMeshType2: Unknown present chunk flags at chunk10."); } }
static void Main(string[] args) { int numberOfFrames = int.Parse(Console.ReadLine()); used = new bool[numberOfFrames]; combinations = new OrderedSet <string>(); frames = new Frame[numberOfFrames]; for (int i = 0; i < numberOfFrames; i++) { string inputString = Console.ReadLine(); frames[i] = new Frame(inputString[0], inputString[2]); } Recursive(0, new Frame[numberOfFrames], 0); StringBuilder sb = new StringBuilder(); sb.AppendLine(combinations.Count.ToString()); foreach (var item in combinations) { sb.AppendLine(item.ToString()); } Console.Write(sb.ToString()); }
internal int LoadIndexed(EndianBinaryReader input, bool is16Bit, OrderedSet <GcmfVertex> vertexPool, uint vertexFlags) { int nIntsRead = 0; int stripLength = LoadSizedInteger(input, is16Bit); nIntsRead++; for (int i = 0; i < stripLength; i++) { int vertexOff = LoadSizedInteger(input, is16Bit); nIntsRead++; int sizeOfVertex = !is16Bit ? 0x40 : 0x20; if ((vertexOff % sizeOfVertex) != 0) { throw new InvalidGmaFileException(string.Format("[GcmfTriangleStripType2] vertexOff not multiple of {0}.", sizeOfVertex)); } int vertexIdx = vertexOff / sizeOfVertex; if (vertexIdx >= vertexPool.Count) { throw new InvalidGmaFileException("[GcmfTriangleStripType2] vertexIdx out of range."); } vertexPool[vertexIdx].AssignVertexFlagsIndexed(vertexFlags); Items.Add(vertexPool[vertexIdx]); } return(nIntsRead); }
CreateUsernamePairList(OrderedSet <CachedUserAccountInfo> userAccounts, bool appendAffiliation) { if (CollectionUtils.IsNullOrEmpty(userAccounts)) { return(new List <KeyValuePair <string, string> >()); } List <KeyValuePair <string, string> > list = new List <KeyValuePair <string, string> >(userAccounts.Count); if (appendAffiliation) { foreach (CachedUserAccountInfo info in userAccounts) { list.Add(new KeyValuePair <string, string>(info.Username, string.Format("{0} ({1})", info.Username, info.Affiliate))); } } else { foreach (CachedUserAccountInfo info in userAccounts) { list.Add(new KeyValuePair <string, string>(info.Username, info.Username)); } } return(list); }
private void ProcessLayers(OrderedSet <int> layers) { foreach (int layerToCover in layers) { ProcessLayer(layerToCover); } }
private int GetAllUserAccountsXmlError(NAAS_USRMGR.GetUserList getUserList, int startIndex, int count, OrderedSet <CachedUserAccountInfo> userAccounts) { int firstHalfCount = (count + 1) / 2; if (firstHalfCount <= 0) { throw new ArgumentException("Invalid startIndex: " + startIndex.ToString()); } int numAddedFirst = GetAllUserAccounts(getUserList, startIndex, firstHalfCount, userAccounts); if (numAddedFirst == 0) { return(0); } int secondHalfCount = count - firstHalfCount; if (secondHalfCount == 0) { return(numAddedFirst); } int numAddedSecond = GetAllUserAccounts(getUserList, startIndex + firstHalfCount, secondHalfCount, userAccounts); if (numAddedSecond == 0) { return(0); } return(numAddedFirst + numAddedSecond); }
static void Main() { var mySet = new OrderedSet <int>(); mySet.Add(17); mySet.Add(9); mySet.Add(12); mySet.Add(19); mySet.Add(51); mySet.Add(7); mySet.Add(34); mySet.Add(16); mySet.Add(11); mySet.Add(22); mySet.Add(6); mySet.Add(25); int i = 1; Console.WriteLine(mySet.Count); foreach (int entry in mySet) { Console.WriteLine(i++ + " -> " + entry); } }
public void RemoveChild(BoardItem child) { if (this.children != null && this.children.Remove(child) && this.children.Count == 0) { this.children = null; } }
private static Dictionary <SHA1Hash, Dictionary <SHA1Hash, int> > LoadScores(OrderedSet <SHA1Hash> hashes, string fileName) { Dictionary <SHA1Hash, Dictionary <SHA1Hash, int> > Result = new Dictionary <SHA1Hash, Dictionary <SHA1Hash, int> >(); string[] Lines = File.ReadAllLines(fileName); for (int i = 1; i < Lines.Length; i++) { string[] Parts = Lines[i].Split(','); int Audio1 = int.Parse(Parts[0]); int Audio2 = int.Parse(Parts[1]); int Score = int.Parse(Parts[2]); SHA1Hash Hash1 = hashes[Audio1 - 1]; SHA1Hash Hash2 = hashes[Audio2 - 1]; if (!Result.ContainsKey(Hash1)) { Result.Add(Hash1, new Dictionary <SHA1Hash, int>()); } if (!Result[Hash1].ContainsKey(Hash2)) { Result[Hash1].Add(Hash2, Score); } } return(Result); }
public static void Main() { var set = new OrderedSet<int>(); set.Add(17); set.Add(9); set.Add(12); set.Add(6); set.Add(25); set.Add(4); set.Add(8); set.Add(10); set.Add(14); set.Add(18); set.Add(22); set.Add(20); set.Add(24); set.Add(28); set.Add(26); set.Add(30); set.Add(2); set.Add(1); Console.WriteLine(set.Contains(12)); Console.WriteLine(set.Contains(60)); foreach (var child in set) { Console.WriteLine(child); } // set.Remove(12); set.Remove(9); }
/// <summary> /// Constructor /// </summary> /// <param name="window"></param> protected internal DesktopWindowView(DesktopWindow window) { _desktopWindow = window; _form = CreateDesktopForm(); _workspaceActivationOrder = new OrderedSet<WorkspaceView>(); // listen to some events on the form _form.VisibleChanged += FormVisibleChangedEventHandler; _form.Activated += FormActivatedEventHandler; _form.Deactivate += FormDeactivateEventHandler; _form.FormClosing += FormFormClosingEventHandler; _form.TabbedGroups.PageCloseRequest += TabbedGroupPageClosePressedEventHandler; _form.TabbedGroups.PageChanged += TabbedGroupPageChangedEventHandler; // NY: We subscribe to ContentHiding instead of ContentHidden because ContentHidden // is fired when the user double clicks the caption bar of a docking window, which // results in a crash. (Ticket #144) _form.DockingManager.ContentHiding += DockingManagerContentHidingEventHandler; _form.DockingManager.ContentShown += DockingManagerContentShownEventHandler; _form.DockingManager.ContentAutoHideOpening += DockingManagerContentAutoHideOpeningEventHandler; _form.DockingManager.ContentAutoHideClosed += DockingManagerContentAutoHideClosedEventHandler; _form.DockingManager.WindowActivated += DockingManagerWindowActivatedEventHandler; _form.DockingManager.WindowDeactivated += FormDockingManagerWindowDeactivatedEventHandler; // init notification dialogs _infoNotificationDialog = new AlertNotificationForm(_form, Application.Name) {AutoDismiss = true}; _infoNotificationDialog.OpenLogClicked += AlertDialogOpenLogClicked; _errorNotificationDialog = new AlertNotificationForm(_form, Application.Name); _errorNotificationDialog.OpenLogClicked += AlertDialogOpenLogClicked; _errorNotificationDialog.Dismissed += ErrorDialogDismissed; }
public ExtremumsRepository() { firstMaximums = new OrderedSet<Extremum>(CompareExtremums); firstMinimums = new OrderedSet<Extremum>(CompareExtremums); secondMaximums = new OrderedSet<Extremum>(CompareExtremums); secondMinimums = new OrderedSet<Extremum>(CompareExtremums); }
public void ClearTest() { OrderedSet<int> actual = new OrderedSet<int> {15, 16, 89}; actual.Clear(); Assert.AreEqual(0, actual.Count); }
public BunnyWarsStructure() { this.bunniesInTeamsByRoom = new OrderedDictionary<int, Dictionary<int, HashSet<Bunny>>>(); this.roomsById = new OrderedSet<int>(); this.bunniesByName = new Dictionary<string, Bunny>(); this.teamsBunnies = new Dictionary<int, OrderedSet<Bunny>>(); this.bunniesOrderedReversedNames = new OrderedDictionary<string, Bunny>(StringComparer.Ordinal); }
public IEnumerable<Product> FindProductsByPriceRange(decimal minPrice, decimal maxPrice) { var filteredByPriceRange = this.productsByPrice.Range(minPrice, true, maxPrice, true).Values.SelectMany(p => p); // TODO: this is slow. Think of better way to extract the products ordered by ID OrderedSet<Product> result = new OrderedSet<Product>(filteredByPriceRange); return result; }
public Repository( OrderedSet<PhoneBookEntry> sortedEntries, IDictionary<string, PhoneBookEntry> entriesByName, MultiDictionaryBase<string, PhoneBookEntry> entriesByPhone) { this.sortedEntries = sortedEntries; this.entriesByName = entriesByName; this.entriesByPhone = entriesByPhone; }
public void TrimTwo() { var set = new OrderedSet<Story>(); var story = new Story(new FrontpageItem { Title = "title", Link = "blah" }) { DisplayTime = DateTime.Now}; var story2 = new Story(new FrontpageItem { Title = "title2", Link = "blah" }) {DisplayTime = DateTime.MinValue}; set.Add(story); set.Add(story2); set.Trim(2); Assert.AreEqual(2, set.Count); }
private IteratorAndAsyncCaptureWalker(CSharpCompilation compilation, MethodSymbol method, BoundNode node, NeverEmptyStructTypeCache emptyStructCache, HashSet<Symbol> initiallyAssignedVariables) : base(compilation, method, node, emptyStructCache, trackUnassignments: true, initiallyAssignedVariables: initiallyAssignedVariables) { _variablesToHoist = new OrderedSet<Symbol>(); }
public void DuplicateObjectTest() { OrderedSet<Person> actual = new OrderedSet<Person>(); Person p1 = new Person { FirstName = "Granville", LastName = "Barnett" }; Person p2 = new Person { FirstName = "Granville", LastName = "Barnett" }; actual.Add(p1); actual.Add(p2); Assert.AreEqual(1, actual.Count); }
public void Trim() { var set = new OrderedSet<Story>(); var story = new Story(new FrontpageItem { Title = "title", Link = "blah", Description = "shouldnt matter" }) { DisplayTime = DateTime.Now}; var story2 = new Story(new FrontpageItem { Title = "title", Link = "blah", Description = "diff but irrelevant" }) {DisplayTime = DateTime.MinValue}; set.Add(story); set.Add(story2); set.Trim(1); Assert.AreEqual(1, set.Count); Assert.AreEqual(story2, set[0]); }
public void AddTest([PexAssumeUnderTest]HashSet<int> newelements) { OrderedSet<int> actual = new OrderedSet<int>(newelements); PexAssert.AreEqual(newelements.Count, actual.Count); foreach (int elem in newelements) PexAssert.IsTrue(actual.Contains(elem)); actual.Clear(); PexAssert.AreEqual(0, actual.Count); }
public void OrderedSetTest() { var set = new OrderedSet<Story>(); var story = new Story(new FrontpageItem { Title = "title", Link = "blah", Description = "shouldnt matter" }); var story2 = new Story(new FrontpageItem { Title = "title", Link = "blah", Description = "diff but irrelevant" }); set.Add(story); set.Add(story2); set.RemoveLast(); Assert.AreEqual(1, set.Count); Assert.AreEqual(story2, set[0]); }
public static void Main(string[] args) { var ints = new OrderedSet<int> (); Console.WriteLine ("Initial set:"); ints.Add (17); ints.Add (17); ints.Add (17); ints.Add (9); ints.Add (12); ints.Add (19); ints.Add (6); ints.Add (25); foreach (var val in ints) { Console.WriteLine (val); } Console.WriteLine ("17 exist. {0}.", ints.Contains(17)); Console.WriteLine ("9 exist. {0}.", ints.Contains(9)); Console.WriteLine ("12 exist. {0}.", ints.Contains(12)); Console.WriteLine ("18 exists. {0}.", ints.Contains(18)); Console.WriteLine ("19 exists. {0}.", ints.Contains(19)); Console.WriteLine ("6 exists. {0}.", ints.Contains(6)); Console.WriteLine ("25 exists. {0}.", ints.Contains(25)); Console.WriteLine ("27 exists. {0}.", ints.Contains(27)); Console.WriteLine ("28 exists. {0}.", ints.Contains(28)); Console.WriteLine ("Adding some elements:"); ints.Add (1); ints.Add (2); ints.Add (3); ints.Add (4); ints.Add (5); ints.Add (7); ints.Add (8); ints.Add (10); foreach (var val in ints) { Console.WriteLine (val); } Console.WriteLine ("Removing some elements:"); ints.Remove (2); ints.Remove (5); ints.Remove (6); ints.Remove (9); ints.Remove (17); ints.Remove (100); foreach (var val in ints) { Console.WriteLine (val); } }
public static void Main() { var testSet = new OrderedSet<int>(); testSet.Add(7); testSet.Add(1); testSet.Add(72); testSet.Add(-27); testSet.Add(0); testSet.Add(15); Console.WriteLine(string.Join(", ", testSet)); testSet.Remove(0); Console.WriteLine(string.Join(", ", testSet)); }
public static void Main() { List<int> itemsToAdd = new List<int> { 17, 9, 9, 12, 19, 6, 25, 10, 15 }; var set = new OrderedSet<int>(); Console.WriteLine("Adding elements: {0}", string.Join(", ", itemsToAdd)); foreach (var item in itemsToAdd) { var added = set.Add(item); //// duplicate items shouldn't be added twice in the set like item 9 Console.WriteLine("Item {0}\t: {1}", item, added ? "added" : "not added"); } Console.WriteLine("{0}\nUsing IEnumerable foreach:", Separator); foreach (var element in set) { Console.WriteLine(element); } Console.WriteLine("{0}\nCount: {1}", Separator, set.Count); Console.WriteLine("{0}\nMin: {1}", Separator, set.Min); Console.WriteLine("{0}\nMax: {1}", Separator, set.Max); Console.WriteLine("{0}\nContains {1}: {2}", Separator, ContainedValue, set.Contains(ContainedValue)); Console.WriteLine("{0}\nContains {1}: {2}", Separator, NotContainedValue, set.Contains(NotContainedValue)); Console.WriteLine("{0}\nUsing ForEach method:", Separator); set.ForEach(Console.WriteLine); Console.WriteLine("{0}\nEfter removing 19:", Separator); set.Remove(19); set.ForEach(Console.WriteLine); Console.WriteLine("Count: {0}", set.Count); Console.WriteLine("{0}\nEfter removing all items:", Separator); set.Remove(6); set.Remove(9); set.Remove(15); set.Remove(25); set.Remove(10); set.Remove(12); set.Remove(17); Console.WriteLine("Count: {0}", set.Count); set.ForEach(Console.WriteLine); // Shouldn't print items because the set is empty }
public void PerumtationsEmptySetPUT(OrderedSet<int> actual, int actualVal) { if (actual == null) { actual.Permutations(actualVal); PexAssert.IsTrue(false, "ArgumentNullException should be thrown"); } else if (actualVal == 0) { actual.Permutations(actualVal); PexAssert.IsTrue(false, "ArgumentOutOfRangeException should be thrown"); } else { PexObserve.ValueForViewing<int[]>("actual OrderedSet", actual.ToArray()); PexObserve.ValueForViewing("Result of permutation",actual.Permutations(actualVal)); } }
private static long FindMinSpanningTreeSum(Node<char> startingNode, int nodesCount) { HashSet<char> visitedNodes = new HashSet<char>(); OrderedSet<Connection<char>> connections = new OrderedSet<Connection<char>>(); long currentSum = 0; visitedNodes.Add(startingNode.Symbol); foreach (var connection in startingNode.Connections) { if (!visitedNodes.Contains(connection.toNode.Symbol)) { connections.Add(connection); } } while (connections.Count > 0) { Connection<char> currentConnection = connections.GetFirst(); connections.RemoveFirst(); Node<char> currentNode = currentConnection.toNode; if (!visitedNodes.Contains(currentNode.Symbol)) { currentSum += currentConnection.Distance; } visitedNodes.Add(currentNode.Symbol); if (visitedNodes.Count == nodesCount) { break; } foreach (var connection in currentNode.Connections) { if (!visitedNodes.Contains(connection.toNode.Symbol)) { connections.Add(connection); } } } return currentSum; }