/// <summary> /// Searches an object in the tree /// </summary> /// <param name="obj"></param> /// <returns></returns> public virtual ComparableObject Find(ComparableObject obj) { ComparableObject comparableObject; if (base.IsEmpty) { comparableObject = null; } else { int i = obj.CompareTo(Key); if (i == 0) { comparableObject = Key; } else if (i < 0) { comparableObject = Left.Find(obj); } else { comparableObject = Right.Find(obj); } } return(comparableObject); }
/// <summary> /// Dequeue an object /// </summary> /// <returns></returns> public virtual ComparableObject DequeueMin() { int i; if (mCount == 0) { throw new ContainerEmptyException(); } ComparableObject comparableObject1 = array[1]; ComparableObject comparableObject2 = array[mCount]; mCount--; int j; for (i = 1; 2 * i < mCount + 1; i = j) { j = 2 * i; if (j + 1 < mCount + 1 && array[j + 1] < array[j]) { j++; } if (comparableObject2 <= array[j]) { break; } array[i] = array[j]; } array[i] = comparableObject2; return comparableObject1; }
/// <summary> /// Returns whether an object is in the tree /// </summary> /// <param name="obj"></param> /// <returns></returns> public virtual bool IsMember(ComparableObject obj) { bool flag; if (base.IsEmpty) { flag = false; } else if (obj == Key) { flag = true; } else if (obj < Key) { flag = Left.IsMember(obj); } else if (obj > Key) { flag = Right.IsMember(obj); } else { flag = false; } return(flag); }
/// <summary> /// Translation /// </summary> /// <param name="dictionary"></param> /// <param name="inputText"></param> /// <param name="outputText"></param> public static void Translate(TextReader dictionary, TextReader inputText, TextWriter outputText) { string str1; ISearchTree searchTree = new AVLTree(); while ((str1 = dictionary.ReadLine()) != null) { string[] strs1 = str1.Split(null); if ((int)strs1.Length != 2) { throw new InvalidOperationException(); } searchTree.Insert(new Association(strs1[0], strs1[1])); } while ((str1 = inputText.ReadLine()) != null) { string[] strs2 = str1.Split(null); for (int i = 0; i < (int)strs2.Length; i++) { string str2 = strs2[i]; ComparableObject comparableObject = searchTree.Find(new Association(str2)); if (comparableObject == null) { outputText.Write("?{0}? ", str2); } else { Association association = (Association)comparableObject; outputText.Write("{0} ", association.Value); } } outputText.WriteLine(); } }
/// <summary> /// Searches the given object in the hashtable /// </summary> /// <param name="obj"></param> /// <returns></returns> public override ComparableObject Find(ComparableObject obj) { ComparableObject comparableObject2; for (LinkedList.Element element = array[base.H(obj)].Head; element != null; element = element.Next) { ComparableObject comparableObject1 = (ComparableObject)element.Datum; if (obj != comparableObject1) { continue; } comparableObject2 = comparableObject1; return(comparableObject1); } comparableObject2 = null; return(comparableObject2); }
/// <summary> /// Returns whether the given object is contained in the hashtable /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool IsMember(ComparableObject obj) { bool flag; for (LinkedList.Element element = array[base.H(obj)].Head; element != null; element = element.Next) { ComparableObject comparableObject = (ComparableObject)element.Datum; if (obj != comparableObject) { continue; } flag = true; return(flag); } flag = false; return(flag); }
/// <summary> /// Enqueues a new objects on the heap /// </summary> /// <param name="obj"></param> public virtual void Enqueue(ComparableObject obj) { int i; if (mCount == (int)array.Length - 1) { throw new Netron.GraphLib.Analysis.ContainerEmptyException(); } mCount++; for (i = mCount; i > 1 && array[i / 2] > obj; i /= 2) { array[i] = array[i / 2]; Console.WriteLine(i/2 + "->" + i); } array[i] = obj; //Console.WriteLine(mCount + " enqueued"); }
/// <summary> /// Removes an object from the tree /// </summary> /// <param name="obj"></param> public virtual void Withdraw(ComparableObject obj) { if (base.IsEmpty) { throw new ArgumentException("object not found"); } int i = obj.CompareTo(Key); if (i == 0) { if (!Left.IsEmpty) { ComparableObject comparableObject1 = Left.Max; mKey = comparableObject1; Left.Withdraw(comparableObject1); } else if (!Right.IsEmpty) { ComparableObject comparableObject2 = Right.Min; mKey = comparableObject2; Right.Withdraw(comparableObject2); } else { base.DetachKey(); } } else if (i < 0) { Left.Withdraw(obj); } else { Right.Withdraw(obj); } Balance(); }
/// <summary> /// Inserts an object in the tree /// </summary> /// <param name="obj"></param> public virtual void Insert(ComparableObject obj) { if (base.IsEmpty) { base.AttachKey(obj); } else { int i = obj.CompareTo(Key); if (i == 0) { throw new ArgumentException("duplicate mKey"); } if (i < 0) { Left.Insert(obj); } else { Right.Insert(obj); } } Balance(); }
/// <summary> /// Returns whether a given object is in the partition /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool IsMember(ComparableObject obj) { return(((PartitionTree)obj).IsMemberOf(this)); }
/// <summary> /// Removes an elements from the hashtable /// </summary> /// <param name="obj"></param> public override void Withdraw(ComparableObject obj) { array[H(obj)].Extract(obj); mCount--; }
/// <summary> /// Searches for the given object in the set /// </summary> /// <param name="obj"></param> /// <returns></returns> public override ComparableObject Find(ComparableObject obj) { throw new InvalidOperationException(); }
/// <summary> /// Removes an object from the set /// </summary> /// <param name="obj"></param> public override void Withdraw(ComparableObject obj) { Withdraw((int)obj); }
/// <summary> /// Inserts an object in the container /// </summary> /// <param name="obj"></param> public abstract void Insert(ComparableObject obj);
/// <summary> /// Returns whether a given obkect is in the container /// </summary> /// <param name="obj"></param> /// <returns></returns> public abstract bool IsMember(ComparableObject obj);
/// <summary> /// Insert an object in the set /// </summary> /// <param name="obj"></param> /// <remarks>the insert object is cast internally to an int</remarks> public override void Insert(ComparableObject obj) { Insert((int)obj); }
/// <summary> /// Removes an object from the container /// </summary> /// <param name="obj"></param> public abstract void Withdraw(ComparableObject obj);
/// <summary> /// Returns whether an object is in the set /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool IsMember(ComparableObject obj) { return(IsMember((int)obj)); }
/// <summary> /// Searches an object in the container /// </summary> /// <param name="obj"></param> /// <returns></returns> public abstract ComparableObject Find(ComparableObject obj);
/// <summary> /// 'Find' of a given ComparableObject /// </summary> /// <param name="obj"></param> /// <returns></returns> public override ComparableObject Find(ComparableObject obj) { return((ComparableObject)Find((int)obj)); }
/// <summary> /// Inserts an element in the hashtable /// </summary> /// <param name="obj"></param> public override void Insert(ComparableObject obj) { array[base.H(obj)].Append(obj); mCount++; }