namespace OsmXmlToRegionConverter; public class Region { private HashSet nodes; public ulong regionHash { get; } private TagManager tagManager { get; } public Region(ulong regionHash) { this.regionHash = regionHash; nodes = new HashSet(); tagManager = new TagManager(); } public void AddNode(Node nodeToAdd) { if (nodes.Contains(nodeToAdd)) throw new Exception("Node already in region"); else nodes.Add(nodeToAdd); } public Node[] GetNodes() { return this.nodes.ToArray(); } public const int ByteSizeEmpty = sizeof(int) + sizeof(ulong); public static Region FromBytes(byte[] bytes) { using (MemoryStream m = new MemoryStream(bytes)) { using (BinaryReader r = new BinaryReader(m)) { int nodesInRegionCount = r.ReadInt32(); ulong regionHash = r.ReadUInt64(); Region retRegion = new Region(regionHash); HashSet nodesSet = ByteConverter.GetObjectsFromBytes(bytes.SubArray(ByteSizeEmpty, bytes.Length - ByteSizeEmpty)); foreach(object node in nodesSet) retRegion.AddNode((Node)node); return retRegion; } } } }