protected override List<Sector> GenerateSectors(List<IndexUnit> indexUnits) { SortedList<Address, List<IndexUnit>> groupings = new SortedList<Address, List<IndexUnit>>(); foreach (IndexUnit indexUnit in indexUnits) { if (!groupings.ContainsKey(indexUnit.Node)) groupings.Add(indexUnit.Node, new List<IndexUnit>()); groupings[indexUnit.Node].Add(indexUnit); } List<Sector> sectors = new List<Sector>(); List<List<IndexUnit>> newGroupings = new List<List<IndexUnit>>(groupings.Values); while (newGroupings.Count > 0) { Sector newSector = new Sector(); List<IndexUnit> initialGrouping = newGroupings[0], addedUnits = new List<IndexUnit>(); newGroupings.Remove(initialGrouping); while (initialGrouping.Count > 0 && newSector.IndexUnits.Count < Constants.INDEX_UNIT_ENTRIES_PER_SECTOR) { newSector.AddIndexUnit(initialGrouping[0]); addedUnits.Add(initialGrouping[0]); initialGrouping.RemoveAt(0); } if (initialGrouping.Count > 0) newGroupings.Add(initialGrouping); else initialGrouping = addedUnits; while (newSector.IndexUnits.Count < Constants.INDEX_UNIT_ENTRIES_PER_SECTOR && newGroupings.Count > 0) { List<List<IndexUnit>> eligibleGroupings = new List<List<IndexUnit>>(); foreach (List<IndexUnit> grouping in newGroupings) if (grouping.Count + newSector.IndexUnits.Count <= Constants.INDEX_UNIT_ENTRIES_PER_SECTOR) eligibleGroupings.Add(grouping); if (eligibleGroupings.Count == 0) break; List<IndexUnit> closestGrouping = PickClosestGrouping(initialGrouping, eligibleGroupings); foreach (IndexUnit i in closestGrouping) newSector.AddIndexUnit(i); initialGrouping.AddRange(closestGrouping); newGroupings.Remove(closestGrouping); } sectors.Add(newSector); } return sectors; }
protected virtual PageData LookupPageData(Address address) { PageData data; Page page = LookupPage(address); Byte type = page.Data[0], childType = page.Data[1]; if (type == (Byte)PageDataType.Node || type == (Byte)PageDataType.Leaf) if (childType == (Byte)NodeChildType.Leaf) data = new Node(address, typeof(Leaf), page.Data); else if (childType == (Byte)NodeChildType.Node) data = new Node(address, typeof(Node), page.Data); else if (childType == (Byte)NodeChildType.Record) data = new Leaf(address, page.Data); else throw new Exception("Not a node"); else if (type == (Byte)PageDataType.Record) data = new Record(address, page.Data); else if (type == (Byte)PageDataType.IndexUnitSector) data = new Sector(address, page.Data); else throw new Exception("Not valid Page Data"); CacheOverflowCheck(); return data; }