Subversion Repositories spk

Rev

Blame | Last modification | View Log | RSS feed

#ifndef BOB_POINT_BST
#define BOB_POINT_BST

#include "../common/ext_bstree.h"

class bob_point_bst
{
        private:
                template <class Key, class Ty>
                struct getkey
                {
                        Key operator() (const Ty& n) { return n->coord; }
                };
                
                template <class Key, class Ty>
                struct getkey2
                {
                        Key operator() (const Ty& n) { return n; }
                };
                
                struct node
                {
                        int coord;
                        
                        typedef ext::bstree<int, node*, getkey<int, node*> > nodebst;
                        
                        nodebst tree;
                        
                        node(int c) { coord=c; }
                };
                
                struct node2
                {
                        int x,y,z;
                        
                        node2() {}
                        node2(const bob_dom_point& p) { x=p.x; y=p.y; z=p.z; }
                        
                        bool operator == (const node2& r) const { return x==r.x && y==r.y && z==r.z; }
                };
                
                struct keyless
                {
                        bool operator () (const node2& left, const node2& right) const {
                                return left.x < right.x || 
                                (left.x == right.x && (left.y < right.y || (left.y == right.y && (left.z < right.z)))); 
                        }
                };
                
                node::nodebst level1;
                
                typedef ext::bstree<node2, node2, getkey2<node2, node2>, keyless> newbst;
                
                newbst tree;
                
        public:
                size_t m_compCount;
                
                bob_point_bst() { m_compCount=0; }
                
                void addPoint(bob_dom_point *pnt)
                {
                        node2 n=node2(*pnt);
                        newbst::insert_iterator &iit=tree.find(n);
                        if(iit==tree.end())
                                tree.insert(iit, n);
                        
                        m_compCount+=tree.m_compCount;
                        
                /*
                        node::nodebst::insert_iterator &iit=level1.find(pnt->x);
                        node::nodebst::const_iterator it;
                        if(iit==level1.end())
                                it=level1.insert(iit, new node(pnt->x));
                        else
                                it=iit;
                        
                        m_compCount+=level1.m_compCount;
                        
                        iit=it->tree.find(pnt->y);
                        m_compCount+=it->tree.m_compCount;
                        
                        if(iit==it->tree.end())
                                it=it->tree.insert(iit, new node(pnt->y));
                        else
                                it=iit;
                        
                        iit=it->tree.find(pnt->z);
                        m_compCount+=it->tree.m_compCount;
                        
                        if(iit==it->tree.end())
                                it=it->tree.insert(iit, new node(pnt->z));
                        else
                                it=iit;
                        
                        */
                }
                
};

#endif // !defined(BOB_POINT_BST)