From f222dfaf57dff6b5ffe9360e1561a965da4b252e Mon Sep 17 00:00:00 2001 From: "alecf%netscape.com" Date: Thu, 12 Sep 2002 04:52:01 +0000 Subject: [PATCH] fix bug 124182 - move nsAVLTree into htmlparser, since it is the only consumer r=harishd, sr=jst git-svn-id: svn://10.0.0.236/trunk@129311 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/htmlparser/macbuild/htmlparser.xml | 30 + mozilla/htmlparser/src/Makefile.in | 1 + mozilla/htmlparser/src/nsAVLTree.cpp | 2 +- mozilla/htmlparser/src/nsAVLTree.h | 6 +- .../parser/htmlparser/macbuild/htmlparser.xml | 30 + mozilla/parser/htmlparser/src/Makefile.in | 1 + mozilla/parser/htmlparser/src/nsAVLTree.cpp | 2 +- mozilla/parser/htmlparser/src/nsAVLTree.h | 6 +- mozilla/xpcom/build/dlldeps.cpp | 11 - mozilla/xpcom/ds/MANIFEST | 1 - mozilla/xpcom/ds/Makefile.in | 2 - mozilla/xpcom/ds/nsAVLTree.cpp | 636 ------------------ mozilla/xpcom/ds/nsAVLTree.h | 93 --- 13 files changed, 70 insertions(+), 751 deletions(-) delete mode 100644 mozilla/xpcom/ds/nsAVLTree.cpp delete mode 100644 mozilla/xpcom/ds/nsAVLTree.h diff --git a/mozilla/htmlparser/macbuild/htmlparser.xml b/mozilla/htmlparser/macbuild/htmlparser.xml index 109dfe92557..812e77e4f3b 100644 --- a/mozilla/htmlparser/macbuild/htmlparser.xml +++ b/mozilla/htmlparser/macbuild/htmlparser.xml @@ -1130,6 +1130,13 @@ Text Debug + + Name + nsAVLTree.cpp + MacOS + Text + Debug + Name UnicharUtilsStaticDebug.o @@ -1289,6 +1296,11 @@ nsParserService.cpp MacOS + + Name + nsAVLTree.cpp + MacOS + Name UnicharUtilsStaticDebug.o @@ -2359,6 +2371,13 @@ Text Debug + + Name + nsAVLTree.cpp + MacOS + Text + Debug + Name UnicharUtilsStatic.o @@ -2508,6 +2527,11 @@ nsParserService.cpp MacOS + + Name + nsAVLTree.cpp + MacOS + Name UnicharUtilsStatic.o @@ -2658,6 +2682,12 @@ nsParserService.cpp MacOS + + htmlparserDebug.shlb + Name + nsAVLTree.cpp + MacOS + Static Libs diff --git a/mozilla/htmlparser/src/Makefile.in b/mozilla/htmlparser/src/Makefile.in index b206084428e..ad8222bb56b 100644 --- a/mozilla/htmlparser/src/Makefile.in +++ b/mozilla/htmlparser/src/Makefile.in @@ -74,6 +74,7 @@ CPPSRCS = \ nsToken.cpp \ nsViewSourceHTML.cpp\ nsParserMsgUtils.cpp\ + nsAVLTree.cpp\ $(NULL) ifdef MOZ_DEBUG diff --git a/mozilla/htmlparser/src/nsAVLTree.cpp b/mozilla/htmlparser/src/nsAVLTree.cpp index 32e0366c422..5465c78c6d7 100644 --- a/mozilla/htmlparser/src/nsAVLTree.cpp +++ b/mozilla/htmlparser/src/nsAVLTree.cpp @@ -40,7 +40,7 @@ enum eLean {eLeft,eNeutral,eRight}; -struct NS_COM nsAVLNode { +struct nsAVLNode { public: nsAVLNode(void* aValue) { diff --git a/mozilla/htmlparser/src/nsAVLTree.h b/mozilla/htmlparser/src/nsAVLTree.h index 42fbec447c2..45923d671a4 100644 --- a/mozilla/htmlparser/src/nsAVLTree.h +++ b/mozilla/htmlparser/src/nsAVLTree.h @@ -54,17 +54,17 @@ struct nsAVLNode; * @param anObject2 is the second object to be compared * @return -1,0,1 if object1 is less, equal, greater than object2 */ -class NS_COM nsAVLNodeComparitor { +class nsAVLNodeComparitor { public: virtual PRInt32 operator()(void* anItem1,void* anItem2)=0; }; -class NS_COM nsAVLNodeFunctor { +class nsAVLNodeFunctor { public: virtual void* operator()(void* anItem)=0; }; -class NS_COM nsAVLTree { +class nsAVLTree { public: nsAVLTree(nsAVLNodeComparitor& aComparitor, nsAVLNodeFunctor* aDeallocator); ~nsAVLTree(void); diff --git a/mozilla/parser/htmlparser/macbuild/htmlparser.xml b/mozilla/parser/htmlparser/macbuild/htmlparser.xml index 109dfe92557..812e77e4f3b 100644 --- a/mozilla/parser/htmlparser/macbuild/htmlparser.xml +++ b/mozilla/parser/htmlparser/macbuild/htmlparser.xml @@ -1130,6 +1130,13 @@ Text Debug + + Name + nsAVLTree.cpp + MacOS + Text + Debug + Name UnicharUtilsStaticDebug.o @@ -1289,6 +1296,11 @@ nsParserService.cpp MacOS + + Name + nsAVLTree.cpp + MacOS + Name UnicharUtilsStaticDebug.o @@ -2359,6 +2371,13 @@ Text Debug + + Name + nsAVLTree.cpp + MacOS + Text + Debug + Name UnicharUtilsStatic.o @@ -2508,6 +2527,11 @@ nsParserService.cpp MacOS + + Name + nsAVLTree.cpp + MacOS + Name UnicharUtilsStatic.o @@ -2658,6 +2682,12 @@ nsParserService.cpp MacOS + + htmlparserDebug.shlb + Name + nsAVLTree.cpp + MacOS + Static Libs diff --git a/mozilla/parser/htmlparser/src/Makefile.in b/mozilla/parser/htmlparser/src/Makefile.in index b206084428e..ad8222bb56b 100644 --- a/mozilla/parser/htmlparser/src/Makefile.in +++ b/mozilla/parser/htmlparser/src/Makefile.in @@ -74,6 +74,7 @@ CPPSRCS = \ nsToken.cpp \ nsViewSourceHTML.cpp\ nsParserMsgUtils.cpp\ + nsAVLTree.cpp\ $(NULL) ifdef MOZ_DEBUG diff --git a/mozilla/parser/htmlparser/src/nsAVLTree.cpp b/mozilla/parser/htmlparser/src/nsAVLTree.cpp index 32e0366c422..5465c78c6d7 100644 --- a/mozilla/parser/htmlparser/src/nsAVLTree.cpp +++ b/mozilla/parser/htmlparser/src/nsAVLTree.cpp @@ -40,7 +40,7 @@ enum eLean {eLeft,eNeutral,eRight}; -struct NS_COM nsAVLNode { +struct nsAVLNode { public: nsAVLNode(void* aValue) { diff --git a/mozilla/parser/htmlparser/src/nsAVLTree.h b/mozilla/parser/htmlparser/src/nsAVLTree.h index 42fbec447c2..45923d671a4 100644 --- a/mozilla/parser/htmlparser/src/nsAVLTree.h +++ b/mozilla/parser/htmlparser/src/nsAVLTree.h @@ -54,17 +54,17 @@ struct nsAVLNode; * @param anObject2 is the second object to be compared * @return -1,0,1 if object1 is less, equal, greater than object2 */ -class NS_COM nsAVLNodeComparitor { +class nsAVLNodeComparitor { public: virtual PRInt32 operator()(void* anItem1,void* anItem2)=0; }; -class NS_COM nsAVLNodeFunctor { +class nsAVLNodeFunctor { public: virtual void* operator()(void* anItem)=0; }; -class NS_COM nsAVLTree { +class nsAVLTree { public: nsAVLTree(nsAVLNodeComparitor& aComparitor, nsAVLNodeFunctor* aDeallocator); ~nsAVLTree(void); diff --git a/mozilla/xpcom/build/dlldeps.cpp b/mozilla/xpcom/build/dlldeps.cpp index aca53272928..465257e85e8 100644 --- a/mozilla/xpcom/build/dlldeps.cpp +++ b/mozilla/xpcom/build/dlldeps.cpp @@ -65,7 +65,6 @@ #include "nsIFileSpec.h" #include "nsILocalFile.h" #include "nsIGenericFactory.h" -#include "nsAVLTree.h" #include "nsHashtableEnumerator.h" #include "nsIPipe.h" #include "nsCWeakReference.h" @@ -94,14 +93,6 @@ #endif #include "nsVariant.h" -class dummyComparitor: public nsAVLNodeComparitor { -public: - virtual PRInt32 operator()(void* anItem1,void* anItem2) - { - return 0; - } -}; - #ifdef DEBUG extern NS_COM void TestSegmentedBuffer(); @@ -112,7 +103,6 @@ void XXXNeverCalled() nsTextFormatter::snprintf(nsnull,0,nsnull); nsTextFormatter::smprintf(nsnull, nsnull); nsTextFormatter::smprintf_free(nsnull); - dummyComparitor dummy; nsVoidArray(); nsSmallVoidArray(); nsStringHashSet(); @@ -120,7 +110,6 @@ void XXXNeverCalled() nsInt32HashSet(); nsVoidHashSet(); nsValueArray(0); - nsAVLTree(dummy, nsnull); nsSupportsArray(); NS_GetNumberOfAtoms(); nsFileURL(NULL); diff --git a/mozilla/xpcom/ds/MANIFEST b/mozilla/xpcom/ds/MANIFEST index abb3e1c364f..522539e0739 100644 --- a/mozilla/xpcom/ds/MANIFEST +++ b/mozilla/xpcom/ds/MANIFEST @@ -1,4 +1,3 @@ -nsAVLTree.h nsAtomService.h nsCppSharedAllocator.h nsCRT.h diff --git a/mozilla/xpcom/ds/Makefile.in b/mozilla/xpcom/ds/Makefile.in index ee894cdb549..11e2b034ddd 100644 --- a/mozilla/xpcom/ds/Makefile.in +++ b/mozilla/xpcom/ds/Makefile.in @@ -42,7 +42,6 @@ CPPSRCS = \ nsArena.cpp \ nsAtomTable.cpp \ nsAtomService.cpp \ - nsAVLTree.cpp \ nsByteBuffer.cpp \ nsCRT.cpp \ nsConjoiningEnumerator.cpp \ @@ -75,7 +74,6 @@ CPPSRCS = \ $(NULL) EXPORTS = \ - nsAVLTree.h \ nsAtomService.h \ nsCppSharedAllocator.h \ nsCRT.h \ diff --git a/mozilla/xpcom/ds/nsAVLTree.cpp b/mozilla/xpcom/ds/nsAVLTree.cpp deleted file mode 100644 index 32e0366c422..00000000000 --- a/mozilla/xpcom/ds/nsAVLTree.cpp +++ /dev/null @@ -1,636 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsAVLTree.h" - - -enum eLean {eLeft,eNeutral,eRight}; - -struct NS_COM nsAVLNode { -public: - - nsAVLNode(void* aValue) { - mLeft=0; - mRight=0; - mSkew=eNeutral; - mValue=aValue; - } - - nsAVLNode* mLeft; - nsAVLNode* mRight; - eLean mSkew; - void* mValue; -}; - - -/************************************************************ - Now begin the tree class. Don't forget that the comparison - between nodes must occur via the comparitor function, - otherwise all you're testing is pointer addresses. - ************************************************************/ - -/** ------------------------------------------------ - * - * - * @update gess 4/22/98 - * @param - * @return - */ //---------------------------------------------- -nsAVLTree::nsAVLTree(nsAVLNodeComparitor& aComparitor, - nsAVLNodeFunctor* aDeallocator) : - mComparitor(aComparitor), mDeallocator(aDeallocator) { - mRoot=0; - mCount=0; -} - - -static void -avlDeleteTree(nsAVLNode* aNode){ - if (aNode) { - avlDeleteTree(aNode->mLeft); - avlDeleteTree(aNode->mRight); - delete aNode; - } -} - -/** - * - * @update gess12/27/98 - * @param - * @return - */ -nsAVLTree::~nsAVLTree(){ - if (mDeallocator) { - ForEachDepthFirst(*mDeallocator); - } - avlDeleteTree(mRoot); -} - - -class CDoesntExist: public nsAVLNodeFunctor { -public: - CDoesntExist(const nsAVLTree& anotherTree) : mOtherTree(anotherTree) { - } - virtual void* operator()(void* anItem) { - void* result=mOtherTree.FindItem(anItem); - if(result) - return nsnull; - return anItem; - } -protected: - const nsAVLTree& mOtherTree; -}; - -/** - * This method compares two trees (members by identity). - * @update gess12/27/98 - * @param tree to compare against - * @return true if they are identical (contain same stuff). - */ -PRBool nsAVLTree::operator==(const nsAVLTree& aCopy) const{ - CDoesntExist functor(aCopy); - void* theItem=FirstThat(functor); - PRBool result=PRBool(!theItem); - return result; -} - - -/** - * - * @update gess12/27/98 - * @param - * @return - */ -static void -avlRotateRight(nsAVLNode*& aRootNode){ - nsAVLNode* ptr2; - nsAVLNode* ptr3; - - ptr2=aRootNode->mRight; - if(ptr2->mSkew==eRight) { - aRootNode->mRight=ptr2->mLeft; - ptr2->mLeft=aRootNode; - aRootNode->mSkew=eNeutral; - aRootNode=ptr2; - } - else { - ptr3=ptr2->mLeft; - ptr2->mLeft=ptr3->mRight; - ptr3->mRight=ptr2; - aRootNode->mRight=ptr3->mLeft; - ptr3->mLeft=aRootNode; - if(ptr3->mSkew==eLeft) - ptr2->mSkew=eRight; - else ptr2->mSkew=eNeutral; - if(ptr3->mSkew==eRight) - aRootNode->mSkew=eLeft; - else aRootNode->mSkew=eNeutral; - aRootNode=ptr3; - } - aRootNode->mSkew=eNeutral; - return; -} - - - -/** - * - * @update gess12/27/98 - * @param - * @return - */ -static void -avlRotateLeft(nsAVLNode*& aRootNode){ - nsAVLNode* ptr2; - nsAVLNode* ptr3; - - ptr2=aRootNode->mLeft; - if(ptr2->mSkew==eLeft) { - aRootNode->mLeft=ptr2->mRight; - ptr2->mRight=aRootNode; - aRootNode->mSkew=eNeutral; - aRootNode=ptr2; - } - else { - ptr3=ptr2->mRight; - ptr2->mRight=ptr3->mLeft; - ptr3->mLeft=ptr2; - aRootNode->mLeft=ptr3->mRight; - ptr3->mRight=aRootNode; - if(ptr3->mSkew==eRight) - ptr2->mSkew=eLeft; - else ptr2->mSkew=eNeutral; - if(ptr3->mSkew==eLeft) - aRootNode->mSkew=eRight; - else aRootNode->mSkew=eNeutral; - aRootNode=ptr3; - } - aRootNode->mSkew=eNeutral; - return; -} - - -/** ------------------------------------------------ - * - * - * @update gess 4/22/98 - * @param - * @return - */ //---------------------------------------------- -static eAVLStatus -avlInsert(nsAVLNode*& aRootNode, nsAVLNode* aNewNode, - nsAVLNodeComparitor& aComparitor) { - eAVLStatus result=eAVL_unknown; - - if(!aRootNode) { - aRootNode = aNewNode; - return eAVL_ok; - } - - if(aNewNode==aRootNode->mValue) { - return eAVL_duplicate; - } - - PRInt32 theCompareResult=aComparitor(aRootNode->mValue,aNewNode->mValue); - if(0 < theCompareResult) { //if(anItemmValue) - result=avlInsert(aRootNode->mLeft,aNewNode,aComparitor); - if(eAVL_ok==result) { - switch(aRootNode->mSkew){ - case eLeft: - avlRotateLeft(aRootNode); - result=eAVL_fail; - break; - case eRight: - aRootNode->mSkew=eNeutral; - result=eAVL_fail; - break; - case eNeutral: - aRootNode->mSkew=eLeft; - break; - } //switch - }//if - } //if - else { - result=avlInsert(aRootNode->mRight,aNewNode,aComparitor); - if(eAVL_ok==result) { - switch(aRootNode->mSkew){ - case eLeft: - aRootNode->mSkew=eNeutral; - result=eAVL_fail; - break; - case eRight: - avlRotateRight(aRootNode); - result=eAVL_fail; - break; - case eNeutral: - aRootNode->mSkew=eRight; - break; - } //switch - } - } //if - return result; -} - -/** ------------------------------------------------ - * - * - * @update gess 4/22/98 - * @param - * @return - */ //---------------------------------------------- -static void -avlBalanceLeft(nsAVLNode*& aRootNode, PRBool& delOk){ - nsAVLNode* ptr2; - nsAVLNode* ptr3; - eLean balnc2; - eLean balnc3; - - switch(aRootNode->mSkew){ - case eLeft: - ptr2=aRootNode->mLeft; - balnc2=ptr2->mSkew; - if(balnc2!=eRight) { - aRootNode->mLeft=ptr2->mRight; - ptr2->mRight=aRootNode; - if(balnc2==eNeutral){ - aRootNode->mSkew=eLeft; - ptr2->mSkew=eRight; - delOk=PR_FALSE; - } - else{ - aRootNode->mSkew=eNeutral; - ptr2->mSkew=eNeutral; - } - aRootNode=ptr2; - } - else{ - ptr3=ptr2->mRight; - balnc3=ptr3->mSkew; - ptr2->mRight=ptr3->mLeft; - ptr3->mLeft=ptr2; - aRootNode->mLeft=ptr3->mRight; - ptr3->mRight=aRootNode; - if(balnc3==eRight) { - ptr2->mSkew=eLeft; - } - else { - ptr2->mSkew=eNeutral; - } - if(balnc3==eLeft) { - aRootNode->mSkew=eRight; - } - else { - aRootNode->mSkew=eNeutral; - } - aRootNode=ptr3; - ptr3->mSkew=eNeutral; - } - break; - - case eRight: - aRootNode->mSkew=eNeutral; - break; - - case eNeutral: - aRootNode->mSkew=eLeft; - delOk=PR_FALSE; - break; - }//switch - return; -} - -/** ------------------------------------------------ - * - * - * @update gess 4/22/98 - * @param - * @return - */ //---------------------------------------------- -static void -avlBalanceRight(nsAVLNode*& aRootNode, PRBool& delOk){ - nsAVLNode* ptr2; - nsAVLNode* ptr3; - eLean balnc2; - eLean balnc3; - - switch(aRootNode->mSkew){ - case eLeft: - aRootNode->mSkew=eNeutral; - break; - - case eRight: - ptr2=aRootNode->mRight; - balnc2=ptr2->mSkew; - if(balnc2!=eLeft) { - aRootNode->mRight=ptr2->mLeft; - ptr2->mLeft=aRootNode; - if(balnc2==eNeutral){ - aRootNode->mSkew=eRight; - ptr2->mSkew=eLeft; - delOk=PR_FALSE; - } - else{ - aRootNode->mSkew=eNeutral; - ptr2->mSkew=eNeutral; - } - aRootNode=ptr2; - } - else{ - ptr3=ptr2->mLeft; - balnc3=ptr3->mSkew; - ptr2->mLeft=ptr3->mRight; - ptr3->mRight=ptr2; - aRootNode->mRight=ptr3->mLeft; - ptr3->mLeft=aRootNode; - if(balnc3==eLeft) { - ptr2->mSkew=eRight; - } - else { - ptr2->mSkew=eNeutral; - } - if(balnc3==eRight) { - aRootNode->mSkew=eLeft; - } - else { - aRootNode->mSkew=eNeutral; - } - aRootNode=ptr3; - ptr3->mSkew=eNeutral; - } - break; - - case eNeutral: - aRootNode->mSkew=eRight; - delOk=PR_FALSE; - break; - }//switch - return; -} - -/** ------------------------------------------------ - * - * - * @update gess 4/22/98 - * @param - * @return - */ //---------------------------------------------- -static eAVLStatus -avlRemoveChildren(nsAVLNode*& aRootNode,nsAVLNode*& anotherNode, PRBool& delOk){ - eAVLStatus result=eAVL_ok; - - if(!anotherNode->mRight){ - aRootNode->mValue=anotherNode->mValue; //swap - anotherNode=anotherNode->mLeft; - delOk=PR_TRUE; - } - else{ - avlRemoveChildren(aRootNode,anotherNode->mRight,delOk); - if(delOk) - avlBalanceLeft(anotherNode,delOk); - } - - return result; -} - - -/** ------------------------------------------------ - * - * - * @update gess 4/22/98 - * @param - * @return - */ //---------------------------------------------- -static eAVLStatus -avlRemove(nsAVLNode*& aRootNode, void* anItem, PRBool& delOk, - nsAVLNodeComparitor& aComparitor){ - eAVLStatus result=eAVL_ok; - - if(!aRootNode) - delOk=PR_FALSE; - else { - PRInt32 cmp=aComparitor(anItem,aRootNode->mValue); - if(cmp<0){ - avlRemove(aRootNode->mLeft,anItem,delOk,aComparitor); - if(delOk) - avlBalanceRight(aRootNode,delOk); - } - else if(cmp>0){ - avlRemove(aRootNode->mRight,anItem,delOk,aComparitor); - if(delOk) - avlBalanceLeft(aRootNode,delOk); - } - else{ //they match... - nsAVLNode* temp=aRootNode; - if(!aRootNode->mRight) { - aRootNode=aRootNode->mLeft; - delOk=PR_TRUE; - delete temp; - } - else if(!aRootNode->mLeft) { - aRootNode=aRootNode->mRight; - delOk=PR_TRUE; - delete temp; - } - else { - avlRemoveChildren(aRootNode,aRootNode->mLeft,delOk); - if(delOk) - avlBalanceRight(aRootNode,delOk); - } - } - } - - return result; -} - -/** ------------------------------------------------ - * - * - * @update gess 4/22/98 - * @param - * @return - */ //---------------------------------------------- -eAVLStatus -nsAVLTree::AddItem(void* anItem){ - eAVLStatus result=eAVL_ok; - - nsAVLNode* theNewNode=new nsAVLNode(anItem); - result=avlInsert(mRoot,theNewNode,mComparitor); - if(eAVL_duplicate!=result) - mCount++; - else { - delete theNewNode; - } - return result; -} - -/** ------------------------------------------------ - * - * - * @update gess 4/22/98 - * @param - * @return - */ //---------------------------------------------- -void* nsAVLTree::FindItem(void* aValue) const{ - nsAVLNode* result=mRoot; - PRInt32 count=0; - while(result) { - count++; - PRInt32 cmp=mComparitor(aValue,result->mValue); - if(0==cmp) { - //we matched... - break; - } - else if(0>cmp){ - //theNode was greater... - result=result->mLeft; - } - else { - //aValue is greater... - result=result->mRight; - } - } - if(result) { - return result->mValue; - } - return nsnull; -} - - -/** - * - * @update gess12/30/98 - * @param - * @return - */ -eAVLStatus -nsAVLTree::RemoveItem(void* aValue){ - PRBool delOk=PR_TRUE; - eAVLStatus result=avlRemove(mRoot,aValue,delOk,mComparitor); - if(eAVL_ok==result) - mCount--; - return result; -} - -/** - * - * @update gess9/11/98 - * @param - * @return - */ -static void -avlForEachDepthFirst(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor){ - if(aNode) { - avlForEachDepthFirst(aNode->mLeft,aFunctor); - avlForEachDepthFirst(aNode->mRight,aFunctor); - aFunctor(aNode->mValue); - } -} - - -/** - * - * @update gess9/11/98 - * @param - * @return - */ -void -nsAVLTree::ForEachDepthFirst(nsAVLNodeFunctor& aFunctor) const{ - ::avlForEachDepthFirst(mRoot,aFunctor); -} - -/** - * - * @update gess9/11/98 - * @param - * @return - */ -static void -avlForEach(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor) { - if(aNode) { - avlForEach(aNode->mLeft,aFunctor); - aFunctor(aNode->mValue); - avlForEach(aNode->mRight,aFunctor); - } -} - - -/** - * - * @update gess9/11/98 - * @param - * @return - */ -void -nsAVLTree::ForEach(nsAVLNodeFunctor& aFunctor) const{ - ::avlForEach(mRoot,aFunctor); -} - - -/** - * - * @update gess9/11/98 - * @param - * @return - */ -static void* -avlFirstThat(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor) { - void* result=nsnull; - if(aNode) { - result = avlFirstThat(aNode->mLeft,aFunctor); - if (result) { - return result; - } - result = aFunctor(aNode->mValue); - if (result) { - return result; - } - result = avlFirstThat(aNode->mRight,aFunctor); - } - return result; -} - -/** - * - * @update gess9/11/98 - * @param - * @return - */ -void* -nsAVLTree::FirstThat(nsAVLNodeFunctor& aFunctor) const{ - return ::avlFirstThat(mRoot,aFunctor); -} - diff --git a/mozilla/xpcom/ds/nsAVLTree.h b/mozilla/xpcom/ds/nsAVLTree.h deleted file mode 100644 index 42fbec447c2..00000000000 --- a/mozilla/xpcom/ds/nsAVLTree.h +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsAVLTree_h___ -#define nsAVLTree_h___ - - -#include "nscore.h" - - -enum eAVLStatus {eAVL_unknown,eAVL_ok,eAVL_fail,eAVL_duplicate}; - - -struct nsAVLNode; - -/** - * - * @update gess12/26/98 - * @param anObject1 is the first object to be compared - * @param anObject2 is the second object to be compared - * @return -1,0,1 if object1 is less, equal, greater than object2 - */ -class NS_COM nsAVLNodeComparitor { -public: - virtual PRInt32 operator()(void* anItem1,void* anItem2)=0; -}; - -class NS_COM nsAVLNodeFunctor { -public: - virtual void* operator()(void* anItem)=0; -}; - -class NS_COM nsAVLTree { -public: - nsAVLTree(nsAVLNodeComparitor& aComparitor, nsAVLNodeFunctor* aDeallocator); - ~nsAVLTree(void); - - PRBool operator==(const nsAVLTree& aOther) const; - PRInt32 GetCount(void) const {return mCount;} - - //main functions... - eAVLStatus AddItem(void* anItem); - eAVLStatus RemoveItem(void* anItem); - void* FindItem(void* anItem) const; - void ForEach(nsAVLNodeFunctor& aFunctor) const; - void ForEachDepthFirst(nsAVLNodeFunctor& aFunctor) const; - void* FirstThat(nsAVLNodeFunctor& aFunctor) const; - -protected: - - nsAVLNode* mRoot; - PRInt32 mCount; - nsAVLNodeComparitor& mComparitor; - nsAVLNodeFunctor* mDeallocator; -}; - - -#endif /* nsAVLTree_h___ */ -