本文整理汇总了C++中IntervalTree::getIntervalSet方法的典型用法代码示例。如果您正苦于以下问题:C++ IntervalTree::getIntervalSet方法的具体用法?C++ IntervalTree::getIntervalSet怎么用?C++ IntervalTree::getIntervalSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IntervalTree
的用法示例。
在下文中一共展示了IntervalTree::getIntervalSet方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例2: 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));
}
}
示例3: 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));
}
示例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'));
}
示例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);
}
}
示例6: 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'));
}
示例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);
//.........这里部分代码省略.........