/// <summary> /// Use this constructor if you want to clone or shallow copy your BTree instance. /// </summary> /// <param name="BTree">BTree instance you want to shallow copy its tree graph</param> /// <param name="itemType">Type of Item the new BTree instance will hold. Normally, ItemType.Default is used, internally, BTreeGold uses Key and Value types for reusing BTree to enumerate Keys and Values respectively.</param> internal BTree(BTree BTree, ItemType itemType) { btree = new BTreeAlgorithm(BTree.btree); this.SortOrder = BTree.SortOrder; this.itemType = itemType; syncRoot = (Synchronizer)BTree.SyncRoot; }
// Needed for cloning (shallow copy) this BTree. private void Initialize(BTreeAlgorithm BTree) { this.SlotLength = BTree.SlotLength; this.Root = BTree.Root; //Copy CurrentItem. "Copy" as CurrentItem is value type. this.CurrentItem = BTree.CurrentItem; this.Comparer = BTree.Comparer; // create another set of temporary slots for thread safe 'Search' operation support TempSlots = new object[SlotLength + 1]; TempChildren = new TreeNode[SlotLength + 2]; }
/// <summary> /// Copy constructor. This causes the new instance to copy the 'BTree' instance<br/> /// passed as parameter. All items are copied including Comparer object and sort order. /// NOTE: Items stored on the Tree are not duplicated. /// </summary> /// <param name="BTree">BTree object you want to duplicate all its btree graph into this new btree instance</param> public BTree(BTree BTree) { btree = new BTreeAlgorithm((ValidSlotLengths)BTree.btree.SlotLength, BTree.btree.Comparer); this.SortOrder = BTree.SortOrder; BTree.MoveFirst(); while (true) { btree.Add(BTree.CurrentEntry); if (!BTree.MoveNext()) { break; } } btree.MoveFirst(); }
internal BTreeAlgorithm(BTreeAlgorithm BTree) { Initialize(BTree); }
//***************** .NET ICollection API /// <summary> /// Implements the ISerializable interface and raises the deserialization event when the deserialization is complete. /// </summary> /// <param name="sender">Source of the deserialization event</param> #if (!DEVICE) public void OnDeserialization(object sender) { // save current sort order // save btree // - save comparer // - save other btree data try { this.CurrentSortOrder = (SortOrderType)SerializationInfo.GetInt32("SortOrder"); } catch (System.Exception e) { throw new System.Runtime.Serialization.SerializationException(GetStringResource("CurrentSortOrderDeSerializeError"), e); } IComparer Comparer; // save comparer, SlotLength, save Keys & save Values try { Comparer = (IComparer)SerializationInfo.GetValue("Comparer", typeof(IComparer)); } catch (System.Exception e) { throw new System.Runtime.Serialization.SerializationException(GetStringResource("ComparerDeSerializeError"), e); } ValidSlotLengths SlotLength; try { SlotLength = (ValidSlotLengths)SerializationInfo.GetByte("SlotLength"); } catch (System.Exception e) { throw new System.Runtime.Serialization.SerializationException(GetStringResource("SlotLengthDeSerializeError"), e); } btree = new BTreeAlgorithm((ValidSlotLengths)SlotLength, Comparer); object[] Keys, Values; try { Keys = (object[])SerializationInfo.GetValue("Keys", typeof(object)); } catch (System.Exception e) { if (e.Message == "Members Keys was not found.") { Keys = new object[0]; } else { throw new System.Runtime.Serialization.SerializationException(GetStringResource("KeysDeSerializeError"), e); } } if (Keys.Length == 0) { Values = new object[0]; } else { try { Values = (object[])SerializationInfo.GetValue("Values", typeof(object)); } catch (System.Exception e) { throw new System.Runtime.Serialization.SerializationException(GetStringResource("ValuesDeSerializeError"), e); } } if (Keys.Length != Values.Length) { throw new System.Runtime.Serialization.SerializationException(GetStringResource("KeysAndValuesDifferInSizeError")); } for (int i = 0; i < Keys.Length; i++) { if (Keys[i] == null) { throw new System.Runtime.Serialization.SerializationException(GetStringResource("DeSerializedNullKeyError")); } this.Add(Keys[i], Values[i]); } }
/// <summary> /// Use this constructor if you want to:<br/> /// - provide your number of slots per node<br/> /// - your Comparer object<br/> /// - your sort order type /// </summary> /// <param name="SlotLen">Number of slots per node</param> /// <param name="Comparer">Comparer object</param> /// <param name="SortOrder">Sort Order Type</param> public BTree(ValidSlotLengths SlotLen, IComparer Comparer, SortOrderType SortOrder) { this.SortOrder = SortOrder; btree = new BTreeAlgorithm((ValidSlotLengths)SlotLen, Comparer); }
/// <summary> /// Use this constructor if you want to:<br/> /// - provide your desired sort order <br/> /// - your Comparer object that defines how items are sorted/organized.<br/> /// - use default slots per node (6) /// </summary> /// <param name="Comparer">object used when comparing keys</param> /// <param name="SortOrder">Sort Order type</param> /// <example>BTree b3(BTree.SortOrderType.Ascending</example> public BTree(IComparer Comparer, SortOrderType SortOrder) { this.SortOrder = SortOrder; btree = new BTreeAlgorithm(Comparer); }
/// <summary> /// Use this constructor if you want to:<br/> /// - provide your desired sort order type<br/> /// - use default slots per node (6)<br/> /// - use default comparer object /// </summary> /// <param name="SortOrder">sort order type</param> /// <example>BTree b3(BTree.SortOrderType.Ascending</example> public BTree(SortOrderType SortOrder) { this.SortOrder = SortOrder; btree = new BTreeAlgorithm(); }
/// <summary> /// Use this constructor if you want to:<br/> /// - provide number of slots per node <br/> /// - provide your comparer object<br/> /// - use default sort order (ascending) /// </summary> /// <param name="SlotLen">Number of slots per node</param> /// <param name="Comparer">compare object defining how records will be sorted</param> public BTree(ValidSlotLengths SlotLen, IComparer Comparer) { btree = new BTreeAlgorithm((ValidSlotLengths)SlotLen, Comparer); }
/// <summary> /// Use this constructor if you want to:<br/> /// - provide your own Comparer object that defines how your records will be sorted/arranged<br/> /// - use default 6 slots per node<br/> /// - use default ascending sort order /// </summary> /// <param name="Comparer">IComparer implementation that defines how records will be sorted</param> public BTree(IComparer Comparer) { btree = new BTreeAlgorithm(Comparer); }
/// <summary> /// Default constructor. Use this if you want:<br/> /// - default (6) slots per node <br/> /// - default sorting (Ascending)<br/> /// - default comparer /// </summary> public BTree() { btree = new BTreeAlgorithm(); }
/// <summary> /// Use this constructor if:<br/> /// - you want to provide number of slots per node of the tree. <br/> /// </summary> /// <param name="SlotLen">Number of slots per node</param> /// <example>BTree b3(BTree.ValidSlotLengths.SixSlots);</example> public BTree(ValidSlotLengths SlotLen) { btree = new BTreeAlgorithm((ValidSlotLengths)SlotLen); }