예제 #1
0
        public HashedArrayList <T> CopyToHashedArrayList <T>(ICollection <T> lst)
        {
            HashedArrayList <T> lstCopy = new HashedArrayList <T>();

            foreach (var item in lst)
            {
                lstCopy.Add((T)item);
            }
            return(lstCopy);
        }
예제 #2
0
        /// <summary>
        /// Read a 1x1 degree square from the HDF5 file, preferentially using data from the high-resolution dataset if it exists, and filling
        /// in any holes in the high-res data from the corresponding area of the low-resolution dataset
        /// </summary>
        /// <param name="highResGroup">Group ID of the high resolution group</param>
        /// <param name="highResolution">Resolution of the high resolution group, in minutes per sample</param>
        /// <param name="lowResGroup">Group ID of the low resolution group</param>
        /// <param name="lowResolution">Resolution of the low resolution group, in minutes per sample</param>
        /// <param name="desiredResolution">Desired resolution of the output data, in minutes per sample</param>
        /// <param name="latitude">Latitude of the south-west corner of the 1x1 degree square to be extracted from the HDF5 file</param>
        /// <param name="longitude">Longitude of the south-west corner of the 1x1 degree square to be extracted from the HDF5 file</param>
        /// <returns></returns>
        static IEnumerable<SedimentSample> ReadDataset(H5FileOrGroupId highResGroup, double highResolution, H5FileOrGroupId lowResGroup, double lowResolution, double desiredResolution, int latitude, int longitude)
        {
            short[,] result = null;
            double resolutionStep;
            double sampleStepSize;

            if (highResGroup != null) result = ReadDataset(highResGroup, latitude, longitude);
            if (result != null)
            {
                resolutionStep = highResolution / 60;
                sampleStepSize = desiredResolution / highResolution;
            }
            else
            {
                if (lowResGroup != null) result = ReadDataset(lowResGroup, latitude, longitude);
                //if (result == null) throw new KeyNotFoundException(string.Format("Unable to locate sediment data for lat: {0}, lon: {1}", latitude, longitude));
                if (result == null) return null;
                resolutionStep = lowResolution / 60.0;
                sampleStepSize = desiredResolution / lowResolution;
            }

            var sedimentList = new HashedArrayList<SedimentSample>();
            for (var i = 0.0; i < result.GetLength(0); i += sampleStepSize)
                for (var j = 0.0; j < result.GetLength(1); j += sampleStepSize)
                    if (result[(int)i, (int)j] > 0) sedimentList.Add(new SedimentSample(latitude + (i * resolutionStep), longitude + (j * resolutionStep), new SedimentSampleBase { SampleValue = result[(int)i, (int)j] }));
            return sedimentList;
        }
예제 #3
0
 static IEnumerable<SedimentSample> BuildSedimentSampleList(double desiredResolution, int latitude, int longitude, Func<int, int, short> dataFunc)
 {
     var resolutionStepSize = desiredResolution / 60;
     var resolutionStepCount = (int)(1.0 / resolutionStepSize);
     var sedimentList = new HashedArrayList<SedimentSample>();
     for (var i = 0; i < resolutionStepCount; i++)
         for (var j = 0; j < resolutionStepCount; j++)
         {
             var sampleValue = dataFunc(i, j);
             if (sampleValue > 0)
                 sedimentList.Add(new SedimentSample(latitude + (i * resolutionStepSize),
                                                     longitude + (j * resolutionStepSize),
                                                     new SedimentSampleBase { SampleValue = sampleValue }));
         }
     return sedimentList;
 }
예제 #4
0
        public static void Main()
        {
            //var eq = new C6.ComparerFactory.EqualityComparer<string>(ReferenceEquals,
            //    SCG.EqualityComparer<string>.Default.GetHashCode);

            //var items = new[] { "-8", "Ab", "6", "-4", "5", "-2", "-1", "1", "10", "8" };
            //var al = new ArrayList<string>(items);
            //var v1 = al.View(al.Count - 2, 2);
            //var v2 = al.View(al.Count - 2, 2);

            var items      = new[] { "-8", "Ab", "6", "-4", "5", "-2", "-1", "1", "10", "8" };
            var collection = new HashedArrayList <string>(items);

            Console.WriteLine(collection.Contains("10"));
            Console.WriteLine(collection.Add("10"));



            // BUG: Sorting
            //var items = new[] { "-8", "Ab", "6", "-4", "5", "-2", "-1", "1", "10", "8" };
            //var collection = new HashedLinkedList<string>(items);

            //var v0 = collection.View(0, 2);
            //var v2 = collection.View(1, 2);
            //var v4 = collection.View(4, 2);
            //var v6 = collection.View(7, 1);
            //var vCount2 = collection.View(collection.Count - 2, 2);

            //Console.WriteLine("Views before calling Sort()");
            //Console.WriteLine($"v0 = {v0}");
            //Console.WriteLine($"v2 = {v2}");
            //Console.WriteLine($"v4 = {v4}");
            //Console.WriteLine($"v6 = {v6}");
            //Console.WriteLine($"vCount2 = {vCount2}");

            //v4.Sort();

            //Console.WriteLine("Views after calling Sort()");
            //Console.WriteLine($"v0 = {v0}");
            //Console.WriteLine($"v2 = {v2}");
            //Console.WriteLine($"v4 = {v4}");
            //Console.WriteLine($"v6 = {v6}");
            //Console.WriteLine($"vCount2 = {vCount2}");



            // ==============================
            // RemoveRange
            //var items = new[] { "8", "Ab", "3", "4", "5", "6", "7", "9" };
            //var collection = new ArrayList<string>(items);
            //var view1 = collection.View(0, 1); // longer
            //var view2 = collection.View(0, 2);
            //var item = view1.Choose();
            //var itms = new ArrayList<string>(new[] { item });

            //view1.RemoveRange(itms);
            //Console.WriteLine(view2);


            //var items = new[] { "8", "Ab", "3", "4", "5", "6", "7", "9" };
            // HLL.Reverse
            //var items = new[] { "a", "b", "c", "d", "e" };
            //var linkedList = new ArrayList<string>(items);
            //var v1 = linkedList.View(0, linkedList.Count);
            //var v2 = linkedList.View(0, 2);
            //v1.Reverse();
            //v1.Reverse();
            //Console.WriteLine(v2);

            // HLL.Sort
            //var items = new[] { "b", "a", "c", "e", "d" };
            //var linkedList = new HashedLinkedList<string>(items);
            //var v1 = linkedList.View(0, 3);
            //var v2 = linkedList.View(3, 2);
            //v1.Sort();
            //Console.WriteLine(v1);
            //Console.WriteLine(v2);

            // HAL.Add()
            //var items = new[] { "8", "Ab", "3", "4", "5", "6", "7", "9" };
            //var arrayList = new LinkedList<string>(items);
            //var v1 = arrayList.View(0, 7);
            //var v2 = arrayList.View(0, 7);
            //v1.Add("333333333");
            //Console.WriteLine(v1);
            //Console.WriteLine(v2);


            //Console.WriteLine(view1.IsValid);
            //Console.WriteLine(view);
            //Console.WriteLine(collection);



            return;

            // Construct list using collection initializer
            //var list = new ArrayList<int>() { 2, 3, 5, 5, 7, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33};
            var list = new ArrayList <int>()
            {
                2, 3
            };
            var backList = list.Backwards();

            backList.ToList().ForEach(x => Console.Write(x + ", "));
            Console.WriteLine(backList.IsValid);

            list.Add(10);
            Console.WriteLine(backList.IsValid);
            //backList.ToList().ForEach(x => Console.Write(x));


            //var list = list1.View(2, list1.Count-2);
            //var v = list.View(3,4);
            //var v2 = v.View(1, 2);
            //var items = new ArrayList<int>() { 3, 13, 7, 17};
            //Console.WriteLine(ArrayList<int>.EmptyArray);



            var dupl = list.FindDuplicates(5);

            Console.WriteLine(dupl);
            list.Add(-100);
            var arr = dupl.ToArray();

            list.Dispose();



            //en.ToList().ForEach(x => Console.WriteLine(x));


            //Console.WriteLine(v);
            //Console.WriteLine(v2);
            //Console.WriteLine(list);

            return;

            // Get index of item
            var index = list.IndexOf(23);

            // Get an index range
            var range = list.GetIndexRange(index, 4);

            // Print range in reverse order
            foreach (var prime in range.Backwards())
            {
                Console.WriteLine(prime);
            }

            // Remove items within index range
            list.RemoveIndexRange(10, 3);

            // Remove item at index
            var second = list.RemoveAt(1);

            // Remove first item
            var first = list.RemoveFirst();

            // Remove last item
            var last = list.RemoveLast();

            // Create array with items in list
            var array = list.ToArray();

            // Clear list
            list.Clear();

            // Check if list is empty
            var isEmpty = list.IsEmpty;

            // Add item
            list.Add(first);

            // Add items from enumerable
            list.AddRange(array);

            // Insert item into list
            list.Insert(1, second);

            // Add item to the end
            list.Add(last);

            // Check if list is sorted
            var isSorted = list.IsSorted();

            // Reverse list
            list.Reverse();

            // Check if list is sorted
            var reverseComparer = ComparerFactory.CreateComparer <int>((x, y) => y.CompareTo(x));

            isSorted = list.IsSorted(reverseComparer);

            // Shuffle list
            var random = new Random(0);

            list.Shuffle(random);

            // Print list using indexer
            for (var i = 0; i < list.Count; i++)
            {
                Console.WriteLine($"{i,2}: {list[i],2}");
            }

            // Check if list contains all items in enumerable
            var containsRange = list.ContainsRange(array);

            // Construct list using enumerable
            var otherList = new ArrayList <int>(array);

            // Add every third items from list
            otherList.AddRange(list.Where((x, i) => i % 3 == 0));

            containsRange = list.ContainsRange(otherList);

            // Remove all items not in enumerable
            otherList.RetainRange(list);

            // Remove all items in enumerable from list
            list.RemoveRange(array);

            // Sort list
            list.Sort();

            // Copy to array
            list.CopyTo(array, 2);

            return;
        }
예제 #5
0
        public void Main()
        {
            // Construct hashed array list using collection initializer
            var list = new HashedArrayList <int> {
                2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59
            };

            // Chose from list
            list.Choose();

            var array = new int[list.Count];

            // Copy list to array
            list.CopyTo(array, 0);

            // Add item to the end of list
            list.Add(61);

            // Add range to list
            array = new[] { 67, 71, 73, 79, 83 };
            list.AddRange(array);

            // Check if list contains an item
            list.Contains(list.Choose());

            // Check if list contains all items in enumerable
            list.ContainsRange(array);

            // Count all occuerence of an item
            list.CountDuplicates(list.Choose());

            // Find an item in list
            var itemToFind = list.Last;

            list.Find(ref itemToFind);

            // Return all occurence of an item
            list.FindDuplicates(itemToFind);

            // Remove within range
            list.RemoveIndexRange(0, 3);

            var range = new[] { list.First, list.Last };

            // Remove all items in enumerable from list
            list.RemoveRange(range);

            // Retain all items in enumarable from list
            list.RetainRange(list.ToArray());

            var lastItem = list.Last;

            // Find last index of an item
            list.LastIndexOf(lastItem);

            // Insert at the end of list
            list.InsertLast(100);

            // Insert at the beginning of list
            list.InsertFirst(-100);

            // Reverse list
            list.Reverse();

            // Shuffle list
            list.Shuffle();

            // Sort list
            list.Sort();

            // Check if list is sorted
            var isSorted = list.IsSorted();

            // Print all items in list by indexer
            var index = 0;

            foreach (var item in list)
            {
                Console.WriteLine($"list[{index++}] = {item}");
            }

            // Clear list
            list.Clear();
        }