void GLColorMap::copyMap(GLsizei newNumEntries,const GLColorMap::Color* newEntries,GLdouble newMin,GLdouble newMax) { /* Set mapping range: */ min=newMin; max=newMax; /* Set number of entries: */ setNumEntries(newNumEntries); /* Copy map entries: */ memcpy(entries,newEntries,numEntries*sizeof(Color)); }
GLColorMap& GLColorMap::load(const char* fileName) { /* Create entry array: */ setNumEntries(256); /* Load the color entries from file: */ IO::AutoFile file(IO::openFile(fileName)); file->setEndianness(IO::File::BigEndian); file->read(entries,numEntries); return *this; }
GLColorMap::GLColorMap(GLenum type,GLfloat alphaMax,GLfloat alphaGamma,GLdouble sMin,GLdouble sMax) :numEntries(0),entries(0),min(sMin),max(sMax) { /* Create entry array: */ setNumEntries(256); /* Create the palette colors: */ GLenum colorType=type&(GREYSCALE|RAINBOW); if(colorType==GREYSCALE) { for(GLsizei i=0;i<256;++i) { entries[i][0]=GLfloat(i)/255.0f; entries[i][1]=GLfloat(i)/255.0f; entries[i][2]=GLfloat(i)/255.0f; } } else if(colorType==RAINBOW) { for(GLsizei i=0;i<256;++i) { /* Create rainbow colors: */ GLdouble rad=GLdouble(i)*(2.0*M_PI/256.0); if(rad<=2.0*M_PI/3.0) entries[i][0]=cos(0.75*rad); else if(rad>=4.0*M_PI/3.0) entries[i][0]=cos(0.75*(2.0*M_PI-rad)); else entries[i][0]=0.0; entries[i][1]=sin(0.75*rad); if(entries[i][1]<0.0) entries[i][1]=0.0; entries[i][2]=sin(0.75*(rad-2.0*M_PI/3.0)); if(entries[i][2]<0.0) entries[i][2]=0.0; } } /* Create the palette opacities: */ GLenum alphaType=type&(CONSTANT_ALPHA|RAMP_ALPHA); if(alphaType==CONSTANT_ALPHA) { for(GLsizei i=0;i<256;++i) entries[i][3]=alphaMax; } else if(alphaType==RAMP_ALPHA) { double ag=double(alphaGamma); for(GLsizei i=0;i<256;++i) entries[i][3]=alphaMax*pow(double(i)/255.0,ag); } }
void MamdaOrderBookPriceLevel::markAllDeleted () { setSizeChange (-getSize()); setSize (0); setNumEntries (0); setAction (MamdaOrderBookPriceLevel::MAMDA_BOOK_ACTION_DELETE); MamdaOrderBookPriceLevel::iterator entryEnd = end(); MamdaOrderBookPriceLevel::iterator entryIter = begin(); for (; entryIter != entryEnd; ++entryIter) { MamdaOrderBookEntry* entry = *entryIter; entry->setSize (0); entry->setAction (MamdaOrderBookEntry::MAMDA_BOOK_ACTION_DELETE); } }
void MamdaOrderBookPriceLevel::setAsDifference ( const MamdaOrderBookPriceLevel& lhs, const MamdaOrderBookPriceLevel& rhs) { assert (lhs.getPrice() == rhs.getPrice()); MamdaOrderBookPriceLevel::iterator lhsEnd = end(); MamdaOrderBookPriceLevel::iterator lhsIter = begin(); MamdaOrderBookPriceLevel::iterator rhsEnd = end(); MamdaOrderBookPriceLevel::iterator rhsIter = begin(); while ((lhsIter != lhsEnd) && (rhsIter != rhsEnd)) { const char* lhsId = NULL; const char* rhsId = NULL; mama_quantity_t lhsSize = 0.0; mama_quantity_t rhsSize = 0.0; if (lhsIter != lhsEnd) { const MamdaOrderBookEntry* entry = *lhsIter; lhsId = entry->getId(); lhsSize = entry->getSize(); } if (rhsIter != rhsEnd) { const MamdaOrderBookEntry* entry = *rhsIter; rhsId = entry->getId(); rhsSize = entry->getSize(); } if (lhsId && rhsId) { if (strcmp(lhsId,rhsId)==0) { // Same ID, maybe different size. if (mama_isQuantityEqual (lhsSize, rhsSize)) { MamdaOrderBookEntry* updateEntry = new MamdaOrderBookEntry (**rhsIter); updateEntry->setAction( MamdaOrderBookEntry::MAMDA_BOOK_ACTION_UPDATE); addEntry (updateEntry); } ++lhsIter; ++rhsIter; continue; } else { // Different ID (either something exists on the LHS // and not on RHS or vice versa). MamdaOrderBookPriceLevel::const_iterator rhsFound = findEntryAfter (rhsIter, lhsId); if (rhsFound != rhsEnd) { // The ID from the LHS was found on the RHS, so // there must have been additional entries on the // RHS, which we now need to add. do { MamdaOrderBookEntry* entry = new MamdaOrderBookEntry(**rhsIter); addEntry (entry); ++rhsIter; } while (rhsIter != rhsFound); } else { // The ID from the LHS was not present on the RHS, // so add the LHS entry. Note: it would probably // be faster to iterate over the LHS side rather // than begin the loop again. MamdaOrderBookEntry* entry = new MamdaOrderBookEntry(**lhsIter); addEntry (entry); ++lhsIter; } } } } setPrice (rhs.getPrice()); setSizeChange (rhs.getSize() - lhs.getSize()); setSize (rhs.getSize()); setNumEntries (rhs.getNumEntries()); setAction (MamdaOrderBookPriceLevel::MAMDA_BOOK_ACTION_UPDATE); setTime (rhs.getTime()); setSide (rhs.getSide()); }
RC insertKey(BTreeHandle *tree, Value *key, RID rid) { RC rc; // get root page PageNumber rootPage; rc = -99; rc = getRootPage(tree, &rootPage); if (rc != RC_OK) { return rc; } RID result; BT_KeyPosition *kp; rc = -99; rc = searchKeyFromRoot(tree, key, &result, kp); // if return RC_OK, then the to-be inserted key is found, return RC_IM_KEY_ALREADY_EXISTS // else if return RC_IM_KEY_NOT_FOUND, then the to-be inserted key is not in the tree, insert it // else, some error happens, return rc if (rc == RC_OK) { return RC_IM_KEY_ALREADY_EXISTS; } else if (rc == RC_IM_KEY_NOT_FOUND) { // start to insert // get N int n; rc = -99; rc = getN(tree, &n); if (rc != RC_OK) { return rc; } // get current keys int currentKeys; rc = -99; rc = getCurrentKeys(tree, kp->nodePage, ¤tKeys); if (rc != RC_OK) { return rc; } // if current node is full, split it into two nodes if (currentKeys == n) { // split splitNode(); } else { rc = -99; rc = insertLeafNode(tree, kp, key, &rid); if (rc != RC_OK) { return rc; } } // increment # of entries by 1 int numEntries; rc = -99; rc = getNumEntries(tree, kp->nodePage, &numEntries); if (rc != RC_OK) { return rc; } rc = -99; rc = setNumEntries(tree, kp->nodePage, ++numEntries); if (rc != RC_OK) { return rc; } } else { return rc; } return RC_OK; }