/// <summary>Creates a populated <see cref="Collection{T}"/> of <see cref="Landmark"/> /// instances.</summary> /// <param name="board">The board on which the collection of landmarks is to be instantiated.</param> /// <param name="landmarkCoords">Board coordinates of the desired landmarks</param> public static ILandmarkCollection CreateLandmarks( IHexBoard <IHex> board, IFastList <HexCoords> landmarkCoords ) { if (landmarkCoords == null) { throw new ArgumentNullException("landmarkCoords"); } ILandmarkCollection tempLandmarks = null, landmarks = null; try { tempLandmarks = new LandmarkCollection(( from coords in landmarkCoords.AsParallel().AsOrdered() where board.IsOnboard(coords) select new Landmark(coords, board) ).ToList <ILandmark>()); landmarks = tempLandmarks; tempLandmarks = null; } finally { if (tempLandmarks != null) { tempLandmarks.Dispose(); } } return(landmarks); }
/// <summary>Creates a populated <see cref="Collection{T}"/> of <see cref="Landmark"/> /// instances.</summary> /// <param name="board">The board on which the collection of landmarks is to be instantiated.</param> /// <param name="landmarkCoords">Board coordinates of the desired landmarks</param> public static ILandmarkCollection New( INavigableBoard board, IFastList <HexCoords> landmarkCoords ) { int degreeOfParallelism = Math.Max(1, Environment.ProcessorCount - 1); var query = from coords in landmarkCoords.AsParallel() .WithDegreeOfParallelism(degreeOfParallelism) .WithMergeOptions(ParallelMergeOptions.NotBuffered) #if UseSortedDictionary select Landmark.DictionaryPriorityQueueLandmark(coords, board); #else select Landmark.HotPriorityQueueLandmark(coords, board); #endif return(Extensions.InitializeDisposable(() => new LandmarkCollection(query))); }