home *** CD-ROM | disk | FTP | other *** search
- #ifndef _INC_CLTN_HPP
- #define _INC_CLTN_HPP
- template <class K, class V> class TC_TPtrMap;
- template <class K, class V> class TC_TPtrMapIter;
-
- // **********************************************************************
- class TC_COREEX_EXPORT TC_CPtrMap
- {
-
- // **********************************************************************
- public:
- struct Pair
- {
- public: void * m_Key ;
- public: void * m_Val ;
- public: Pair ( void * key, void * val)
- {
- m_Key = key;
- m_Val = val;
- } // end of func
- // **********************************************************************
-
-
- }; // end of class Pair
-
- // **********************************************************************
- typedef TC_TArrayPTR <Pair> SrtCltn;
- protected: SrtCltn m_Cltn ;
- protected: TCCmpFunc m_CmpFunc ;
- protected: int m_CurPos ;
- protected: void * GetKey (int idx) ;
- protected: void * GetVal (int idx) ;
- protected: void * DoSearch (void * searchKey, int &pos) ;
- public: TC_CPtrMap (TCCmpFunc cmp_func) ;
- public: void SetCmpFunc (TCCmpFunc cmp_func)
- {
- m_CmpFunc = cmp_func;
- } // end of func
- // **********************************************************************
-
- public: TCCmpFunc GetCmpFunc ()
- {
- return m_CmpFunc;
- } // end of func
- // **********************************************************************
-
- public: int InsertAssoc (void * key, void * val) ;
- public: BOOL DeleteAssoc (void * key) ;
- protected: virtual void DestroyValue (void * val) ;
- public: BOOL RemoveAssoc (void * key) ;
- public: BOOL RemoveByIdx (int idx) ;
- public: int GetCurPos () ;
- public: BOOL InsertInCurPos (void* key, void * val) ;
- public: void DeleteAll () ;
- public: void RemoveAll () ;
- public: void * Search (void * searchKey, TCCmpFunc cmp_func=0) ;
- public: long Count () ;
- public: void * ValByIdx (int idx) ;
- public: void * KeyByIdx (int idx) ;
-
- }; // end of class TC_CPtrMap
-
- // **********************************************************************
-
- // **********************************************************************
- class TC_COREEX_EXPORT TC_CPtrMapIter
- {
- protected: TC_CPtrMap & m_Map ;
- protected: int m_Idx ;
- public: TC_CPtrMapIter (const TC_CPtrMap & map) ;
- public: void Reset () ;
- public: void BeginFrom (void * key) ;
- public: void * Next () ;
- public: BOOL More () ;
-
- }; // end of class TC_CPtrMapIter
-
- // **********************************************************************
-
- // **********************************************************************
- template <class K, class V>
- class TC_TPtrMap
- {
- friend TC_TPtrMapIter<K,V>;
- public:
- typedef int (*MapCmpFunc)(const K*, const K*);
-
- // **********************************************************************
- public:
- class Map
- : public TC_CPtrMap
- {
- public: Map (::TCCmpFunc cmp_func)
- : TC_CPtrMap (cmp_func)
- {
-
- } // end of func
- // **********************************************************************
-
- protected: virtual void DestroyValue (void * val)
- {
- delete (V*)val;
- } // end of func
- // **********************************************************************
-
-
- }; // end of class Map
-
- // **********************************************************************
- private: Map m_Map ;
- public: TC_TPtrMap (MapCmpFunc cmp_func)
- : m_Map((::TCCmpFunc)cmp_func)
- {
- } // end of func
- // **********************************************************************
-
- public: MapCmpFunc GetCmpFunc ()
- {
- return (MapCmpFunc)m_Map.GetCmpFunc();
- } // end of func
- // **********************************************************************
-
- public: int InsertAssoc (K * key, V * val)
- {
- return m_Map.InsertAssoc(key,val);
- } // end of func
- // **********************************************************************
-
- public: BOOL DeleteAssoc (K * key)
- {
- return m_Map.DeleteAssoc(key);
-
-
- } // end of func
- // **********************************************************************
-
- public: BOOL RemoveAssoc (K * key)
- {
- return m_Map.RemoveAssoc(key);
- } // end of func
- // **********************************************************************
-
- public: BOOL InsertInCurPos (K* key, V * val)
- {
- return m_Map.InsertInCurPos(key,val);
- } // end of func
- // **********************************************************************
-
- public: BOOL RemoveByIdx (int idx)
- {
- return m_Map.RemoveByIdx(idx);
- } // end of func
- // **********************************************************************
-
- public: V * Search (K * searchKey, MapCmpFunc cmp_func=0)
- {
- return (V*) m_Map.Search(searchKey, (::TCCmpFunc)cmp_func);
- } // end of func
- // **********************************************************************
-
- public: V * operator [] (K * key)
- {
- return Search(key);
- } // end of func
- // **********************************************************************
-
- public: V * ValByIdx (int idx)
- {
- return (V*) m_Map.ValByIdx(idx);
- } // end of func
- // **********************************************************************
-
- public: K * KeyByIdx (int idx)
- {
- return (K*) m_Map.KeyByIdx(idx);
- } // end of func
- // **********************************************************************
-
- public: long Count ()
- {
- return m_Map.Count();
- } // end of func
- // **********************************************************************
-
- public: void DeleteAll ()
- {
- m_Map.DeleteAll();
- } // end of func
- // **********************************************************************
-
- public: void RemoveAll ()
- {
- m_Map.RemoveAll();
- } // end of func
- // **********************************************************************
-
- public: int GetCurPos ()
- {
- return m_Map.GetCurPos();
- } // end of func
- // **********************************************************************
-
-
- }; // end of class TC_TPtrMap
-
- // **********************************************************************
-
- // **********************************************************************
- template <class K, class V>
- class TC_TPtrMapIter
- : public TC_TIterator<V>
- {
- protected: TC_CPtrMapIter m_Iter ;
- public: TC_TPtrMapIter (const TC_TPtrMap<K,V> & map)
- : m_Iter(map.m_Map)
- {
- } // end of func
- // **********************************************************************
-
- public: void BeginFrom (K * key)
- {
- m_Iter.BeginFrom(key);
- } // end of func
- // **********************************************************************
-
- public: void Reset ()
- {
- m_Iter.Reset();
- } // end of func
- // **********************************************************************
-
- public: BOOL More ()
- {
- return m_Iter.More();
- } // end of func
- // **********************************************************************
-
- public: V * Next ()
- {
- return (V*) m_Iter.Next();
-
-
-
- } // end of func
- // **********************************************************************
-
-
- }; // end of class TC_TPtrMapIter
-
- // **********************************************************************
-
- // **********************************************************************
- class TC_COREEX_EXPORT TC_CSNode
- {
- friend class TC_CSList;
-
- protected: TC_CSNode * m_Next ;
- protected: void * m_Item ;
- public: TC_CSNode (void * item)
- {
- m_Item = item;
- m_Next = 0;
- } // end of func
- // **********************************************************************
-
- public: TC_CSNode * Next ()
- {
- return m_Next;
- } // end of func
- // **********************************************************************
-
- public: void SetItem (void * item)
- {
- m_Item = item;
- } // end of func
- // **********************************************************************
-
- public: void * GetItem () ;
-
- }; // end of class TC_CSNode
-
- // **********************************************************************
-
- // **********************************************************************
- class TC_COREEX_EXPORT TC_CKeyNode
- : public TC_CSNode
- {
- private: HANDLE m_Key ;
- public: TC_CKeyNode (void * item)
- : TC_CSNode (item)
- {
- m_Key = 0;
- } // end of func
- // **********************************************************************
-
- public: TC_CKeyNode * Next ()
- {
- return (TC_CKeyNode*)m_Next;
- } // end of func
- // **********************************************************************
-
- public: void SetKey (HANDLE key)
- {
- m_Key = key;
- } // end of func
- // **********************************************************************
-
- public: HANDLE GetKey ()
- {
- return m_Key;
- } // end of func
- // **********************************************************************
-
-
- }; // end of class TC_CKeyNode
-
- // **********************************************************************
-
- // **********************************************************************
- class TC_COREEX_EXPORT TC_CNameNode
- : public TC_CKeyNode
- {
- protected: TC_CString m_Name ;
- public: TC_CNameNode (void * item)
- : TC_CKeyNode(item)
- {
-
- } // end of func
- // **********************************************************************
-
- public: TC_CNameNode * Next ()
- {
- return (TC_CNameNode*)m_Next;
- } // end of func
- // **********************************************************************
-
- public: void SetName (const char * name) ;
- public: const char * GetName () ;
-
- }; // end of class TC_CNameNode
-
- // **********************************************************************
-
- // **********************************************************************
- class TC_COREEX_EXPORT TC_CSList
- {
- public:
- typedef void* (*ITR_FUNC)(void*, void*);
-
-
-
- protected: TC_CSNode * m_Root ;
- protected: TC_CSNode * m_Tail ;
- protected: int m_Count ;
- public: TC_CSList ()
- {
- Reset();
- } // end of func
- // **********************************************************************
-
- public: virtual ~TC_CSList () ;
- public: TC_CSNode * Root ()
- {
- return m_Root;
- } // end of func
- // **********************************************************************
-
- public: int Count () ;
- public: void Add (TC_CSNode & node) ;
- public: void Add (void * item)
- {
- Add (*new TC_CSNode(item));
- } // end of func
- // **********************************************************************
-
- public: void Append (TC_CSNode & node) ;
- public: void Append (void * item)
- {
- Append (*new TC_CSNode(item));
- } // end of func
- // **********************************************************************
-
- public: BOOL Remove (TC_CSNode & node) ;
- public: TC_CSNode * Remove (void * item) ;
- public: void * Iterate (ITR_FUNC itr_func, void * arg) ;
- public: void Reset ()
- {
- m_Tail = 0;
- m_Root = 0;
- m_Count = 0;
- } // end of func
- // **********************************************************************
-
-
- }; // end of class TC_CSList
-
- // **********************************************************************
-
- // **********************************************************************
- class TC_COREEX_EXPORT TC_CSListIter
- {
- protected: TC_CSList * m_List ;
- protected: TC_CSNode * m_Curr ;
- public: TC_CSListIter (TC_CSList * list) ;
- public: void Reset () ;
- public: TC_CSNode * Current () ;
- public: TC_CSNode * Next () ;
-
- }; // end of class TC_CSListIter
-
- // **********************************************************************
-
- // **********************************************************************
- class TC_COREEX_EXPORT TC_CSListValIter
- : public TC_CSListIter
- {
- public: TC_CSListValIter (TC_CSList * list) ;
- public: void * CurrentVal () ;
- public: void * NextVal () ;
-
- }; // end of class TC_CSListValIter
-
- // **********************************************************************
-
- // **********************************************************************
- class TC_COREEX_EXPORT TC_CKeyList
- : public TC_CSList
- {
- private:
- void Add(TC_CSNode& node);
- void Append(TC_CSNode& node);
- BOOL Remove(TC_CSNode& node);
- public: TC_CKeyList ()
- : TC_CSList()
- {
- } // end of func
- // **********************************************************************
-
- public: TC_CKeyNode * Root ()
- {
- return (TC_CKeyNode*)m_Root;
- } // end of func
- // **********************************************************************
-
- public: void Add (TC_CKeyNode & node)
- {
- TC_CSList::Add(node);
- } // end of func
- // **********************************************************************
-
- public: void Add (void * item)
- {
- TC_CSList::Add (*new TC_CKeyNode(item));
- } // end of func
- // **********************************************************************
-
- public: void Append (TC_CKeyNode & node)
- {
- TC_CSList::Append(node);
- } // end of func
- // **********************************************************************
-
- public: void Append (void * item)
- {
- TC_CSList::Append (*new TC_CKeyNode(item));
- } // end of func
- // **********************************************************************
-
- public: BOOL Remove (TC_CKeyNode & node)
- {
- return TC_CSList::Remove(node);
- } // end of func
- // **********************************************************************
-
- public: TC_CKeyNode * Remove (void * item)
- {
- return (TC_CKeyNode*)TC_CSList::Remove(item);
- } // end of func
- // **********************************************************************
-
- public: void * Find (HANDLE key) ;
-
- }; // end of class TC_CKeyList
-
- // **********************************************************************
-
- // **********************************************************************
- class TC_COREEX_EXPORT TC_CNameList
- : public TC_CKeyList
- {
- public: TC_CNameList ()
- : TC_CKeyList()
- {
- } // end of func
- // **********************************************************************
-
- public: TC_CNameNode * Root ()
- {
- return (TC_CNameNode*)m_Root;
- } // end of func
- // **********************************************************************
-
- public: void Add (TC_CNameNode & node)
- {
- TC_CKeyList::Add(node);
- } // end of func
- // **********************************************************************
-
- public: void Add (void * item)
- {
- TC_CKeyList::Add (*new TC_CNameNode(item));
- } // end of func
- // **********************************************************************
-
- public: void Append (TC_CNameNode & node)
- {
- TC_CKeyList::Append(node);
- } // end of func
- // **********************************************************************
-
- public: void Append (void * item)
- {
- TC_CKeyList::Append (*new TC_CNameNode(item));
- } // end of func
- // **********************************************************************
-
- public: BOOL Remove (TC_CNameNode & node)
- {
- return TC_CKeyList::Remove(node);
- } // end of func
- // **********************************************************************
-
- public: TC_CNameNode * Remove (void * item)
- {
- return (TC_CNameNode*)TC_CKeyList::Remove(item);
- } // end of func
- // **********************************************************************
-
- public: void * Find (HANDLE key)
- {
- return TC_CKeyList::Find(key);
- } // end of func
- // **********************************************************************
-
- public: void * Find (const char * name) ;
-
- }; // end of class TC_CNameList
-
- // **********************************************************************
-
- // **********************************************************************
- class TC_COREEX_EXPORT TC_CLockList
- : public TC_CNameList
- {
- private: TC_CRWAccess * m_Lock ;
- public: TC_CLockList () ;
- public: ~TC_CLockList () ;
- public: void Add (TC_CNameNode & node) ;
- public: void Add (void * item)
- {
- Add (*new TC_CNameNode(item));
- } // end of func
- // **********************************************************************
-
- public: void Append (TC_CNameNode & node) ;
- public: void Append (void * item)
- {
- Append (*new TC_CNameNode(item));
- } // end of func
- // **********************************************************************
-
- public: BOOL Remove (TC_CNameNode & node) ;
- public: TC_CNameNode * Remove (void * item)
- {
- return Remove(item);
- } // end of func
- // **********************************************************************
-
- public: void * Iterate (ITR_FUNC itr_func, void * arg) ;
- public: void * Find (HANDLE key) ;
- public: void * Find (const char * name) ;
- public: TC_CRWAccess * GetLock () ;
-
- }; // end of class TC_CLockList
-
- // **********************************************************************
-
- // **********************************************************************
- template <class Item>
- class TC_TSNode
- : public TC_CSNode
- {
- public: TC_TSNode (Item * item)
- : TC_CSNode(item)
- {
- } // end of func
- // **********************************************************************
-
- public: TC_TSNode<Item> * Next ()
- {
- return (TC_TSNode<Item>*)m_Next;
- } // end of func
- // **********************************************************************
-
- public: void SetItem (Item * item)
- {
- m_Item = item;
- } // end of func
- // **********************************************************************
-
- public: Item * GetItem ()
- {
- return (Item*)m_Item;
- } // end of func
- // **********************************************************************
-
-
- }; // end of class TC_TSNode
-
- // **********************************************************************
-
- // **********************************************************************
- template <class Item>
- class TC_TKeyNode
- : public TC_CKeyNode
- {
- public: TC_TKeyNode (Item * item)
- : TC_CKeyNode(item)
- {
- } // end of func
- // **********************************************************************
-
- public: TC_TKeyNode<Item> * Next ()
- {
- return (TC_TKeyNode<Item>*)m_Next;
- } // end of func
- // **********************************************************************
-
- public: void SetItem (Item * item)
- {
- m_Item = item;
- } // end of func
- // **********************************************************************
-
- public: Item * GetItem ()
- {
- return (Item*)m_Item;
- } // end of func
- // **********************************************************************
-
-
- }; // end of class TC_TKeyNode
-
- // **********************************************************************
-
- // **********************************************************************
- template <class Item>
- class TC_TNameNode
- : public TC_CNameNode
- {
- public: TC_TNameNode (Item * item)
- : TC_CNameNode(item)
- {
- } // end of func
- // **********************************************************************
-
- public: TC_TNameNode<Item> * Next ()
- {
- return (TC_TNameNode<Item>*)m_Next;
- } // end of func
- // **********************************************************************
-
- public: void SetItem (Item * item)
- {
- m_Item = item;
- } // end of func
- // **********************************************************************
-
- public: Item * GetItem ()
- {
- return (Item*)m_Item;
- } // end of func
- // **********************************************************************
-
-
- }; // end of class TC_TNameNode
-
- // **********************************************************************
-
- // **********************************************************************
- template <class Item>
- class TC_TSList
- : public TC_CSList
- {
- typedef Item* (*ITR_FUNC)(Item*, void*);
- public: TC_TSList ()
- : TC_CSList()
- {
- } // end of func
- // **********************************************************************
-
- public: TC_TSNode<Item>* Root ()
- {
- return (TC_TSNode<Item>*)m_Root;
- } // end of func
- // **********************************************************************
-
- public: void Add (TC_TSNode<Item>& node)
- {
- TC_CSList::Add(node);
- } // end of func
- // **********************************************************************
-
- public: void Add (Item* item)
- {
- TC_CSList::Add(*new TC_TSNode<Item>(item));
- } // end of func
- // **********************************************************************
-
- public: void Append (TC_TSNode<Item>& node)
- {
- TC_CSList::Append(node);
- } // end of func
- // **********************************************************************
-
- public: void Append (Item* item)
- {
- TC_CSList::Append(*new TC_TSNode<Item>(item));
- } // end of func
- // **********************************************************************
-
- public: BOOL Remove (TC_TSNode<Item>& node)
- {
- return TC_CSList::Remove(node);
- } // end of func
- // **********************************************************************
-
- public: TC_TSNode<Item>* Remove (Item * item)
- {
- return (TC_TSNode<Item>*) TC_CSList::Remove(item);
- } // end of func
- // **********************************************************************
-
- public: Item * Iterate (ITR_FUNC itr_func, void* arg)
- {
- return (Item*)TC_CSList::Iterate((TC_CSList::ITR_FUNC)itr_func, arg);
- } // end of func
- // **********************************************************************
-
-
- }; // end of class TC_TSList
-
- // **********************************************************************
-
- // **********************************************************************
- template <class Item>
- class TC_TKeyList
- : public TC_CKeyList
- {
- typedef Item* (*ITR_FUNC)(Item*, void*);
- public: TC_TKeyList ()
- : TC_CKeyList()
- {
- } // end of func
- // **********************************************************************
-
- public: TC_TKeyNode<Item>* Root ()
- {
- return (TC_TKeyNode<Item>*)m_Root;
- } // end of func
- // **********************************************************************
-
- public: void Add (TC_TKeyNode<Item>& node)
- {
- TC_CKeyList::Add(node);
- } // end of func
- // **********************************************************************
-
- public: void Add (Item* item)
- {
- TC_CKeyList::Add(*new TC_TKeyNode<Item>(item));
- } // end of func
- // **********************************************************************
-
- public: void Append (TC_TKeyNode<Item>& node)
- {
- TC_CKeyList::Append(node);
- } // end of func
- // **********************************************************************
-
- public: void Append (Item* item)
- {
- TC_CKeyList::Append(*new TC_TKeyNode<Item>(item));
- } // end of func
- // **********************************************************************
-
- public: BOOL Remove (TC_TKeyNode<Item>& node)
- {
- return TC_CKeyList::Remove(node);
- } // end of func
- // **********************************************************************
-
- public: TC_TKeyNode<Item>* Remove (Item * item)
- {
- return (TC_TKeyNode<Item>*) TC_CKeyList::Remove(item);
- } // end of func
- // **********************************************************************
-
- public: Item * Iterate (ITR_FUNC itr_func, void* arg)
- {
- return (Item*)TC_CKeyList::Iterate((TC_CKeyList::ITR_FUNC)itr_func, arg);
- } // end of func
- // **********************************************************************
-
- public: Item * Find (HANDLE key)
- {
- return (Item*)TC_CKeyList::Find(key);
- } // end of func
- // **********************************************************************
-
-
- }; // end of class TC_TKeyList
-
- // **********************************************************************
-
- // **********************************************************************
- template <class Item>
- class TC_TNameList
- : public TC_CNameList
- {
- typedef Item* (*ITR_FUNC)(Item*, void*);
- public: TC_TNameList ()
- : TC_CNameList()
- {
- } // end of func
- // **********************************************************************
-
- public: TC_TNameNode<Item>* Root ()
- {
- return (TC_TNameNode<Item>*)m_Root;
- } // end of func
- // **********************************************************************
-
- public: void Add (TC_TNameNode<Item>& node)
- {
- TC_CNameList::Add(node);
- } // end of func
- // **********************************************************************
-
- public: void Add (Item* item)
- {
- TC_CNameList::Add(*new TC_TNameNode<Item>(item));
- } // end of func
- // **********************************************************************
-
- public: void Append (TC_TNameNode<Item>& node)
- {
- TC_CNameList::Append(node);
- } // end of func
- // **********************************************************************
-
- public: void Append (Item* item)
- {
- TC_CNameList::Append(*new TC_TNameNode<Item>(item));
- } // end of func
- // **********************************************************************
-
- public: BOOL Remove (TC_TNameNode<Item>& node)
- {
- return TC_CNameList::Remove(node);
- } // end of func
- // **********************************************************************
-
- public: TC_TNameNode<Item>* Remove (Item * item)
- {
- return (TC_TNameNode<Item>*) TC_CNameList::Remove(item);
- } // end of func
- // **********************************************************************
-
- public: Item * Iterate (ITR_FUNC itr_func, void* arg)
- {
- return (Item*)TC_CNameList::Iterate((TC_CNameList::ITR_FUNC)itr_func, arg);
- } // end of func
- // **********************************************************************
-
- public: Item * Find (HANDLE key)
- {
- return (Item*)TC_CNameList::Find(key);
- } // end of func
- // **********************************************************************
-
- public: Item * Find (const char * name)
- {
- return (Item*)TC_CNameList::Find(name);
- } // end of func
- // **********************************************************************
-
-
- }; // end of class TC_TNameList
-
- // **********************************************************************
-
- // **********************************************************************
- template <class Item>
- class TC_TLockList
- : public TC_CLockList
- {
- typedef Item* (*ITR_FUNC)(Item*, void*);
- public: TC_TLockList ()
- : TC_CLockList()
- {
- } // end of func
- // **********************************************************************
-
- public: TC_TNameNode<Item>* Root ()
- {
- return (TC_TNameNode<Item>*)m_Root;
- } // end of func
- // **********************************************************************
-
- public: void Add (TC_TNameNode<Item>& node)
- {
- TC_CLockList::Add(node);
- } // end of func
- // **********************************************************************
-
- public: void Add (Item* item)
- {
- TC_CLockList::Add(*new TC_TNameNode<Item>(item));
- } // end of func
- // **********************************************************************
-
- public: void Append (TC_TNameNode<Item>& node)
- {
- TC_CLockList::Append(node);
- } // end of func
- // **********************************************************************
-
- public: void Append (Item* item)
- {
- TC_CLockList::Append(*new TC_TNameNode<Item>(item));
- } // end of func
- // **********************************************************************
-
- public: BOOL Remove (TC_TNameNode<Item>& node)
- {
- return TC_CLockList::Remove(node);
- } // end of func
- // **********************************************************************
-
- public: TC_TNameNode<Item>* Remove (Item * item)
- {
- return (TC_TNameNode<Item>*) TC_CLockList::Remove(item);
- } // end of func
- // **********************************************************************
-
- public: Item * Iterate (ITR_FUNC itr_func, void* arg)
- {
- return (Item*)TC_CLockList::Iterate((TC_CLockList::ITR_FUNC)itr_func, arg);
- } // end of func
- // **********************************************************************
-
- public: Item * Find (HANDLE key)
- {
- return (Item*)TC_CLockList::Find(key);
- } // end of func
- // **********************************************************************
-
- public: Item * Find (const char * name)
- {
- return (Item*)TC_CLockList::Find(name);
- } // end of func
- // **********************************************************************
-
-
- }; // end of class TC_TLockList
-
- // **********************************************************************
- template<class Item> void tcTClear (TC_TSList<Item>& list) ;
- template<class Item> void tcTClear (TC_TKeyList<Item>& list) ;
- template<class Item> void tcTClear (TC_TNameList<Item>& list) ;
- typedef long TCHTreeNode;
- class TC_CBTree;
- class TC_CBTreeNodeSpace;
- class TC_CBTreeNodeHeap;
- class TC_CBTreeIter;
- class TC_CBTreeNode;
- class TC_CComparator;
-
- template <class ItemType> class TBTreeIterator;
- #define TC_BTREE_CMP_FUNC TC_CBTree::BTreeCmpFunc
-
- // **********************************************************************
- class TC_COREEX_EXPORT TC_CBTree
- {
- protected:
- enum DelAction {
- DelAct_None,
- DelAct_RotateLeft,
- DelAct_RotateRight,
- DelAct_Merge,
- };
- public:
- typedef int (*BTreeCmpFunc)(const void*, const void*);
- private: BOOL m_OwnNodeSpace ;
- protected: BTreeCmpFunc m_Cmp ;
- protected: TC_CBTreeNodeSpace* m_NodeSpace ;
- protected: short m_Order ;
- protected: TC_CRWAccess * m_Lock ;
- public: TC_CBTree (BTreeCmpFunc cmp, short order = 2, TC_CBTreeNodeSpace* space = 0) ;
- public: virtual ~TC_CBTree () ;
- protected: TC_CBTreeNode* _Adjust (TC_CBTreeNode* node, short index, TC_CBTreeNode* c0, TC_CBTreeNode* c1, DelAction& action) ;
- protected: TC_CBTreeNode* _DescendInto (TC_CBTreeNode* node, short subtreeIndex, DelAction& action) ;
- protected: BOOL _InsertNonFull (TC_CBTreeNode* node, void* item) ;
- protected: void _SplitChild (TC_CBTreeNode* x, short i, TC_CBTreeNode* y) ;
- public: virtual void* Find (void* item, void ** last_item = 0) const ;
- public: virtual void* ItemWithRank (long rank) const ;
- public: virtual long RankOf (void* item) ;
- public: virtual long Size () const ;
- public: virtual BOOL Add (void* item) ;
- public: virtual void* Remove (void* key) ;
- public: virtual BOOL Delete (void* item) ;
- public: virtual void* ExtractMin () ;
- public: TC_CBTreeNodeSpace* NodeSpace () const
- {
- return m_NodeSpace;
- } // end of func
- // **********************************************************************
-
- public: BTreeCmpFunc CmpFunc ()
- {
- return m_Cmp;
- } // end of func
- // **********************************************************************
-
- public: void SetCmpFunc (BTreeCmpFunc cmp) ;
- public: short Order ()
- {
- return m_Order;
- } // end of func
- // **********************************************************************
-
- public: void* Smallest ()
- {
- return ItemWithRank (0);
- } // end of func
- // **********************************************************************
-
- public: void* Largest ()
- {
- return ItemWithRank (Size()-1);
- } // end of func
- // **********************************************************************
-
- public: void UseLocking (TCRWPrivilege privilege = W_Privilege) ;
- public: BOOL Lock (TCRWRequest request = R_Request, long timeout = -1L) ;
- public: void Unlock () ;
-
- }; // end of class TC_CBTree
-
- // **********************************************************************
-
- // **********************************************************************
- class TC_COREEX_EXPORT TC_CBTreeNode
- {
- friend TC_CBTree;
- friend TC_CBTreeIter;
- friend TC_CBTreeNodeSpace;
- protected: TCHTreeNode m_Handle ;
- protected: long m_SubtreeSize ;
- protected: BOOL m_IsLeaf ;
- protected: short m_KeyCount ;
- protected: void** m_Items ;
- protected: TCHTreeNode* m_Subtree ;
- protected: TC_CBTreeNodeSpace* m_NodeSpace ;
- protected: TC_CBTreeNode (TC_CBTreeNodeSpace* space) ;
- protected: virtual ~TC_CBTreeNode () ;
- protected: virtual void MoveSubNode (const TC_CBTreeNode& x, short pos, short our_pos, short nkeys) ;
- public: virtual BOOL Search (void* itm, short& index) ;
- public: virtual void ShiftRightAt (short pos, short amount = 1) ;
- public: virtual void ShiftLeftAt (short pos, short amount = 1) ;
- public: long Size ()
- {
- return m_KeyCount;
- } // end of func
- // **********************************************************************
-
- public: void* Item (short i)
- {
- TC_COREEX_ASSERT ( i < m_KeyCount );
- return m_Items[i];
- } // end of func
- // **********************************************************************
-
- public: TCHTreeNode Subtree (short i) ;
- public: long SubtreeSize ()
- {
- return m_SubtreeSize;
- } // end of func
- // **********************************************************************
-
- public: TCHTreeNode Handle ()
- {
- return m_Handle;
- } // end of func
- // **********************************************************************
-
- public: TC_CBTreeNodeSpace* NodeSpace ()
- {
- return m_NodeSpace;
- } // end of func
- // **********************************************************************
-
- public: short Order () ;
- public: TC_BTREE_CMP_FUNC CmpFunc () ;
- public: BOOL IsLeaf ()
- {
- return m_IsLeaf;
- } // end of func
- // **********************************************************************
-
- public: short KeyCount ()
- {
- return m_KeyCount;
- } // end of func
- // **********************************************************************
-
-
- }; // end of class TC_CBTreeNode
-
- // **********************************************************************
-
- // **********************************************************************
- class TC_COREEX_EXPORT TC_CBTreeNodeSpace
- {
- friend class TC_CBTree;
- protected: TC_CBTree * m_BTree ;
- public: TC_CBTreeNodeSpace (TC_CBTree * tree) ;
- protected: TC_CBTreeNodeSpace () ;
- protected: virtual void _Init (TC_CBTree * tree) ;
- public: virtual ~TC_CBTreeNodeSpace () ;
- protected: virtual void _Destroy (TC_CBTreeNode* node) ;
- protected: virtual TC_CBTreeNode* _BuildNode () ;
- protected: virtual void _SetHandle (TC_CBTreeNode& node, TCHTreeNode h) ;
- public: virtual TCHTreeNode RootHandle () =0 ;
- public: virtual void NewRoot (TCHTreeNode h) =0 ;
- public: virtual TCHTreeNode CreateNode () =0 ;
- public: virtual void DestroyNode (TC_CBTreeNode*) =0 ;
- public: virtual TC_CBTreeNode* BorrowNode (TCHTreeNode h) =0 ;
- public: virtual void ReturnNode (TC_CBTreeNode* n) =0 ;
- public: virtual void NodeModified (TC_CBTreeNode* n) =0 ;
- public: TC_CBTreeNode* BorrowRoot ()
- {
- return BorrowNode (RootHandle());
- } // end of func
- // **********************************************************************
-
- public: void WriteBack (TC_CBTreeNode* node)
- {
- NodeModified (node);
- ReturnNode (node);
- } // end of func
- // **********************************************************************
-
- public: TC_CBTreeNode* MakeNode ()
- {
- return BorrowNode (CreateNode());
- } // end of func
- // **********************************************************************
-
- public: virtual void DestroyItem (void *item) ;
- public: short Order () ;
- public: TC_BTREE_CMP_FUNC CmpFunc () ;
-
- }; // end of class TC_CBTreeNodeSpace
-
- // **********************************************************************
-
- // **********************************************************************
- class TC_COREEX_EXPORT TC_CBTreeNodeHeap
- : public TC_CBTreeNodeSpace
- {
- protected: TCHTreeNode m_Root ;
- public: TC_CBTreeNodeHeap (TC_CBTree * tree) ;
- public: TC_CBTreeNodeHeap () ;
- public: ~TC_CBTreeNodeHeap () ;
- protected: virtual void _Init (TC_CBTree * tree) ;
- protected: void _DestroySubtree (TCHTreeNode h) ;
- public: virtual TCHTreeNode CreateNode () ;
- public: virtual TC_CBTreeNode* BorrowNode (TCHTreeNode h) ;
- public: virtual void ReturnNode (TC_CBTreeNode* /* h */) ;
- public: virtual void DestroyNode (TC_CBTreeNode* node) ;
- public: virtual TCHTreeNode RootHandle () ;
- public: virtual void NewRoot (TCHTreeNode h) ;
- public: virtual void NodeModified (TC_CBTreeNode*) ;
-
- }; // end of class TC_CBTreeNodeHeap
-
- // **********************************************************************
-
- // **********************************************************************
- class TC_COREEX_EXPORT TC_CBTreeIter
- {
- protected: const TC_CBTree& m_Tree ;
- protected: long m_Index ;
- protected: short m_Length ;
- protected: void* m_Path ;
- public: TC_CBTreeIter (const TC_CBTree& tree) ;
- public: TC_CBTreeIter (const TC_CBTreeIter& itr) ;
- public: virtual ~TC_CBTreeIter () ;
- public: void BeginFrom (void* item) ;
- public: void Reset () ;
- public: void* Next () ;
- public: BOOL More () ;
- public: long CurrentRank ()
- {
- return m_Index;
- } // end of func
- // **********************************************************************
-
-
- }; // end of class TC_CBTreeIter
-
- // **********************************************************************
- // **********************************************************************
- template<class Item> void tcTClear (TC_TSList<Item>& list)
- {
- for ( TC_TSNode<Item>* curr = list.Root(); curr; ) {
- TC_TSNode<Item>* node= curr->Next();
- delete curr->GetItem();
- curr = node;
- }
- list.Reset();
- }
- // **********************************************************************
- template<class Item> void tcTClear (TC_TKeyList<Item>& list)
- {
- for ( TC_TKeyNode<Item>* curr = list.Root(); curr; ) {
- TC_TKeyNode<Item>* node= curr->Next();
- delete curr->GetItem();
- curr = node;
- }
- list.Reset();
- }
- // **********************************************************************
- template<class Item> void tcTClear (TC_TNameList<Item>& list)
- {
- for ( TC_TNameNode<Item>* curr = list.Root(); curr; ) {
- TC_TNameNode<Item>* node= curr->Next();
- delete curr->GetItem();
- curr = node;
- }
- list.Reset();
- }
-
- #endif // _INC_CLTN_HPP
-