File: PrioritySearchTree.hpp

package info (click to toggle)
pbseqlib 0~20161219-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,924 kB
  • ctags: 5,123
  • sloc: cpp: 82,727; makefile: 305; python: 239; sh: 8
file content (69 lines) | stat: -rw-r--r-- 1,887 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef _BLASR_PRIORITY_SEARCH_TREE_HPP_
#define _BLASR_PRIORITY_SEARCH_TREE_HPP_

#include <vector>
#include "BasicEndpoint.hpp"

/*
 * Define a priority search tree on a point that implements 
 * the following interface:
 *
 * int T_point::GetIndex()
 *    - Return the index of the point in a list of points.
 * int T_point::GetKey()
 *    - Return the key value that the points are sorted by (x-value in a 2D query)
 * int T_point::GetValue()
 *    - Return the value of a point.
 * int T_point::SetValue(int value)
 *    - sets the value of a point.
 *
 * This class implements a query FindMax(key), which returns
 * the index of the point with greatest value of all points with key [0...key).
 *
 * 
 */
template<typename T_Point>
class PSTVertex {
public: 
    unsigned int leftChildIndex;
    unsigned int rightChildIndex;
    unsigned int isALeaf;
    KeyType medianKey;
    KeyType maxKey;
    unsigned int pointIndex;
    int maxScoreNode;
    PSTVertex();
};

template<typename T_Point>
class PrioritySearchTree {
private:
    std::vector<PSTVertex<T_Point> > tree;
    std::vector<PSTVertex<T_Point> > * treePtr;
	int GetMedianIndex(int start, int end);

	inline KeyType CreateTree(std::vector<T_Point> &points, 
        int start, int end, unsigned int &iterativeIndex);

	int FindIndexOfMaxPoint(int curVertexIndex, std::vector<T_Point> &points, 
        KeyType maxKey, int &maxPointValue, 
        int &maxPointIndex);

public:
    PrioritySearchTree();

	void CreateTree(std::vector<T_Point> &points, 
        std::vector<PSTVertex<T_Point> > *bufTreePtr=NULL);

	int FindPoint(KeyType pointKey, 
        int curVertexIndex, int &pointVertexIndex);

	void Activate(std::vector<T_Point> &points, int pointIndex);

	int FindIndexOfMaxPoint(std::vector<T_Point> &points, 
        KeyType maxPointKey, int &maxPointIndex);
};

#include "PrioritySearchTreeImpl.hpp"

#endif