Ejemplo n.º 1
0
/*public*/
bool
NodeBase::remove(const Envelope* itemEnv, void* item)
{
	// use envelope to restrict nodes scanned
	if (! isSearchMatch(itemEnv)) return false;

	bool found = false;
	for (int i = 0; i < 4; i++) {
		if (subnode[i] != NULL) {
			found = subnode[i]->remove(itemEnv, item);
			if (found) {
				// trim subtree if empty
				if (subnode[i]->isPrunable())
				subnode[i] = NULL;
				break;
			}
		}
	}
	// if item was found lower down, don't need to search for it here
	if (found) return found;

	// otherwise, try and remove the item from the list of items
	// in this node
	vector<void*>::iterator foundIter = 
		find(items->begin(), items->end(), item);
	if ( foundIter != items->end() ) {
		items->erase(foundIter);
		return true;
	} else {
		return false;
	}
}
Ejemplo n.º 2
0
vector<void*>*
NodeBase::addAllItemsFromOverlapping(Interval *interval,vector<void*> *resultItems)
{
	if (!isSearchMatch(interval))
		return items;
	resultItems->insert(resultItems->end(),items->begin(),items->end());
	for (int i=0;i<2;i++) {
		if (subnode[i]!=NULL) {
			subnode[i]->addAllItemsFromOverlapping(interval,resultItems);
		}
	}
	return items;
}
Ejemplo n.º 3
0
/*public*/
void
NodeBase::visit(const Envelope* searchEnv, ItemVisitor& visitor)
{
	if (! isSearchMatch(*searchEnv)) return;

	// this node may have items as well as subnodes (since items may not
	// be wholely contained in any single subnode
	visitItems(searchEnv, visitor);

	for (int i = 0; i < 4; i++) {
		if (subnode[i] != NULL) {
			subnode[i]->visit(searchEnv, visitor);
		}
	}
}
Ejemplo n.º 4
0
void
NodeBase::addAllItemsFromOverlapping(const Envelope *searchEnv, vector<void*> *resultItems)
{
	if (!isSearchMatch(searchEnv))
		return;

	//<<TODO:ASSERT?>> Can we assert that this node cannot have both items
	//and subnodes? [Jon Aquino]
	resultItems->insert(resultItems->end(),items->begin(),items->end());
	for(int i=0;i<4;i++) {
		if (subnode[i]!=NULL) {
			subnode[i]->addAllItemsFromOverlapping(searchEnv,resultItems);
		}
	}
}
Ejemplo n.º 5
0
/*public*/
void
NodeBase::visit(const Envelope* searchEnv, ItemVisitor& visitor)
{
    if(! isSearchMatch(*searchEnv)) {
        return;
    }

    // this node may have items as well as subnodes (since items may not
    // be wholly contained in any single subnode
    visitItems(searchEnv, visitor);

    for(const auto& subnode : subnodes) {
        if(subnode != nullptr) {
            subnode->visit(searchEnv, visitor);
        }
    }
}
Ejemplo n.º 6
0
void
NodeBase::addAllItemsFromOverlapping(const Envelope& searchEnv,
                                     vector<void*>& resultItems) const
{
    if(!isSearchMatch(searchEnv)) {
        return;
    }

    // this node may have items as well as subnodes (since items may not
    // be wholly contained in any single subnode
    resultItems.insert(resultItems.end(), items.begin(), items.end());

    for(const auto& subnode : subnodes) {
        if(subnode != nullptr) {
            subnode->addAllItemsFromOverlapping(searchEnv,
                                                resultItems);
        }
    }
}
Ejemplo n.º 7
0
void
NodeBase::addAllItemsFromOverlapping(const Envelope& searchEnv,
                                     vector<void*>& resultItems) const
{
	if (!isSearchMatch(searchEnv))
		return;

	// this node may have items as well as subnodes (since items may not
	// be wholely contained in any single subnode
	resultItems.insert(resultItems.end(), items.begin(), items.end());

	for(int i=0; i<4; ++i)
	{
		if ( subnode[i] )
		{
			subnode[i]->addAllItemsFromOverlapping(searchEnv,
			                                       resultItems);
		}
	}
}
Ejemplo n.º 8
0
/*public*/
bool
NodeBase::remove(const Envelope* itemEnv, void* item)
{
    // use envelope to restrict nodes scanned
    if(! isSearchMatch(*itemEnv)) {
        return false;
    }

    bool found = false;
    for(auto& subnode : subnodes) {
        if(subnode != nullptr) {
            found = subnode->remove(itemEnv, item);
            if(found) {
                // trim subtree if empty
                if(subnode->isPrunable()) {
                    delete subnode;
                    subnode = nullptr;
                }
                break;
            }
        }
    }
    // if item was found lower down, don't need to search for it here
    if(found) {
        return found;
    }

    // otherwise, try and remove the item from the list of items
    // in this node
    auto foundIter = find(items.begin(), items.end(), item);
    if(foundIter != items.end()) {
        items.erase(foundIter);
        return true;
    }
    else {
        return false;
    }
}