当前位置: 首页>>代码示例>>C++>>正文


C++ IntervalTree::addInterval方法代码示例

本文整理汇总了C++中IntervalTree::addInterval方法的典型用法代码示例。如果您正苦于以下问题:C++ IntervalTree::addInterval方法的具体用法?C++ IntervalTree::addInterval怎么用?C++ IntervalTree::addInterval使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IntervalTree的用法示例。


在下文中一共展示了IntervalTree::addInterval方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testStringIntervals

void testStringIntervals()
{
  IntervalTree<char, String> tree;

  tree.addInterval('a', 'c', string("ac"));
  tree.addInterval('a', 'f', string("af"));
  tree.addInterval('d', 'k', string("dk"));
  tree.addInterval('d', 'l', string("dl"));
  tree.addInterval('d', 'o', string("do"));
  tree.addInterval('t', 'z', string("tz"));

  printTree(tree);
  std::list<String> result;

  {
    result = tree.getIntervalSet('b', 'g');
    assert(result.size() == 5);
    assert(!hasNode(result, String(string("tz"))));
  }

  {
    result = tree.getIntervalSet('k', 'z');
    assert(result.size() == 3);
    assert(hasNode(result, String(string("dl"))));
    assert(hasNode(result, String(string("do"))));
    assert(hasNode(result, String(string("tz"))));

    printResultSet(result);
  }

}
开发者ID:conqer,项目名称:conqur,代码行数:31,代码来源:TestIntervalTree.cpp

示例2: testBoundaries

void testBoundaries()
{
  // 1. Create new lock and acquire lock from 1-10
  IntervalTree<int, LockHolder> tree;
  LockHolder lockA('A');
  tree.addInterval(1, 10, lockA);

  // 2. Create lock B on the edge
  LockHolder lockB('B');
  tree.addInterval(10, 15, lockB);

  //3. Query the edge
  std::list<LockHolder> result = tree.getIntervalSet(10, 10);
  printResultSet(result);
  assert((result.size() == 1) && (result.front() == 'B'));
}
开发者ID:conqer,项目名称:conqur,代码行数:16,代码来源:TestIntervalTree.cpp

示例3: testRemoveInterval

void testRemoveInterval()
{
  int arr[][2] ={

    {1888,1971},
    {1874,1951},
    {1843,1907},
    {1779,1828},
    {1756,1791},
    {1585, 1672}

  };

  Node a(1888, 1971);
  Node b(1874, 1951);
  Node c(1843, 1907);
  Node d(1779, 1828);
  Node e(1756, 1791);
  Node f(1585, 1672);

  IntervalTree<int,Node> tree;
  for(size_t i=0; i < ARRAY_SIZE(arr); i++) {
    Node nd (arr[i][0], arr[i][1]);
    tree.addInterval( arr[i][0], arr[i][1], nd);
  }

  printTree(tree);
  std::list<Node> result; 

  {
    tree.removeInterval(1951, 1972, a); 
    result = tree.getIntervalSet(1960, 1970);
    assert(result.size() == 0);
  }

  {
    result = tree.getIntervalSet(1890, 1900);
    assert(result.size() == 3);
    assert(popNode(result, c) && popNode(result, b) && popNode(result, a));
  }

  {
    tree.removeInterval(1875, 1890, c); 
    result = tree.getIntervalSet(1877, 1889);
    assert(!hasNode(result, c));
  }

  {
    result = tree.getIntervalSet(1906, 1910);
    assert(result.size() == 3);
    assert(hasNode(result, a));
    assert(hasNode(result, b));
    assert(hasNode(result, c));
  }

}
开发者ID:conqer,项目名称:conqur,代码行数:56,代码来源:TestIntervalTree.cpp

示例4: testRemoveFromMiddle

void testRemoveFromMiddle()
{
  // 1. Create new lock and acquire lock from 1-10
  IntervalTree<int, LockHolder> tree;
  LockHolder lockA('A');
  tree.addInterval(1, 10, lockA);

  // 2. Create lock B on the edge
  LockHolder lockB('B');
  tree.addInterval(10, 15, lockB);

  // 3. Remove all locks from 6-12
  tree.removeInterval(6, 12);

  //4.  Query the removed interval
  std::list<LockHolder> result = tree.getIntervalSet(6, 11);
  assert(result.size() == 0);

  //5. Query the interval locked by A
  result = tree.getIntervalSet(2, 5);
  assert((result.size() == 1) && (result.front() == 'A'));
}
开发者ID:conqer,项目名称:conqur,代码行数:22,代码来源:TestIntervalTree.cpp

示例5: testNames

void testNames()
{  
  IntervalTree<char, string> tree;

  tree.addInterval('j', 'y', string("jojy"));
  tree.addInterval('b', 'n', string("brian"));
  tree.addInterval('e', 's', string("sage"));
  tree.addInterval('f', 'g', string("gregsf"));
  tree.addInterval('h', 'y', string("yehudah"));

  printTree(tree);

  std::list<string> result;
  {
    result = tree.getIntervalSet('b', 'y');
    assert(result.size() == 5);

    printResultSet(result);
  }
  
  { 
    result = tree.getIntervalSet('j', 'm');
    assert(!hasNode(result, string("gregsf")));

    printResultSet(result);
  }

  {
    tree.removeAll("jojy");

    result = tree.getIntervalSet('b', 'z');
    assert(!hasNode(result, string("jojy")));

    printResultSet(result);
  }
}
开发者ID:conqer,项目名称:conqur,代码行数:36,代码来源:TestIntervalTree.cpp

示例6: testIntervalQuery

void testIntervalQuery()
{
  int arr[][2] ={

    {1888,1971},
    {1874,1951},
    {1843,1907},
    {1779,1828},
    {1756,1791},
    {1585, 1672}

  };

  Node a(1888, 1971);
  Node b(1874, 1951);
  Node c(1843, 1907);
  Node d(1779, 1828);
  Node e(1756, 1791);
  Node f(1585, 1672);

  IntervalTree<int,Node> tree;
  for(size_t i=0; i < ARRAY_SIZE(arr); i++) {
    Node nd (arr[i][0], arr[i][1]);
    tree.addInterval( arr[i][0], arr[i][1], nd);
  }


  std::list<Node> result = tree.getIntervalSet(1843, 1874);
  assert(result.size() == 1 && (result.front() == c));

  result = tree.getIntervalSet(1873, 1974);
  assert(result.size() == 3);
  assert(popNode(result, c) && popNode(result,b) && popNode(result,a));


  result = tree.getIntervalSet(1910, 1910);
  assert(result.size() == 2);
  assert(popNode(result, b) &&  popNode(result,a));

  result = tree.getIntervalSet(1829, 1842);
  assert(result.size() == 0); 

  result = tree.getIntervalSet(1829, 1845);
  assert(result.size() == 1);
  assert(popNode(result, c)); 
}
开发者ID:conqer,项目名称:conqur,代码行数:46,代码来源:TestIntervalTree.cpp

示例7: testLocks

void testLocks()
{
  // 1. Create new lock and acquire lock from 1-10
  IntervalTree<int, LockHolder> tree;
  LockHolder lockA('A');
  tree.addInterval(1, 10, lockA);

  printTree(tree);
  std::list<LockHolder> result;

  {
    result = tree.getIntervalSet(1,10);
    assert(result.size() == 1);

    printResultSet(result);
  }

  // Create new lock and acquire from 3-15
  LockHolder lockB('B');
  tree.addInterval(3, 15, lockB);

  {
    result = tree.getIntervalSet(1,15);
    assert(result.size() == 2);
  }

  // Release all  locks  from 3-10
  tree.removeInterval(3,10);

  // Query the whole range
  result = tree.getIntervalSet(1,15);

  assert(result.size() == 2 && (result.front() == 'A') );
  result.pop_front();
  assert(result.front() == 'B');


  // Query the range held by only A
  result = tree.getIntervalSet(1,5);
  assert(result.front().name == 'A');

  // Query the range held by none
  result = tree.getIntervalSet(4,9);
  printResultSet(result);
  assert(!result.size());

  // Again acquire lock B from 3-15
  tree.addInterval(3, 15, lockB);
  result = tree.getIntervalSet(1,15);
  assert(result.size() ==2);


  // Query the range held by only B
  result = tree.getIntervalSet(4,10);
  assert((result.size() ==1) && (result.front().name == 'B'));


  // Again acquire lock A from 3-10
  tree.addInterval(3, 10, lockA);
  result = tree.getIntervalSet(3,10);
  assert(result.size() ==2);

  // Release only  locks held by B from 3-10	
  tree.removeInterval(3,10, lockB);


  // Query interval just released by B
  result = tree.getIntervalSet(3,9);
  assert((result.size() ==1) && (result.front().name == 'A'));


  // Query interval now partially owned by B
  result = tree.getIntervalSet(3,12);
  assert(result.size() ==2);


  // Add one more lock between 4-8
  LockHolder lockC('C');
  tree.addInterval(4, 8, lockC);

  printTree(tree);

  // Query the interval shared by A,B,C
  result = tree.getIntervalSet(3,12);
  assert(result.size() ==3);


  // Query the intervals shared by A, C
  result = tree.getIntervalSet(3, 6);
  assert(result.size() == 2 && (result.front() == 'A') );
  result.pop_front();
  assert(result.front() == 'C');

  // Add one more lock between 2-4
  LockHolder lockD('D');
  tree.addInterval(2, 4, lockD);

  // Query the intervals owned by A.B,C,D
  result = tree.getIntervalSet(2, 11);
  assert(result.size () == 4);
//.........这里部分代码省略.........
开发者ID:conqer,项目名称:conqur,代码行数:101,代码来源:TestIntervalTree.cpp

示例8: algorithm2

void algorithm2(vector<Square> & squares){
	
	priority_queue<Event, vector<Event>, CompareEvent> events; 
	//vector<SQINTERVAL> intervals; // vector containg all vertical intervals and their rectangles
	IntervalTree<Square, float> activeTree; // tree containing the vertical intervals
	vector<SQINTERVAL> results; // contains the intersecting vertical intervals and their rectangles

	ofstream output;
	output.open("uitvoerrechthoeken.txt");

	// start timer
	auto start = std::chrono::steady_clock::now();
	
	for (int i = 0; i < squares.size(); i++){
		Event e1 = Event(true, squares[i], squares[i].getLB().getX());
		Event e2 = Event(false, squares[i], squares[i].getRA().getX());
		events.push( e1 ); //left side event of rectangle
		events.push( e2 ); //right side event of rectangle
	}
	
	while (!events.empty()) {
		Event current = events.top();
		if (current.isLeftEdge()){
			
			if (activeTree.getIntervals().size() > 0){
				
				activeTree.findOverlapping(current.getSquare().getLB().getY(), current.getSquare().getRA().getY(), results);
				vector<Coordinate> pos;
				for (int i = 0; i < results.size(); i++){
					
					results[i].value.getIntersection(current.getSquare(), pos);
					for (int w = 0; w < pos.size(); w++){
						output << pos[w].getX() << " " << pos[w].getY() << "\n";
					}
					
					pos.clear();
				}
			}
			activeTree.addInterval(SQINTERVAL(current.getSquare().getInterval()));
      activeTree.sort();
			results.clear();
		}
		else {

      for (vector<SQINTERVAL>::iterator i = activeTree.getIntervals().begin(); i != activeTree.getIntervals().end(); ++i){
				if (current.getSquare().getId() == i->value.getId()){
          activeTree.getIntervals().erase(i);
          break;
				}
			}
			results.clear();
		}
		events.pop();
	}

	// stop timer
	auto end = std::chrono::steady_clock::now();
	auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
	output << elapsed.count() << "\n"; 
	output.close();
	cout << "Ready. \n";
	cout << elapsed.count();
}
开发者ID:yvanvds,项目名称:tmi,代码行数:63,代码来源:Algorithm.cpp


注:本文中的IntervalTree::addInterval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。