本文整理汇总了C++中IntervalTree类的典型用法代码示例。如果您正苦于以下问题:C++ IntervalTree类的具体用法?C++ IntervalTree怎么用?C++ IntervalTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IntervalTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST
TEST(IntervalTest, Merging3)
{
IntervalTree tree;
tree.Insert(Interval(1, 3));
tree.Insert(Interval(5, 6));
tree.Insert(Interval(4, 6));
EXPECT_EQ(tree.size(), 2);
}
示例2: partialMerging
static SortedRanges partialMerging(const IntervalTree<ElemChunk> &tree, const dav_size_t mergedist) {
MergedRanges merged;
std::vector<Interval<ElemChunk> > allranges_unsorted;
tree.findContained(0, std::numeric_limits<dav_size_t>::max(), allranges_unsorted);
MergedRanges allranges;
for(std::vector<Interval<ElemChunk> >::iterator it = allranges_unsorted.begin(); it != allranges_unsorted.end(); it++)
allranges.insert(std::make_pair(it->start, it->stop));
dav_off_t offset = allranges.begin()->first;
dav_off_t end = allranges.begin()->second;
for(MergedRanges::iterator it = allranges.begin(); it != allranges.end(); it++) {
if(end + (dav_off_t) mergedist >= it->first) {
end = it->second;
}
else {
merged.insert(std::make_pair(offset, end));
offset = it->first;
end = it->second;
}
}
merged.insert(std::make_pair(offset, end));
SortedRanges output;
for(MergedRanges::iterator it = merged.begin(); it != merged.end(); it++)
output.push_back(*it);
return output;
}
示例3: 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'));
}
示例4: printTree
void printTree(IntervalTree<T,U> &tree)
{
#ifdef DEBUG
std::cout << "============= tree ============" << std::endl;
tree.printTree(std::cout);
std::cout << "============= ============" << std::endl;
#endif
}
示例5: 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));
}
}
示例6: while
void PCLibraryState::removeLibFromCache(cache_t element) {
IntervalTree<Address, cache_t>::iterator iter = loadedLibs.begin();
while(iter != loadedLibs.end()) {
// Can't use a for loop because I need to fiddle with
// increments manually.
cache_t found = iter->second.second;
if (found == element) {
IntervalTree<Address, cache_t>::iterator toDelete = iter;
++iter;
loadedLibs.erase(toDelete->first);
}
else {
++iter;
}
}
}
示例7: solve
i64 solve(vector<Rect> rects){
compress(rects);
vector<Event> evs = eventsFromRect(rects);
i64 total = 0;
IntervalTree::Node root = {1, 0, (int)xs.size() - 2};
tree.init(root);
for (size_t i = 0; i < evs.size(); i++){
Event &e = evs[i];
if (i != 0){
i64 s = tree.gao(0, (int)xs.size() - 2).query(root, k);
//printf("%lld\n", s);
total += s * (ys[evs[i].tick] - ys[evs[i - 1].tick]);
}
//e.debug();
//printf("%lu: %lld\n", i, total);
tree.gao(e.from, e.to).add(root, e.inc);
}
return total;
}
示例8: fillChunks
// find all matching chunks in tree and fill them
static void fillChunks(const char *source, const IntervalTree<ElemChunk> &tree, dav_off_t offset, dav_size_t size) {
std::vector<Interval<ElemChunk> > matches;
tree.findOverlapping(offset, offset+size-1, matches);
for(std::vector<Interval<ElemChunk> >::iterator it = matches.begin(); it != matches.end(); it++) {
copyBytes(source, offset, size, it->value);
}
if(matches.size() == 0) {
DAVIX_SLOG(DAVIX_LOG_DEBUG, DAVIX_LOG_CHAIN, "WARNING: Received byte-range from server does not match any in the interval tree");
}
}
示例9: 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);
}
}
示例10: 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);
}
}
示例11: main
int main() {
int n, q;
scanf("%d%d", &n, &q);
memset(&tree, 0, sizeof(tree));
for(int i = 1; i <= n; i++)
scanf("%d", &A[i]);
tree.build(1, 1, n);
int k, args[20], original[20];
char cmd[100];
while(q--) {
scanf("%s", cmd);
// 解析输入
int len = strlen(cmd);
k = 0; args[k] = 0;
for(int i = 6; i < len; i++)
if(isdigit(cmd[i])) args[k] = args[k] * 10 + cmd[i] - '0';
else { k++; args[k] = 0; }
// 处理命令
if(cmd[0] == 'q') {
qL = args[0]; qR = args[1];
printf("%d\n", tree.query(1, 1, n));
} else {
for(int i = 0; i < k; i++) original[i] = A[args[i]];
for(int i = 0; i < k; i++) {
p = args[i];
v = A[p] = original[(i+1)%k];
tree.update(1, 1, n);
}
}
}
return 0;
}
示例12: initialize
void initialize(int n, int q) {
uf.reset(n);
tree.reset(1, q);
stkpos = 1;
stk[1] = tree.root();
}
示例13: cacheLibraryRanges
bool PCLibraryState::cacheLibraryRanges(Library::ptr lib)
{
std::string filename = lib->getName();
Address base = lib->getLoadAddress();
SymbolReaderFactory *fact = getDefaultSymbolReader();
SymReader *reader = fact->openSymbolReader(filename);
if (!reader) {
sw_printf("[%s:%u] - Error could not open expected file %s\n",
FILE__, __LINE__, filename.c_str());
return false;
}
int num_segments = reader->numSegments();
for (int i=0; i<num_segments; i++) {
SymSegment segment;
reader->getSegment(i, segment);
if (segment.type != 1) continue;
Address segment_start = segment.mem_addr + base;
Address segment_end = segment_start + segment.mem_size;
loadedLibs.insert(segment_start, segment_end,
makeCache(LibAddrPair(lib->getName(),
lib->getLoadAddress()),
lib));
}
return true;
}
示例14: main
int main() {
int n, m;
while(scanf("%d%d", &n, &m) == 2) {
memset(&tree, 0, sizeof(tree));
while(m--) {
scanf("%d", &op);
if(op == 1) {
scanf("%d%d", &p, &v);
tree.update(1, 1, n);
} else {
scanf("%d%d", &qL, &qR);
printf("%d\n", tree.query(1, 1, n));
}
}
}
return 0;
}
示例15: add_connection
void add_connection(int u, int v, int t) {
current++;
Edge *e = new Edge(u, v);
tree.modify(current, current + t - 1, e);
if (current == 1)
add_node(stk[1]);
}