/*
* returns the physical address when supplied the page's index in the original file
*/
int logicalToPhysical(int index) {
    double exp = 0; // keep track of the power we want to raiseiin 2 to
    int *frameB = malloc(sizeof(int)*8);
    int *offsetB = malloc(sizeof(int)*8);
    int pageNum = pageNums[index];
    frameB = toB(pageTable[pageNum]);
    offsetB = toB(offsets[index]);

    int physicalAddress = 0;
    for (int i = 7; i >= 0; i--) {
        if (offsetB[i] == 1) {
            //printf("%f\n", pow(2,exp));
            physicalAddress += (int) pow(2, exp);
        }
        exp++;
    }
    
    for (int j = 7; j >= 0; j--) {
        if (frameB[j] == 1) {
            physicalAddress += (int) pow(2, exp);
            //printf("%f\n", pow(2,exp));
        }
        exp++;
    }
    //printf("physical address %d\n", physicalAddress);
    return physicalAddress;
}
void A::Trace(Visitor* visitor)
{
    switch (m_type) {
    case TB:
        toB(this)->TraceAfterDispatch(visitor);
        break;
    }
}
Lab_Colour ColourPickerConversions::toLab(RGB_Colour colour)
{
    float X = toX(colour.r, colour.g, colour.b);
    float Y = toY(colour.r, colour.g, colour.b);
    float Z = toZ(colour.r, colour.g, colour.b);

    float L = toL(Y);
    float a = toA(X, Y);
    float b = toB(Y, Z);

    return Lab_Colour(L, a, b);
}
Beispiel #4
0
int main(){

	int numero, b, i;
	char base1, base2;
	char *bin;
	bin = (char*)malloc(32*sizeof(char));
	for(i=0;i<32;i++){
		bin[i]=0;;
	}
	scanf("%c",&base1);

	b = traduzbase(base1);
	if(b==8){
		scanf("%o",&numero);
	}
	if(b==10){
		scanf("%d",&numero);
	}
	if(b==16){
		scanf("%x",&numero);
	}
	if(b==2){
		scanf("%s",&bin);
	}

	scanf("%c%c",&base1,&base2);
	if(b!=2){
		bin = toB(numero,bin);
	}


	b = traduzbase(base2);
	if(b==8){
		printf("%o\n",fromB(bin,b));
	}
	if(b==10){
		printf("%d\n",fromB(bin,b));
	}
	if(b==16){
		printf("%x\n",fromB(bin,b));
	}
	if(b==2){
		for(i=31;i>=0;i--){
			printf("%d",bin[i]);
		}
	}

	printf("\n");
	system("pause");
}
void A::trace(Visitor* visitor)
{
    switch (m_type) {
    case TB:
        toB(this)->traceAfterDispatch(visitor);
        break;
    case TC:
        static_cast<C*>(this)->traceAfterDispatch(visitor);
        break;
    case TD:
        // Missing static_cast<D*>(this)->traceAfterDispatch(visitor);
        break;
    }
}
Beispiel #6
0
/** given an unmapped node from set A we follow it from set B until it cannot be matched from B
  if not mateched from B then umn is a chain*/
RamAutoIndex::Chain RamAutoIndex::getChain(const SearchColumns umn, const RamMaxMatching::Matchings& match) {
    SearchColumns start = umn; // start at an unmateched node
    Chain chain;
    // Assume : no circular mappings, i.e. a in A -> b in B -> ........ -> a in A is not allowed.
    // Given this, the loop will terminate
    while (true) {
        RamMaxMatching::Matchings::const_iterator mit = match.find(toB(start)); // we start from B side
        chain.insert(start);

        if(mit == match.end()) {
            return chain;
        }

        SearchColumns a = mit->second;
        chain.insert(a);
        start = a; 
    }
}
Beispiel #7
0
/** map the keys in the key set to lexicographical order */
void RamAutoIndex::solve() { 
    if(searches.size() == 0) return;

//    // -- hack to disable indexing --
//
//    // every search pattern gets its naive index
//    for(SearchColumns cur : searches) {
//
//        // obtain order
//        LexicographicalOrder order;
//        SearchColumns mask = cur;
//        for(int i=0; mask != 0; i++) {
//            if (!(1<<i & mask)) continue;
//            order.push_back(i);
//            // clear bit
//            mask &= ~(1<<i);
//        }
//
//        // add new order
//        orders.push_back(order);
//
//        // register pseudo chain
//        chainToOrder.push_back(Chain());
//        chainToOrder.back().insert(cur);
//    }
//
//    std::cout << "Orders: " << orders << "\n";
//    std::cout << "Chains: " << chainToOrder << "\n";
//
//    return;
//
//    // ------------------------------



    // Construct the matching poblem
    for (SearchSet::const_iterator it = searches.begin(); it != searches.end(); ++it) {
        // For this node check if other nodes are strict subsets
        for (SearchSet::const_iterator itt = searches.begin(); itt != searches.end(); ++itt) {
            if (isStrictSubset(*it, *itt)) {
                matching.addEdge(*it, toB(*itt));
            }
        }
    } 

    // Perform the hopcroft-karp on the graph and receive matchings (mapped A-> B and B->A)
    // Assume: alg.calculate is not called on an empty graph
    ASSERT(searches.size() > 0);
    const RamMaxMatching::Matchings& matchings = matching.calculate();

    // Extract the chains given the nodes and matchings
    const ChainOrderMap chains = getChainsFromMatching(matchings, searches);

    // Should never get no chains back as we never call calculate on an empty graph
    ASSERT(chains.size() > 0);

    for (ChainOrderMap::const_iterator it = chains.begin(); it != chains.end(); ++it) {
        std::vector<int> ids;
        SearchColumns initDelta = *(it->begin());
        insertIndex(ids, initDelta);

        for (Chain::iterator iit = it->begin(); next(iit) != it->end(); ++iit) {
            SearchColumns delta = *(next(iit)) - *iit; 
            insertIndex(ids, delta);
        }

        ASSERT(ids.size() > 0);

        orders.push_back(ids);
    }

    // Construct the matching poblem
    for (SearchSet::const_iterator it = searches.begin(); it != searches.end(); ++it) {
        int idx = map(*it); 
        size_t l = card(*it); 
        SearchColumns k = 0; 
        for (size_t i=0;i<l;i++) { 
            k = k + (1 << (orders[idx][i])); 
        }
        ASSERT(k == *it && "incorrect lexicographical order");  
    } 
}