00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef __UT_SplayTree_h__
00027 #define __UT_SplayTree_h__
00028
00029
00030 #include "UT_API.h"
00031 class utSplayNode;
00032
00033 class UT_API UT_SplayTree {
00034
00035 public:
00036
00037
00038
00039 explicit UT_SplayTree(int (*fcomp)(const void *, const void *));
00040 UT_SplayTree(const UT_SplayTree &tree);
00041 virtual ~UT_SplayTree(void);
00042
00043
00044
00045 int add(const void *, unsigned maxDepth = 0);
00046
00047
00048
00049 const void *remove(const void * = 0);
00050
00051
00052 void clear(void);
00053
00054
00055 UT_SplayTree &operator+=(const UT_SplayTree &tree);
00056 UT_SplayTree &operator-=(const UT_SplayTree &tree);
00057
00058
00059 UT_SplayTree &operator=(const UT_SplayTree &tree);
00060
00061
00062
00063
00064
00065
00066
00067
00068 int traverse(int (*func)(const void *));
00069 int traverse(int (*func)(const void *,void *),void *data);
00070 int traverseBackward(int (*func)(const void *));
00071 int traverseBackward(int (*func)(const void *,void *),
00072 void *data);
00073
00074
00075 const void *find(const void *data) const;
00076
00077 int entries(void) const {return count; }
00078
00079 private:
00080
00081
00082
00083 void insertNode(utSplayNode *, unsigned maxDepth);
00084 void deleteNode(utSplayNode *);
00085 utSplayNode *findNode(const void *data);
00086 utSplayNode *removeHead(utSplayNode **);
00087 void splay(utSplayNode *);
00088 void splayToDepth(unsigned);
00089 int splayToDepth(utSplayNode *, unsigned, unsigned);
00090
00091
00092 int (*myFcomp)(const void *, const void *);
00093 utSplayNode *myRoot;
00094 int count;
00095 int myNumAdded;
00096 };
00097
00098 #endif