Пример #1
0
void YSelection::delInterval( const YInterval& i )
{
    bool containsFrom;
    bool containsTo;
    unsigned int idFrom = locatePosition( i.from(), &containsFrom );
    unsigned int idTo = locatePosition( i.to(), &containsTo );
    if ( idFrom == idTo && !containsFrom && !containsTo ) return ;
    // dbg() << "delInterval: from=" << idFrom << "," << containsFrom << "; to=" << idTo << "," << containsTo << endl;

    if ( containsFrom && i.from() <= mMap[ idFrom ].from() ) {
        containsFrom = false;
    }
    if ( containsTo && i.to() >= mMap[ idTo ].to() ) {
        ++idTo;
        containsTo = false;
    }
    if ( containsTo && containsFrom && idFrom == idTo ) {
        ++idTo;
        insertInterval( idTo, mMap[ idFrom ] );
    }

    if ( containsFrom )
        mMap[ idFrom ].setTo( YBound(i.from().pos(), !i.from().opened()) );
    if ( containsTo )
        mMap[ idTo ].setFrom( YBound(i.to().pos(), !i.to().opened()) );
    removeInterval( idFrom + (containsFrom ? 1 : 0), idTo - idFrom - (containsFrom && containsTo ? 1 : 0) );
}
Пример #2
0
void YSelection::addInterval( const YInterval& i )
{
    bool containsFrom;
    bool containsTo;
    unsigned int idFrom = locatePosition( i.from(), &containsFrom );
    unsigned int idTo = locatePosition( i.to(), &containsTo );
    if ( containsFrom && containsTo ) {
        if ( idFrom != idTo ) {
            mMap[ idFrom ].setTo( mMap[ idTo ].to() );
            removeInterval( idFrom + 1, idTo - idFrom );
        }
    } else if ( containsFrom ) {
        mMap[ idFrom ].setTo( i.to() );
        removeInterval( idFrom + 1, idTo - idFrom - 1 );
    } else if ( containsTo ) {
        mMap[ idTo ].setFrom( i.from() );
        removeInterval( idFrom, idTo - idFrom );
    } else if ( idTo != idFrom ) {
        mMap[ idFrom ].setFrom( i.from() );
        mMap[ idFrom ].setTo( i.to() );
        removeInterval( idFrom + 1, idTo - idFrom );
    } else {
        insertInterval( idFrom, i );
    }
}
Пример #3
0
/**
 * Inserts new node with given key in the tree
 * NOTE: only the leafs of this tree contains the data we need, the rest is just for infrastructure
 */
void IntervalMap::insertInterval(node *leaf, double key) {
	if (key < leaf->key_value) {
		if (leaf->left == NULL) {
			leaf->left = new node;
			leaf->left->key_value = key;
			leaf->left->left = NULL;
			leaf->left->right = NULL;
			leaf->left->tracks = NULL;
		} else {
			insertInterval(leaf->left, key);
		}
	} else {
		if (leaf->right == NULL) {
			leaf->right = new node;
			leaf->right->key_value = key;
			leaf->right->left = NULL;
			leaf->right->right = NULL;
			leaf->right->tracks = NULL;
		} else {
			insertInterval(leaf->right, key);
		}
	}
}
Пример #4
0
/*
 * Build up binary tree containing all 100 Intervals
 */
void IntervalMap::allocateIntervalMap() {
	/*	this->map = new std::set<PC>*[numberOfIntervalls];
	 for (int i = 0; i < numberOfIntervalls; i++) {
	 map[i] = new std::set<PC>();
	 }*/
	map = new node;
	map->key_value = 50;
	map->tracks = NULL;
	map->left = NULL;
	map->right = NULL;

	insertInterval(map, 25);
	insertInterval(map, 75);
	for (int i = 0; i < 4; i++) {
		insertInterval(map, 12 + i * 25);
		insertInterval(map, 6 + i * 25);
		insertInterval(map, 3 + i * 25);
		insertInterval(map, 5 + i * 25);
		insertInterval(map, 4 + i * 25);
		insertInterval(map, 1 + i * 25);
		insertInterval(map, 2 + i * 25);
		insertInterval(map, 9 + i * 25);
		insertInterval(map, 8 + i * 25);
		insertInterval(map, 7 + i * 25);
		insertInterval(map, 11 + i * 25);
		insertInterval(map, 10 + i * 25);
		insertInterval(map, 18 + i * 25);
		insertInterval(map, 15 + i * 25);
		insertInterval(map, 14 + i * 25);
		insertInterval(map, 13 + i * 25);
		insertInterval(map, 17 + i * 25);
		insertInterval(map, 16 + i * 25);
		insertInterval(map, 21 + i * 25);
		insertInterval(map, 20 + i * 25);
		insertInterval(map, 19 + i * 25);
		insertInterval(map, 23 + i * 25);
		insertInterval(map, 22 + i * 25);
		insertInterval(map, 24 + i * 25);
	}
	insertInterval(map, 0);
	//debug
//	inorder(map);

}