public GEDFile(XmlDocument Doc) { GEDFileEntry Entry; // Top level nodes are "Head", "Subm", "Indi", "Fam", "Sour" foreach (XmlNode Node in Doc.DocumentElement.ChildNodes) { Entry = null; switch (Node.Name.ToUpper()) { case "HEAD": Entry = new GEDFileEntryHead(); break; case "SUBM": Entry = new GEDFileEntrySubm(); break; case "INDI": Entry = new GEDFileEntryIndi(); break; case "FAM": Entry = new GEDFileEntryFam(); break; case "SOUR": Entry = new GEDFileEntrySour(); break; default: frmGEDXmlEditor.Log("Node type not recognised: " + Node.Name); break; } if (Entry != null) { Entry.Node = Node; Entries.Add(Entry); } } // Now, for each family, cross-reference individuals foreach (GEDFileEntry FEntry in Entries) { if (FEntry.ListType() == "FAM") { ((GEDFileEntryFam)FEntry).ResolveXrefs(); } } }
//============================================================ // <T>修正删除元素的哈希表。</T> // // @param entries 入口对象列表 // @param index 删除的索引位置 //============================================================ public static void Remove(FEntry[] entries, int index) { int length = entries.Length; for (int n = 0; n < length; n++) { FEntry entry = entries[n]; while (null != entry) { if (entry._index > index) { entry._index--; } entry = entry._next; } } }
//============================================================ // <T>调整哈希表大小。</T> // // @param entries 入口对象列表 // @param count 总数 // @return 调整后的入口对象列表 //============================================================ public static FEntry[] Resize(FEntry[] entries, int count) { FEntry[] alloc = new FEntry[count]; if (null != entries) { int total = entries.Length; for (int n = 0; n < total; n++) { FEntry entry = entries[n]; while (null != entry) { FEntry next = entry._next; // 设置对象 int index = entry._hash % count; entry._next = alloc[index]; alloc[index] = entry; entry = next; } } } return(alloc); }
//============================================================ // <T>设置内容。</T> // // @param index 索引位置 // @param next 下一个对象 //============================================================ public void Set(int index, FEntry next) { _index = index; _next = next; }
//============================================================ // <T>构造哈希入口对象。</T> // // @param hash 哈希值 // @param index 索引位置 // @param next 下一个对象 //============================================================ public FEntry(int hash, int index, FEntry next) { _hash = hash; _index = index; _next = next; }