/// <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;
        }
Esempio n. 2
0
        public Block(Block block, bool thawChildren)
        {
            ContractsCommon.NotNull(block, "block");
            Contract.Ensures(this.Version == block.Version);
            Contract.Ensures(this.PreviousBlockHash == block.PreviousBlockHash);
            Contract.Ensures(this.Timestamp == block.Timestamp);
            Contract.Ensures(this.DifficultyBits == block.DifficultyBits);
            Contract.Ensures(this.Nonce == block.Nonce);
            Contract.Ensures(this.Transactions.SequencedEquals(block.Transactions));
            Contract.Ensures(this.MerkleRoot == block.MerkleRoot);
            ContractsCommon.ChildrenThawed(Transactions, thawChildren);

            this._version           = block._version;
            this._previousBlockHash = block._previousBlockHash;
            this._timestamp         = block._timestamp;
            this._difficultyBits    = block._difficultyBits;
            this._nonce             = block._nonce;
            if (block._merkleTree != null)
            {
                var tree = new ArrayList <Hash256>(block._merkleTree.Count);
                tree.AddAll(block._merkleTree);
                this._merkleTree = new GuardedList <Hash256>(tree);
            }

            var transactions = new HashedArrayList <Transaction>(block.Transactions.Count);

            transactions.AddAll(FreezableExtensions.ThawChildren(block.Transactions, thawChildren));
            transactions.CollectionChanged += InvalidateMerkleTree;
            this.Transactions = transactions;
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        protected override void Deserialize(Stream stream)
        {
            Version           = ReadUInt32(stream);
            PreviousBlockHash = new Hash256(stream);
            new Hash256(stream); // Throw away the Merkle Root
            Timestamp      = ReadUInt32(stream);
            DifficultyBits = ReadUInt32(stream);
            Nonce          = ReadUInt32(stream);

            var transactionsArr = ReadVarArray <Transaction>(stream);
            var transactions    = new HashedArrayList <Transaction>(transactionsArr.Length);

            transactions.AddAll(transactionsArr);
            transactions.CollectionChanged += InvalidateMerkleTree;
            Transactions = transactions;

            Freeze();
        }
Esempio n. 5
0
        public override void CreateNewInstanceOfInternalC5DataStructure(C5DataStructure dataStructure)
        {
            switch (dataStructure)
            {
            case C5DataStructure.ArrayList:
                InternalC5DataStructure = new ArrayList <T>();
                break;

            case C5DataStructure.LinkedList:
                InternalC5DataStructure = new LinkedList <T>();
                break;

            case C5DataStructure.HashBag:
                InternalC5DataStructure = new HashBag <T>();
                break;

            case C5DataStructure.TreeBag:
                InternalC5DataStructure = new TreeBag <T>();
                break;

            case C5DataStructure.HashedArrayList:
                InternalC5DataStructure = new HashedArrayList <T>();
                break;

            case C5DataStructure.HashedLinkedList:
                InternalC5DataStructure = new HashedLinkedList <T>();
                break;

            case C5DataStructure.SortedArray:
                InternalC5DataStructure = new SortedArray <T>();
                break;

            case C5DataStructure.HashSet:
                InternalC5DataStructure = new HashSet <T>();
                break;

            case C5DataStructure.TreeSet:
                InternalC5DataStructure = new TreeSet <T>();
                break;

            default: throw new ArgumentException("Unknown C5 Collection name");
            }
        }
Esempio n. 6
0
        protected override void Deserialize(Stream stream)
        {
            Version = ReadUInt32(stream);

            var transactionInputsArr = ReadVarArray <TransactionInput>(stream);
            var transactionInputs    = new HashedArrayList <TransactionInput>(transactionInputsArr.Length);

            transactionInputs.AddAll(transactionInputsArr);
            transactionInputs.CollectionChanged += InputOutputChanged;
            TransactionInputs = transactionInputs;

            var transactionOutputsArr = ReadVarArray <TransactionOutput>(stream);
            var transactionOutputs    = new HashedArrayList <TransactionOutput>(transactionOutputsArr.Length);

            transactionOutputs.AddAll(transactionOutputsArr);
            transactionOutputs.CollectionChanged += InputOutputChanged;
            TransactionOutputs = transactionOutputs;

            LockTime = ReadUInt32(stream);

            Freeze();
        }
        public static Sediment Extract(string bstDirectory, GeoRect region, float resolution, PercentProgress progress = null)
        {
            if (progress != null) lock (progress) progress.Report(0);

            var north = (float)Math.Round(region.North + 1);
            var south = (float)Math.Round(region.South - 1);
            var east = (float)Math.Round(region.East + 1);
            var west = (float)Math.Round(region.West - 1);

            if (progress != null) progress.MaximumValue = (((north - south) * (east - west)) + 3);
            var totalProgress = 0;

            var fileId = H5F.open(bstDirectory, H5F.OpenMode.ACC_RDONLY);
            var highResGroup = H5G.open(fileId, "0.10000/G/UNCLASSIFIED/");
            var lowResGroup = H5G.open(fileId, "5.00000/G/UNCLASSIFIED/");
            var dedupeList = new HashedArrayList<SedimentSample>();
            for (var lat = south; lat < north; lat++)
                for (var lon = west; lon < east; lon++)
                {
                    //var data = ReadDataset(highResGroup, 0.1, lowResGroup, 5.0, resolution, (int)lat, (int)lon);
                    var data = ReadDatasetHierarchical(highResGroup, 0.1, lowResGroup, 5.0, resolution, (int)lat, (int)lon);
                    if (data != null) dedupeList.AddAll(data);
                    if (progress != null) lock (progress) progress.Report(totalProgress++);
                }
            var sediment = new Sediment();
            if (progress != null) lock (progress) progress.Report(totalProgress++);
            sediment.Samples.AddRange(dedupeList);
            sediment.Samples.Sort();
            sediment.Samples.TrimToNearestPoints(region);
            if (progress != null) lock (progress) progress.Report(totalProgress++);
            if (lowResGroup != null) H5G.close(lowResGroup);
            if (highResGroup != null) H5G.close(highResGroup);
            H5F.close(fileId);
            if (progress != null) lock (progress) progress.Report(totalProgress);
            return sediment;
        }
 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;
 }
Esempio n. 9
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;
        }
Esempio n. 10
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();
        }