void KDT<T>::printRange(const std::vector<T> &low, const std::vector<T> &high, TreeNode<T> *r, int idx) const { idx = idx%K; if( r == nullptr ) return; bool valid = true; for(int i = 0; i < K; ++i) { if( low[i] <= r->val[i] && high[i] >= r->val[i] ) valid = valid && true; else { valid = false; break; } } if( valid ) { std::cout << "("; for(int i = 0; i < K; ++i) { std::cout << r->val[i] << (( i == K - 1 ) ? "" : " , "); } std::cout << ") "; } if( low[idx] < r->val[idx] ) return printRange(low,high, r->left, idx+1); else return printRange(low,high, r->right,idx+1); }
void printRange(TreeNode T, ElementType k1, ElementType k2) { if (T != NULL) { if (T->data >= k1 && T->data <= k2) printf_s("%d ", T->data); printRange(T->Left, k1, k2); printRange(T->Right, k1, k2); } }
int main(int argc, char *argv[]) { int num1,num2,k; printf("Please enter value1: "); scanf("%i",&num1); printf("Please enter value2: "); scanf("%i",&num2); printRange(num1,num2,1); }
void printRange(int num1,int num2, int k) { if(num1>num2) return; else { printf("step[%d] == %d\n",k, num1); printRange(++num1,num2,++k); } }
static void printTransitions(const DFA& dfa, unsigned sourceNodeId) { const DFANode& sourceNode = dfa.nodes[sourceNodeId]; auto transitions = sourceNode.transitions(dfa); if (transitions.begin() == transitions.end()) return; HashMap<unsigned, Vector<uint16_t>, DefaultHash<unsigned>::Hash, WTF::UnsignedWithZeroKeyHashTraits<unsigned>> transitionsPerTarget; // First, we build the list of transitions coming to each target node. for (const auto& transition : transitions) { unsigned target = transition.target(); transitionsPerTarget.add(target, Vector<uint16_t>()); for (unsigned offset = 0; offset < transition.range().size(); ++offset) transitionsPerTarget.find(target)->value.append(transition.first() + offset); } // Then we go over each one an display the ranges one by one. for (const auto& transitionPerTarget : transitionsPerTarget) { dataLogF(" %d -> %d [label=\"", sourceNodeId, transitionPerTarget.key); Vector<uint16_t> incommingCharacters = transitionPerTarget.value; std::sort(incommingCharacters.begin(), incommingCharacters.end()); char rangeStart = incommingCharacters.first(); char rangeEnd = rangeStart; bool first = true; for (unsigned sortedTransitionIndex = 1; sortedTransitionIndex < incommingCharacters.size(); ++sortedTransitionIndex) { char nextChar = incommingCharacters[sortedTransitionIndex]; if (nextChar == rangeEnd+1) { rangeEnd = nextChar; continue; } printRange(first, rangeStart, rangeEnd); rangeStart = rangeEnd = nextChar; first = false; } printRange(first, rangeStart, rangeEnd); dataLogF("\"];\n"); } }
static void printTransitions(const Vector<NFANode>& graph, unsigned sourceNode, uint16_t epsilonTransitionCharacter) { const NFANode& node = graph[sourceNode]; const HashMap<uint16_t, NFANodeIndexSet, DefaultHash<uint16_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<uint16_t>>& transitions = node.transitions; HashMap<unsigned, HashSet<uint16_t, DefaultHash<uint16_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<uint16_t>>, DefaultHash<unsigned>::Hash, WTF::UnsignedWithZeroKeyHashTraits<unsigned>> transitionsPerTarget; for (const auto& transition : transitions) { for (unsigned targetNode : transition.value) { transitionsPerTarget.add(targetNode, HashSet<uint16_t, DefaultHash<uint16_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<uint16_t>>()); transitionsPerTarget.find(targetNode)->value.add(transition.key); } } for (const auto& transitionPerTarget : transitionsPerTarget) { dataLogF(" %d -> %d [label=\"", sourceNode, transitionPerTarget.key); Vector<uint16_t> incommingCharacters; copyToVector(transitionPerTarget.value, incommingCharacters); std::sort(incommingCharacters.begin(), incommingCharacters.end()); uint16_t rangeStart = incommingCharacters.first(); uint16_t rangeEnd = rangeStart; bool first = true; for (unsigned sortedTransitionIndex = 1; sortedTransitionIndex < incommingCharacters.size(); ++sortedTransitionIndex) { uint16_t nextChar = incommingCharacters[sortedTransitionIndex]; if (nextChar == rangeEnd+1) { rangeEnd = nextChar; continue; } printRange(first, rangeStart, rangeEnd, epsilonTransitionCharacter); rangeStart = rangeEnd = nextChar; first = false; } printRange(first, rangeStart, rangeEnd, epsilonTransitionCharacter); dataLogF("\"];\n"); } for (unsigned targetOnAnyCharacter : node.transitionsOnAnyCharacter) dataLogF(" %d -> %d [label=\"[any input]\"];\n", sourceNode, targetOnAnyCharacter); }
int main() { TreeNode T = NULL; int i, inData; printf_s("Elements:\n"); for (i = 0; i < 7; i++) { printf_s("#%d: ", i + 1); scanf_s("%d", &inData); T = insert(inData, T); } printf_s("\nTree:\n"); display(T); printf_s("\nRange[1,5]: "); printRange(T, 1, 5); makeEmpty(T); return 0; }
static void print(O& o, Range const& r) { printRange(o, r); }
// Test Function void test1() { printf("Printing Range from 5 to 23\n"); printRange(5, 23); printf("Printing Range from 3 to 15\n"); printRange(3, 15); }
int OPTpushrangesImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { int i,j, limit,actions=0; InstrPtr p, *old; int x,y,z; Range range; if( mb->errors) return 0; range= (Range) GDKzalloc(mb->vtop * sizeof(RangeRec)); if (range == NULL) return 0; OPTDEBUGpushranges mnstr_printf(cntxt->fdout,"#Range select optimizer started\n"); (void) stk; (void) pci; limit = mb->stop; old = mb->stmt; /* * In phase I we collect information about constants */ for (i = 0; i < limit; i++) { p = old[i]; if( p->barrier) break; /* end of optimizer */ for(j=p->retc; j< p->argc; j++) range[getArg(p,j)].used++; for(j=0; j<p->retc; j++){ range[getArg(p,j)].lastupdate= i; if( range[getArg(p,j)].lastrange == 0) range[getArg(p,j)].lastrange= i; } if( getModuleId(p)== algebraRef && ( getFunctionId(p)== selectRef || getFunctionId(p)== uselectRef) ){ /* * The operation X:= algebra.select(Y,L,H,Li,Hi) is analysed. * First, we attempt to propagate the range known for Y onto the * requested range of X. This may lead to smaller range of * even the conclusion that X is necessarily empty. * Of course, only under the condition that Y has not been changed by a * side-effect since it was bound to X. */ x= getArg(p,1); y= getArg(p,2); if( range[x].lcst && isVarConstant(mb,y) ){ /* merge lowerbound */ if( ATOMcmp( getVarGDKType(mb,y), VALptr( &getVarConstant(mb,range[x].lcst)), VALptr( &getVarConstant(mb,y)) ) > 0){ getArg(p,2)= range[x].lcst; z= range[x].srcvar; if( getArg(p,1) == x && range[z].lastupdate == range[z].lastrange){ getArg(p,1) = z; actions++; } } y= getArg(p,3); /* merge higherbound */ if( ATOMcmp( getVarGDKType(mb,y), VALptr( &getVarConstant(mb,range[x].hcst)), VALptr( &getVarConstant(mb,y)) ) < 0 || ATOMcmp( getVarGDKType(mb,y), VALptr( &getVarConstant(mb,y)), ATOMnilptr(getVarType(mb,y)) ) == 0){ getArg(p,3)= range[x].hcst; z= range[x].srcvar; if( getArg(p,1) == x && range[z].lastupdate == range[z].lastrange){ getArg(p,1) = z; actions++; } } } /* * The second step is to assign the result of this exercise to the * result variable. */ x= getArg(p,0); if( isVarConstant(mb, getArg(p,2)) ){ range[x].lcst = getArg(p,2); range[x].srcvar= getArg(p,1); range[x].lastupdate= range[x].lastrange = i; } if( isVarConstant(mb, getArg(p,3)) ){ range[x].hcst = getArg(p,3); range[x].srcvar= getArg(p,1); range[x].lastupdate= range[x].lastrange = i; } /* * If both range bounds are constant, we can also detect empty results. * It is empty if L> H or when L=H and the bounds are !(true,true). */ x= getArg(p,2); y= getArg(p,3); if( isVarConstant(mb, x) && isVarConstant(mb, y) ){ z =ATOMcmp( getVarGDKType(mb,y), VALptr( &getVarConstant(mb,x)), VALptr( &getVarConstant(mb,y))); x= p->argc > 4; x= x && isVarConstant(mb,getArg(p,4)); x= x && isVarConstant(mb,getArg(p,5)); x= x && getVarConstant(mb,getArg(p,4)).val.btval; x= x && getVarConstant(mb,getArg(p,5)).val.btval; if( z > 0 || (z==0 && p->argc>4 && !x)) { int var = getArg(p, 0); wrd zero = 0; ValRecord v, *vp; vp = VALset(&v, TYPE_wrd, &zero); varSetProp(mb, var, rowsProp, op_eq, vp); /* create an empty replacement */ x = getArgType(mb, p, 1); p->argc=1; getModuleId(p)= batRef; getFunctionId(p)= newRef; p= pushArgument(mb,p, newTypeVariable(mb, getHeadType(x))); (void) pushArgument(mb,p, newTypeVariable(mb, getTailType(x))); actions++; } } } } OPTDEBUGpushranges for(j=0; j< mb->vtop; j++) if( range[j].used ) printRange(cntxt, mb,range,j); /* * Phase II, if we succeeded in pushing constants around and * changing instructions, we might as well try once more to perform * aliasRemoval, constantExpression, and pushranges. */ GDKfree(range); return actions; }
int QPrintDialog::exec() { Q_D(QPrintDialog); QMacBlockingFunction func; Boolean result; // If someone is reusing a QPrinter object, the end released all our old // information. In this case, we must reinitialize. if (d->ep->session == 0) d->ep->initialize(); // Carbon's documentation lies. // It seems the only way that Carbon lets you use all is if the minimum // for the page range is 1. This _kind of_ makes sense if you think about // it. However, calling _q_setFirstPage or _q_setLastPage always enforces the range. PMSetPageRange(d->ep->settings, minPage(), maxPage()); if (printRange() == PageRange) { PMSetFirstPage(d->ep->settings, fromPage(), false); PMSetLastPage(d->ep->settings, toPage(), false); } { //simulate modality QWidget modal_widg(0, Qt::Window); modal_widg.setObjectName(QLatin1String(__FILE__ "__modal_dlg")); QApplicationPrivate::enterModal(&modal_widg); PMSessionPrintDialog(d->ep->session, d->ep->settings, d->ep->format, &result); QApplicationPrivate::leaveModal(&modal_widg); } if (result) { UInt32 frompage, topage; PMGetFirstPage(d->ep->settings, &frompage); PMGetLastPage(d->ep->settings, &topage); topage = qMin(UInt32(INT_MAX), topage); setFromTo(frompage, topage); // OK, I need to map these values back let's see // If from is 1 and to is INT_MAX, then print it all // (Apologies to the folks with more than INT_MAX pages) // ...that's a joke. if (fromPage() == 1 && toPage() == INT_MAX) { setPrintRange(AllPages); setFromTo(0,0); } else { setPrintRange(PageRange); // In a way a lie, but it shouldn't hurt. // Carbon hands us back a very large number here even for ALL, set it to max // in that case to follow the behavior of the other print dialogs. if (maxPage() < toPage()) setFromTo(fromPage(), maxPage()); } // Keep us in sync with file output PMDestinationType dest; PMSessionGetDestinationType(d->ep->session, d->ep->settings, &dest); if (dest == kPMDestinationFile) { QCFType<CFURLRef> file; PMSessionCopyDestinationLocation(d->ep->session, d->ep->settings, &file); UInt8 localFile[2048]; // Assuming there's a POSIX file system here. CFURLGetFileSystemRepresentation(file, true, localFile, sizeof(localFile)); d->ep->outputFilename = QString::fromUtf8(reinterpret_cast<const char *>(localFile)); } } return result; }
void KDT<T>::printRange(const std::vector<T> &low, const std::vector<T> &high) const { printRange(low,high,root,0); }