File: segment_tree_1.cpp

package info (click to toggle)
cgal 4.0-5
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 65,068 kB
  • sloc: cpp: 500,870; ansic: 102,544; sh: 321; python: 92; makefile: 75; xml: 2
file content (60 lines) | stat: -rw-r--r-- 1,792 bytes parent folder | download
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
// Implementation: Testprogram for 1-dimensional Segment Trees
// A one dimensional Segment Tree is defined in this class.
// Ti is the type of each dimension of the tree.

#include "include/Tree_Traits.h"
#include <CGAL/Segment_tree_k.h>
#include <iostream>
#include <iterator>
#include <list>
#include <utility>

typedef CGAL::Segment_tree_1<CGAL::Tree_traits_1> SSegment_tree_1_type;

int main()
{
  typedef CGAL::Tree_traits_1::Interval Interval;
  typedef CGAL::Tree_traits_1::Key Key;
  // definition of the one-dimensional segment tree
  std::list<Interval> InputList, OutputList, N;

  // insertion of the tree elements into the sequence container
  InputList.push_back(Interval(64, 81));
  InputList.push_back(Interval(465, 499));
  InputList.push_back(Interval(288, 379));
  InputList.push_back(Interval(314, 375));

  // creation of the segment tree
  typedef std::list<Interval>::iterator l_iterator;
  l_iterator first = InputList.begin();
  l_iterator last = InputList.end();

  SSegment_tree_1_type segment_tree_1(first,last);

  // perform a window query
  Interval a(45,200);
  segment_tree_1.window_query(a,std::back_inserter(OutputList));

  // output of the querey elements on stdout
  l_iterator j = OutputList.begin();
  std::cerr << "\n window_query (45,200)\n";
  while(j!=OutputList.end())
  {
    std::cerr << (*j).first << "-" << (*j).second << std::endl;
    j++;
  }
  Interval b(320, 370);
  segment_tree_1.enclosing_query(b,std::back_inserter(N));
  j = N.begin();
  std::cerr << "\n enclosing_query (320, 370)\n";
  while(j!=N.end())
  {
    std::cerr << (*j).first << "-" << (*j).second << std::endl;
    j++;
  }
  if(segment_tree_1.segment_tree_1->is_valid())
    std::cerr << "Tree is valid\n";
  else
    std::cerr << "Tree is not valid\n";
  return 0;
}