home *** CD-ROM | disk | FTP | other *** search
- #ifndef __RWBTREE_H__
- #define __RWBTREE_H__
- pragma push_align_members(64);
-
- /*
- * RWBTree -- in memory B-Tree.
- *
- * $Header: E:/vcs/rw/btree.h_v 1.3 04 Mar 1992 09:07:24 KEFFER $
- *
- ****************************************************************************
- *
- * Rogue Wave
- * P.O. Box 2328
- * Corvallis, OR 97339
- * Voice: (503) 754-3010 FAX: (503) 757-6650
- *
- * Copyright (C) 1989, 1990, 1991. This software is subject to copyright
- * protection under the laws of the United States and other countries.
- *
- ***************************************************************************
- *
- * $Log: E:/vcs/rw/btree.h_v $
- *
- * Rev 1.3 04 Mar 1992 09:07:24 KEFFER
- * Changed nil to rwnil
- *
- * Rev 1.2 18 Feb 1992 09:54:10 KEFFER
- *
- * Rev 1.1 28 Oct 1991 09:08:08 keffer
- * Changed inclusions to <rw/xxx.h>
- *
- * Rev 1.0 28 Jul 1991 08:12:46 keffer
- * Tools.h++ V4.0.5 PVCS baseline version
- *
- */
-
- #include "rw/colclass.h"
- #include "rw/mempool.h"
-
- #ifdef RDEBUG
- static const unsigned order = 2;
- static const unsigned twoTimesOrder = 2*order;
- #else
- static const unsigned order = 50;
- static const unsigned twoTimesOrder = 2*order;
- #endif
-
-
- class RWExport RWBTreeNode : public RWMemoryPool {
- friend class RWExport RWBTree;
- typedef RWCollectable* keyP;
-
- RWBTreeNode(); // Private constructors.
- RWBTreeNode(RWCollectable*);
- unsigned counter; // How many of the [twoTimesOrder]
- // fields are used.
- keyP key[twoTimesOrder]; // Array of pointers keys.
- RWBTreeNode* next[twoTimesOrder+1]; // Array of pointers to children nodes.
- int binarySearch(const RWCollectable*) const; // Binary search for insertion.
- void initialize();
- void siz(unsigned&) const; // Count items in self & children.
- RWBoolean subSetOf(const RWBTree& bt) const;
- };
-
- class RWExport RWBTree : public RWCollection {
- RWBTreeNode* root; // root = first node in tree.
- RWCollectable* tempKey; // Place holder to handle node over- and underflow
- RWBTreeNode* tempNode; // Place holder to handle node over- and underflow
- protected:
- void apl(RWBTreeNode*, RWapplyCollectable, void*); // Apply to all children
- void del(RWBTreeNode*); // Delete all children.
- int ins(RWCollectable* a, RWBTreeNode*); // Insert a in tree.
- int rem(const RWCollectable* a, RWBTreeNode*, RWCollectable*&); // Remove a
- public:
- RWBTree();
- ~RWBTree();
- RWBTree(const RWBTree&);
-
- void operator=(const RWBTree&);
- RWBoolean operator<=(const RWBTree& bt) const; // Subset of bt
- RWBoolean operator==(const RWBTree& bt) const;
-
- // Special member function to return the height of the B-tree.
- unsigned height() const;
-
- /************ Standard Collection classes functions **************/
- virtual void apply(RWapplyCollectable, void*);
- virtual void clear();
- //virtual void clearAndDestroy();
- //virtual RWBoolean contains(const RWCollectable*) const;
- virtual unsigned entries() const; // Total entries
- virtual RWCollectable* find(const RWCollectable*) const;
- virtual RWCollectable* insert(RWCollectable*);
- virtual RWBoolean isEqual(const RWCollectable*) const;
- virtual ClassID isA() const {return __RWBTREE;}
- virtual RWCollectable* newSpecies() const;
- virtual RWBoolean isEmpty() const {return root==rwnil;}
- virtual unsigned occurrencesOf(const RWCollectable*) const;
- virtual RWCollectable* remove(const RWCollectable*);
- //virtual void removeAndDestroy(const RWCollectable*);
- };
-
- pragma pop_align_members();
- #endif /* __RWBTREE_H__ */
-