RecordId KVDictionary::Encoding::extractRecordId(const Slice &key) const { if (isRecordStore()) { BufReader br(key.data(), key.size()); return KeyString::decodeRecordId(&br); } else { dassert(isIndex()); return KVSortedDataImpl::extractRecordId(key); } }
void checkBgMove(int*img, int sx, int sy, int x, int y, int *dx, int *dy,int searchLimit = 8) { int c ; if(!isIndex(img,sx,sy,x,y)) // bg has move, search for index in the 3 pixel around x.y point { for(int xx=-searchLimit;xx<=searchLimit;xx++) for(int yy=-searchLimit;yy<=searchLimit;yy++) if(xx!=0 || yy!=0) if(isIndex(img,sx,sy,x+xx,y+yy)) { *dx=xx;*dy=yy ; if(notAllowClassicTileSizeAsMove) { if(xx==8 || -xx==8 || yy==8 || -yy==8) *dx=*dy=0xff; else if(xx==16 || -xx==16 || yy==16 || -yy==16) *dx=*dy=0xff; else if(xx==32 || -xx==32 || yy==32 || -yy==32) *dx=*dy=0xff; } return ; } } else { *dx=*dy=0 ; return ; } *dx=*dy=0xff ; // 0xff > not found return ; }
int searchIndex(POINTS data, double v){ unsigned long mid, j=data.length, i=0; while(1){ mid=(j+i)/2; if (isIndex(mid)) break; else if (tooSmall(mid)) i=mid; else j=mid; } return mid; }
ALWAYS_INLINE static void JIT_OPERATION operationPutByValInternal(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty, EncodedJSValue encodedValue) { VM* vm = &exec->vm(); NativeCallFrameTracer tracer(vm, exec); JSValue baseValue = JSValue::decode(encodedBase); JSValue property = JSValue::decode(encodedProperty); JSValue value = JSValue::decode(encodedValue); if (LIKELY(property.isUInt32())) { // Despite its name, JSValue::isUInt32 will return true only for positive boxed int32_t; all those values are valid array indices. ASSERT(isIndex(property.asUInt32())); putByVal<strict, direct>(exec, baseValue, property.asUInt32(), value); return; } if (property.isDouble()) { double propertyAsDouble = property.asDouble(); uint32_t propertyAsUInt32 = static_cast<uint32_t>(propertyAsDouble); if (propertyAsDouble == propertyAsUInt32 && isIndex(propertyAsUInt32)) { putByVal<strict, direct>(exec, baseValue, propertyAsUInt32, value); return; } } // Don't put to an object if toString throws an exception. auto propertyName = property.toPropertyKey(exec); if (vm->exception()) return; PutPropertySlot slot(baseValue, strict); if (direct) { RELEASE_ASSERT(baseValue.isObject()); if (Optional<uint32_t> index = parseIndex(propertyName)) asObject(baseValue)->putDirectIndex(exec, index.value(), value, 0, strict ? PutDirectIndexShouldThrow : PutDirectIndexShouldNotThrow); else asObject(baseValue)->putDirect(*vm, propertyName, value, slot); } else baseValue.put(exec, propertyName, value, slot); }
L_Summary* LS_TLWM::preload(CString symbol) { for (uint i = 0; i<subs.size(); i++) { if (!isIndex(subsym[i]) && (subs[i]!=NULL) && (subsym[i]==symbol)) { return subs[i]; } } L_Summary* sec = L_CreateSummary(symbol); sec->L_Attach(this); subs.push_back(sec); subsym.push_back(symbol); return sec; }
int tree<T>::push( T content, std::string type ) { int wasIndexed; bool changedDir = false;// if we change direction this will be true //temp variable to keep track if the type was inexed. if(!full) { //check if it is indexed and if it is move to the first item in the index if(isIndex(type)) { moveTo(type); wasIndexed=1; }//this will place it with like items in the tree for oginization sake //if it is a non indexed item it simply starts from the current position and goes left or right accordingly else wasIndexed=0; //only change directions when type changes; if(type!=current->type) { right= !right; changedDir = true; std::cout<<"true"<<std::endl; } if(right) { newNode(current->right, content, type); if(changedDir) current->isLroot=true;//if we are switching direction i want the new current to be the local root } else { newNode(current->left, content, type); if(changedDir) current->isLroot=true; } return wasIndexed; } else return -1;//if full obviously }
void drawIndex(void) { loadIndex(); int *ptr, color=indexBoundColor ; Form1->lastFrmImg->Picture->Bitmap->PixelFormat = pf32bit ; if(frmIndex.enable == 2) // draw 4 pink line to see index pos { ptr = (int*)(Form1->lastFrmImg->Picture->Bitmap->ScanLine[frmIndex.y]) ; for(int x=frmIndex.x;x<frmIndex.x+frmIndex.szx;x++) ptr[x]=color ; for(int y=frmIndex.y +1;y<frmIndex.y+frmIndex.szy -1;y++) { ptr = (int*)(Form1->lastFrmImg->Picture->Bitmap->ScanLine[y]) ; ptr[frmIndex.x]=color ; ptr[frmIndex.x+frmIndex.szx - 1]=color ; }; ptr = (int*)(Form1->lastFrmImg->Picture->Bitmap->ScanLine[frmIndex.y+frmIndex.szy - 1]) ; for(int x=frmIndex.x;x<frmIndex.x+frmIndex.szx;x++) ptr[x]=color ; // draw index colors in the right down img. Form1->indexPalImg->Picture->Bitmap->PixelFormat = pf32bit ; // set deep to 32 bits int lnb = (frmIndex.colorNb)>>2 ; Form1->indexPalImg->Picture->Graphic->Height = lnb + ((frmIndex.colorNb)>(lnb<<2))*1 ; Form1->indexPalImg->Picture->Graphic->Width = 4 ; Form1->indexPalImg->Top = Form1->lblCurColor->Top - (Form1->indexPalImg->Picture->Graphic->Height)*24 ; Form1->Edit3->Text = frmIndex.colorNb ; Form1->Edit4->Text = frmIndex.szx ; Form1->Edit5->Text = frmIndex.szy ; int c=0, cpt=0 ; int l=0 ; ptr = (int*)(Form1->indexPalImg->Picture->Bitmap->ScanLine[l]); for(lnb=0;lnb<4;lnb++)ptr[lnb]=0xd6d3ce ; // 0xd6d3ce -> window gray while(c<frmIndex.colorNb) // show color under index { ptr[c%4] = frmIndex.color[c++] ; if(++cpt == 4) if(++l < Form1->indexPalImg->Picture->Graphic->Height) { ptr = (int*)(Form1->indexPalImg->Picture->Bitmap->ScanLine[l]); for(lnb=0;lnb<4;lnb++)ptr[lnb]=0xd6d3ce ; cpt=0 ; } }; Form1->lastFrmImg->Refresh(); Form1->indexPalImg->Refresh(); Form1->Label1->Caption = isIndex(frmBuffer,frmSx,frmSy,frmIndex.x,frmIndex.y); if(preview) if(preview->Visible) preview->Image1->Picture->Assign(Form1->lastFrmImg->Picture) ; }
static inline void putByVal(ExecState* exec, JSValue baseValue, uint32_t index, JSValue value) { VM& vm = exec->vm(); NativeCallFrameTracer tracer(&vm, exec); ASSERT(isIndex(index)); if (direct) { RELEASE_ASSERT(baseValue.isObject()); asObject(baseValue)->putDirectIndex(exec, index, value, 0, strict ? PutDirectIndexShouldThrow : PutDirectIndexShouldNotThrow); return; } if (baseValue.isObject()) { JSObject* object = asObject(baseValue); if (object->canSetIndexQuickly(index)) { object->setIndexQuickly(vm, index, value); return; } object->methodTable(vm)->putByIndex(object, exec, index, value, strict); return; } baseValue.putByIndex(exec, index, value, strict); }
EncodedJSValue JIT_OPERATION operationGetByVal(ExecState* exec, EncodedJSValue encodedBase, EncodedJSValue encodedProperty) { VM& vm = exec->vm(); NativeCallFrameTracer tracer(&vm, exec); JSValue baseValue = JSValue::decode(encodedBase); JSValue property = JSValue::decode(encodedProperty); if (LIKELY(baseValue.isCell())) { JSCell* base = baseValue.asCell(); if (property.isUInt32()) { return getByVal(exec, base, property.asUInt32()); } else if (property.isDouble()) { double propertyAsDouble = property.asDouble(); uint32_t propertyAsUInt32 = static_cast<uint32_t>(propertyAsDouble); if (propertyAsUInt32 == propertyAsDouble && isIndex(propertyAsUInt32)) return getByVal(exec, base, propertyAsUInt32); } else if (property.isString()) { Structure& structure = *base->structure(vm); if (JSCell::canUseFastGetOwnProperty(structure)) { if (AtomicStringImpl* existingAtomicString = asString(property)->toExistingAtomicString(exec)) { if (JSValue result = base->fastGetOwnProperty(vm, structure, existingAtomicString)) return JSValue::encode(result); } } } } baseValue.requireObjectCoercible(exec); if (exec->hadException()) return JSValue::encode(jsUndefined()); auto propertyName = property.toPropertyKey(exec); if (exec->hadException()) return JSValue::encode(jsUndefined()); return JSValue::encode(baseValue.get(exec, propertyName)); }
void testObj::test<5>(void) { ensure("floating point accepted", isIndex("4.2")==false); }
/******************************************************************* * Function: ArrayIndexAnalysis::flowFunction * Purpose : compute out set from in set based on the type of statement * Initial : Nurudeen A. Lameed on July 21, 2009 ******************************************************************** Revisions and bug fixes: */ FlowSet ArrayIndexAnalysis::flowFunction(const Statement* stmt, const FlowSet& in) { // declare out flow set FlowSet out; // copy in flow set into out flow set out.insert(in.begin(), in.end()); switch(stmt->getStmtType()) { case Statement::ASSIGN: { const AssignStmt* aStmt = dynamic_cast<const AssignStmt*>(stmt); // get the left handsides Expression::ExprVector lhs = aStmt->getLeftExprs(); SymbolExpr* symbol = 0; if (lhs.size() == 1 && lhs[0]->getExprType() == Expression::SYMBOL) { symbol = dynamic_cast<SymbolExpr*>(lhs[0]); } else { // get all left symbols/expressions for (size_t i=0, size = lhs.size(); i < size; ++i) { // update out set, if it is a parameterized expression computeOutSet(lhs[i], out); } } // check the right hand side Expression* rhs = aStmt->getRightExpr(); // is symbol an array/matrix with known size? if ( allMatrixSymbols.find(symbol) != allMatrixSymbols.end() ) // symbol is used as an array ... { // get the type information TypeInfo typ = getTypeInfo(aStmt, symbol); if ( typ.getSizeKnown()) { const TypeInfo::DimVector& dimV = typ.getMatSize(); TypeInfo::DimVector bounds; // remove dimensions with value 1; (e.g. row or column vectors) std::remove_copy_if(dimV.begin(), dimV.end(), std::back_inserter(bounds), equalOne); // update the table arrayBoundsMap[symbol] = bounds; // update the flow set using the bounds updateFlowSet(symbol, bounds, out); } } // update outset (for parameterized expression) computeOutSet(rhs, out); // update outset (for index update if (isIndex(symbol)) { // compute flow set for index update computeOutSet(symbol, rhs, out); } } break; case Statement::EXPR: { // convert the statement to an expression const ExprStmt* aStmt = dynamic_cast<const ExprStmt*>(stmt); // compute out set for the statement computeOutSet(aStmt->getExpression(), out); } break; default: // do nothing; { } } return out; }
void Instruction::parseElements(string pos1, string pos2, string pos3, string pos4, string pos5) { //the first or second words are index's, not allowed if (isIndex(pos1) || isIndex(pos2) || isParam2(pos1) || isParam2(pos2)) { throwInvalidCommand("Invalid index/parameter placement : " + pos1 + " " + pos2 + " " + pos3 + " " + pos4); } string newLabel; string newOper; string newParam1; string newIndex1; string newParam2; string newIndex2; if (OPCodes::isOPCode(pos1) || OPCodes::isDirective(pos1)) // no label { newLabel = ""; newOper = pos1; if (!isIndex(pos2) && !isParam2(pos2) && !pos2.empty()) { newParam1 = pos2; if (isIndex(pos3)) { newIndex1 = pos3; if (isParam2(pos4)) { newParam2 = pos4; } } else if (isParam2(pos3)) { newParam2 = pos3; if (isIndex(pos4)) { newIndex2 = pos4; } } } } else if (OPCodes::isOPCode(pos2) || OPCodes::isDirective(pos2)) // has label { newLabel = pos1; newOper = pos2; if (!isIndex(pos3) && !isParam2(pos3) && !pos2.empty()) { newParam1 = pos3; if (isIndex(pos4)) { newIndex1 = pos4; if (isParam2(pos5)) { newParam2 = pos5; } } else if (isParam2(pos4)) { newParam2 = pos4; if (isIndex(pos5)) { newIndex2 = pos5; } } } } else { throwInvalidCommand("Invalid command or missing OP code"); } set(newLabel, newOper, newParam1, newIndex1, newParam2, newIndex2); }
bool BufferedLogForwarder::isStatusIndex(const std::string& index) { return isIndex(index, false); }
/******************************************************************* * Function: ArrayIndexAnalysis::fillSets * Purpose : Fill data structures for the flow analysis * Initial : Nurudeen A. Lameed on July 21, 2009 ******************************************************************** Revisions and bug fixes: */ void ArrayIndexAnalysis::fillSets(const Expression *expr) { // what kind of expression? switch (expr->getExprType()) { case Expression::PARAM: { const ParamExpr* paramExpr = dynamic_cast<const ParamExpr*>(expr); // matrix/array symbol SymbolExpr* mSymbol = paramExpr->getSymExpr(); // assume for now, all parameterized expression symbols are matrices ... // collect in one place all array/matrices symbols allMatrixSymbols.insert(mSymbol); const Expression::ExprVector& args = paramExpr->getArguments(); // insert the indexes for (size_t j = 0, size = args.size(); j < size; ++j) { if ( args[j]->getExprType() == Expression::SYMBOL || args[j]->getExprType() == Expression::INT_CONST ) { IndexKey iKey = {args[j], j}; if (!isIndex(iKey)) { // new matrix, insert it. Expression::SymbolSet s; s.insert(mSymbol); indexMatMap[iKey] = s; } else { indexMatMap[iKey].insert(mSymbol); } } } } break; case Expression::BINARY_OP: { const BinaryOpExpr* bOp = dynamic_cast<const BinaryOpExpr*>(expr); fillSets(bOp->getLeftExpr()); fillSets(bOp->getRightExpr()); } break; case Expression::UNARY_OP: { const UnaryOpExpr* uOp = dynamic_cast<const UnaryOpExpr*>(expr); fillSets(uOp->getOperand()); } break; default: // do nothing { } } }
//! Find pointer to node at specified path JsonTree* JsonTree::getNodePtr( const string &relativePath, bool caseSensitive, char separator ) const { // Format path into dotted address std::string path = boost::replace_all_copy( relativePath, "[", std::string( 1, separator ) ); path = boost::replace_all_copy( path, "'", ""); path = boost::replace_all_copy( path, "]", ""); // Start search from this node JsonTree *curNode = const_cast<JsonTree*>( this ); // Split address at dot and iterate tokens vector<string> pathComponents = split( path, separator ); for( vector<string>::const_iterator pathIt = pathComponents.begin(); pathIt != pathComponents.end(); ++pathIt ) { // Declare target node ConstIter node; // The key is numeric if( isIndex( *pathIt ) ) { // Find child which uses this index as its key uint32_t index = boost::lexical_cast<int32_t>( *pathIt ); uint32_t i = 0; for ( node = curNode->getChildren().begin(); node != curNode->getChildren().end(); ++node, i++ ) { if ( i == index ) { break; } } } else { // Iterate children node = curNode->getChildren().begin(); while( node != curNode->getChildren().end() ) { // Compare child's key to path component bool keysMatch = false; string key1 = node->getKey(); string key2 = *pathIt; if( caseSensitive && key1 == key2 ) { keysMatch = true; } else if ( !caseSensitive && ( boost::iequals( key1, key2 ) ) ) { keysMatch = true; } // Break if found, advance node if not if( keysMatch ) { break; } else { ++node; } } } // Return null pointer if we're out of nodes to search, // otherwise assign node and continue to search its children if( node == curNode->getChildren().end() ) { return 0; } else { curNode = const_cast<JsonTree*>( &( *node ) ); } } // Return child return curNode; }
bool BufferedLogForwarder::isResultIndex(const std::string& index) { return isIndex(index, true); }
void testObj::test<8>(void) { ensure("empty string accepted", isIndex("")==false); }
void testObj::test<7>(void) { ensure("white space accepted", isIndex("1 2")==false); }
void testObj::test<2>(void) { ensure("valid number not accepted", isIndex("0")==true); }
void testObj::test<3>(void) { ensure("negative accepted", isIndex("-1")==false); }
void testObj::test<4>(void) { ensure("non-number accepted", isIndex("narf")==false); }
void testObj::test<6>(void) { ensure("digits and letters accepted", isIndex("42xyz")==false); }
BSONObj KVDictionary::Encoding::extractKey(const Slice &key, const Slice &val) const { dassert(isIndex()); return KVSortedDataImpl::extractKey(key, val, _ordering); }