//------------------------------------------------------------------------------ // queryRunwayByChannel() -- find all airports within search area with 'chan' // channel ILS components. //------------------------------------------------------------------------------ int AirportLoader::queryRunwayByChannel(const int chan) { double mr2(FLT_MAX); if (mrng > 0.0f) mr2 = mrng*mrng; // compute range**2 to ref point and select all that have range less // than maxRange nql = 0; for (int i = 0; i < nrl; i++) { AirportKey* k = static_cast<AirportKey*>(rl[i]); k->rng2 = range2(k->lat,k->lon); if (k->rng2 < mr2) { for (RunwayKey* rwk = k->runways; rwk != 0; rwk = rwk->next) { if ( chkRwIlsChan( rwk, chan ) ) { ql[nql++] = rwk; } } } } // sort and limit by range rangeSort2(); // limit number of result records if (qlimit > 0 && nql > qlimit) nql = qlimit; return nql; }
TEST(ConsistentHashMapTest, TestGetRange) { TestMap test_map; typedef std::pair<string, Range<size_t>> node_range_type; const string node1("node1"); test_map.insert(0, node1); size_t range = numeric_limits<size_t>::max() / test_map.num_partitions(); vector<size_t> expected_parts; for (unsigned int i = 0; i < test_map.num_partitions(); i++) { expected_parts.push_back(range*i); } vector<size_t> actual_parts = test_map.get_partitions(); EXPECT_THAT(actual_parts, ContainerEq(expected_parts)); Range<size_t> range1(0, range - 1); Range<size_t> range2(range, range*2 - 1); Range<size_t> range3(range*2, range*3 - 1); Range<size_t> range4(range*3, numeric_limits<size_t>::max()); node_range_type range1_node1 = std::make_pair(node1, range1); node_range_type range2_node1 = std::make_pair(node1, range2); node_range_type range3_node1 = std::make_pair(node1, range3); node_range_type range4_node1 = std::make_pair(node1, range4); node_range_type tmp; EXPECT_TRUE(test_map.get_range(range/2, &tmp).ok()); EXPECT_EQ(range1_node1, tmp); EXPECT_TRUE(test_map.get_range(range + range/2, &tmp).ok()); EXPECT_EQ(range2_node1, tmp); EXPECT_TRUE(test_map.get_range(range*2 + range/2, &tmp).ok()); EXPECT_EQ(range3_node1, tmp); EXPECT_TRUE(test_map.get_range(range*3 + range/2, &tmp).ok()); EXPECT_EQ(range4_node1, tmp); }
//------------------------------------------------------------------------------ // queryAirport() -- find airports within search area with minimum runway // length and airport type. //------------------------------------------------------------------------------ int AirportLoader::queryAirport(const Airport::AirportType type, const float minRwLen) { double mr2(FLT_MAX); if (mrng > 0.0f) mr2 = mrng*mrng; // compute range**2 to ref point and select all that have range less // than maxRange nql = 0; for (int i = 0; i < nrl; i++) { AirportKey* k = static_cast<AirportKey*>(rl[i]); if ( type == k->type || type == Airport::ANY ) { k->rng2 = range2(k->lat,k->lon); if (k->rng2 < mr2) { if ( chkRwLen( k, minRwLen ) ) { ql[nql++] = k; } } } } // sort and limit by range rangeSort2(); // limit number of result records if (qlimit > 0 && nql > qlimit) nql = qlimit; return nql; }
//------------------------------------------------------------------------------ // queryByFreq() -- find all airports within search area with 'freq' frequency // ILS components. //------------------------------------------------------------------------------ int AirportLoader::queryByFreq(const float freq) { double mr2(FLT_MAX); if (mrng > 0.0f) mr2 = mrng*mrng; // compute range**2 to ref point and select all that have range less // than maxRange nql = 0; for (int i = 0; i < nrl; i++) { Key* k = rl[i]; k->rng2 = range2(k->lat,k->lon); if (k->rng2 < mr2) { if ( chkIlsFreq(static_cast<AirportKey*>(k), freq ) ) { ql[nql++] = k; } } } // sort and limit by range rangeSort2(); // limit number of result records if (qlimit > 0 && nql > qlimit) nql = qlimit; return nql; }
// Driver code int main() { int i; //For really large numbers for (; (i=range2(1, 5));) printf("control at main :%d\n", i); return 0; }
TEST_F(SimplifiedBackwardsTextIteratorTest, characterAt) { const char* bodyContent = "<a id=host><b id=one>one</b> not appeared <b id=two>two</b></a>"; const char* shadowContent = "three <content select=#two></content> <content select=#one></content> " "zero"; setBodyContent(bodyContent); setShadowContent(shadowContent, "host"); Element* host = document().getElementById("host"); EphemeralRangeTemplate<EditingStrategy> range1( EphemeralRangeTemplate<EditingStrategy>::rangeOfContents(*host)); SimplifiedBackwardsTextIteratorAlgorithm<EditingStrategy> backIter1( range1.startPosition(), range1.endPosition()); const char* message1 = "|backIter1| should emit 'one' and 'two' in reverse order."; EXPECT_EQ('o', backIter1.characterAt(0)) << message1; EXPECT_EQ('w', backIter1.characterAt(1)) << message1; EXPECT_EQ('t', backIter1.characterAt(2)) << message1; backIter1.advance(); EXPECT_EQ('e', backIter1.characterAt(0)) << message1; EXPECT_EQ('n', backIter1.characterAt(1)) << message1; EXPECT_EQ('o', backIter1.characterAt(2)) << message1; EphemeralRangeTemplate<EditingInFlatTreeStrategy> range2( EphemeralRangeTemplate<EditingInFlatTreeStrategy>::rangeOfContents( *host)); SimplifiedBackwardsTextIteratorAlgorithm<EditingInFlatTreeStrategy> backIter2( range2.startPosition(), range2.endPosition()); const char* message2 = "|backIter2| should emit 'three ', 'two', ' ', 'one' and ' zero' in " "reverse order."; EXPECT_EQ('o', backIter2.characterAt(0)) << message2; EXPECT_EQ('r', backIter2.characterAt(1)) << message2; EXPECT_EQ('e', backIter2.characterAt(2)) << message2; EXPECT_EQ('z', backIter2.characterAt(3)) << message2; EXPECT_EQ(' ', backIter2.characterAt(4)) << message2; backIter2.advance(); EXPECT_EQ('e', backIter2.characterAt(0)) << message2; EXPECT_EQ('n', backIter2.characterAt(1)) << message2; EXPECT_EQ('o', backIter2.characterAt(2)) << message2; backIter2.advance(); EXPECT_EQ(' ', backIter2.characterAt(0)) << message2; backIter2.advance(); EXPECT_EQ('o', backIter2.characterAt(0)) << message2; EXPECT_EQ('w', backIter2.characterAt(1)) << message2; EXPECT_EQ('t', backIter2.characterAt(2)) << message2; backIter2.advance(); EXPECT_EQ(' ', backIter2.characterAt(0)) << message2; EXPECT_EQ('e', backIter2.characterAt(1)) << message2; EXPECT_EQ('e', backIter2.characterAt(2)) << message2; EXPECT_EQ('r', backIter2.characterAt(3)) << message2; EXPECT_EQ('h', backIter2.characterAt(4)) << message2; EXPECT_EQ('t', backIter2.characterAt(5)) << message2; }
// rangeSort: first compute range and then uses rangeSort2() to sort. int Database::rangeSort() { // compute ranges for (int i = 0; i < nql; i++) { Key* k = ql[i]; k->rng2 = range2(k->lat,k->lon); } return rangeSort2(); }
void ofApp::setup() { ofxNet::IPAddressRange range0; ofxNet::IPAddressRange range1(Poco::Net::IPAddress("192.168.0.1")); ofxNet::IPAddressRange range2(Poco::Net::IPAddress("192.168.0.33"), 23); ofxNet::IPAddressRange range3("2001:0db8:85a3::8a2e:0370:7334/64"); ofxNet::IPAddressRange range4("192.168.5.219/28"); ofxNet::IPAddressRange range5("2001:0db8:85a3::8a2e:0370:7334"); ofxNet::IPAddressRange range6("0.0.0.0/31"); std::cout << toString(range0); std::cout << "-----" << std::endl; std::cout << toString(range1); std::cout << "-----" << std::endl; std::cout << toString(range2); std::cout << "-----" << std::endl; std::cout << toString(range3); std::cout << "-----" << std::endl; std::cout << toString(range4); std::cout << "-----" << std::endl; std::cout << toString(range5); std::cout << "-----" << std::endl; Poco::Net::IPAddress test0("192.168.0.1"); Poco::Net::IPAddress test1("2001:0db8:85a3::8a2e:0370:7334"); Poco::Net::IPAddress test2("127.0.0.2"); Poco::Net::IPAddress test3("10.10.10.2"); Poco::Net::IPAddress test4("::FFFF"); Poco::Net::IPAddress test5("0.0.0.1"); std::cout << toString(range0, test0) << std::endl; std::cout << toString(range0, test1) << std::endl; std::cout << toString(range0, test2) << std::endl; std::cout << toString(range0, test3) << std::endl; std::cout << toString(range0, test4) << std::endl; std::cout << toString(range0, test4) << std::endl; std::cout << toString(range0, test5) << std::endl; std::cout << toString(range6, test5) << std::endl; ofxNet::IPAddressRange a("192.168.5.219/28"); ofxNet::IPAddressRange b("192.168.5.219/27"); std::cout << toString(a, b) << std::endl; std::cout << toString(b, a) << std::endl; }
void test3(){ SimplePrng p; int i; Int v; double d1; double *ptr1, *ptr2; int inrange = 0; Int range1(5000); Int range2(9000); Int maxv(-1); int res1, res2; Int tmpint; for (int j=1; j < TEST3_NOPS; ++j){ // insert elements for (i = 0; i < TEST3_NINSERT; ++i){ v = Int(p.next() % TEST3_RANGE); if (maxv.val < v.val) maxv = v; if (range1.val <= v.val && v.val <= range2.val) ++inrange; // count number to be deleted test3_sl.insert(v, (double)v.val); //test3_sl.insert(&v, new double(v)); } // copy skiplist SkipList<Int,double> sl2(test3_sl); Int todel; int n1, n2; // delete elements for (i = 0; i < TEST3_NDELETE; ++i){ todel = Int(p.next() % TEST3_RANGE); n1 = 0; while (!test3_sl.lookupRemove(todel,0, d1)){ assert((int)d1 == todel.val); ++n1; } n2 = sl2.delRange(todel, 1, todel, 1, 0, 0); assert(n1 == n2); } // check elements for (i=0; i < TEST3_RANGE; ++i){ tmpint.val = i; res1 = test3_sl.lookup(tmpint, ptr1); res2 = sl2.lookup(tmpint, ptr2); assert (res1==res2); if (res1==0) assert(*ptr1==*ptr2); } SkipListNode<Int,double> *it1, *it2; it1 = test3_sl.getFirst(); it2 = sl2.getFirst(); while (it1 != test3_sl.getLast()){ assert(it2 != test3_sl.getLast()); assert(it1->key.val == it2->key.val); assert(it1->value == it2->value); it1 = test3_sl.getNext(it1); it2 = test3_sl.getNext(it2); } assert(it2 == sl2.getLast()); // clear lists test3_sl.clear(0, 0); sl2.clear(0, 0); } }
void diffChange(LatexDocument *doc,int ln,int col,bool theirs){ LatexEditorView *edView=doc->getEditorView(); QDocumentCursor cursor(doc); cursor.moveTo(ln,col); QList<int> fids; fids<<edView->deleteFormat<<edView->insertFormat<<edView->replaceFormat; foreach(int fid,fids){ QFormatRange fr; if (cursor.hasSelection()) fr= cursor.line().getOverlayAt((cursor.columnNumber()+cursor.anchorColumnNumber()) / 2,fid); else fr = cursor.line().getOverlayAt(cursor.columnNumber(),fid); if (fr.length>0 ) { QDocumentCursor range=diffSearchBoundaries(doc,ln,col,fid); cursor.moveTo(range.lineNumber(),range.columnNumber()); QVariant var=cursor.line().getCookie(QDocumentLine::DIFF_LIST_COOCKIE); if(var.isValid()){ DiffList diffList=var.value<DiffList>(); //QString word=cursor.line().text().mid(fr.offset,fr.length); DiffOp op; QList<DiffOp>::iterator i; for (i = diffList.begin(); i != diffList.end(); ++i){ op=*i; if(op.start<=cursor.columnNumber() && op.start+op.length>=cursor.columnNumber()){ break; } } QStringList splitText; if(i!=diffList.end()){ QString txt; QString altText; int ln2; QDocumentCursor range2(doc); if(theirs){ switch(op.type){ case DiffOp::Delete: range.beginBoundary(ln2,col); range.endBoundary(ln,col); if(ln2-ln==0){ range2=diffSearchBoundaries(doc,ln,col,edView->insertFormat); diffChangeOpType(range2,DiffOp::Inserted); } range.removeSelectedText(); diffList.erase(i); cursor.line().setCookie(QDocumentLine::DIFF_LIST_COOCKIE,QVariant::fromValue<DiffList>(diffList)); break; case DiffOp::Insert: //op.type=DiffOp::Inserted; //*i=op; range.endBoundary(ln,col); range.beginBoundary(ln2,col); diffChangeOpType(range,DiffOp::Inserted); if((ln2-ln==0)&&(col>0)){ range2=diffSearchBoundaries(doc,ln2,col-1,edView->deleteFormat); range2.removeSelectedText(); diffChangeOpType(range2,DiffOp::Deleted); } break; case DiffOp::Replace: altText=diffCollectText(range); txt=range.selectedText(); range.removeSelectedText(); range.insertText(altText); op.type=DiffOp::Replaced; op.text=txt; splitText=txt.split("\n"); op.length=splitText.first().length(); *i=op; cursor.line().setCookie(QDocumentLine::DIFF_LIST_COOCKIE,QVariant::fromValue<DiffList>(diffList)); break; default: ; } // end theirs }else{ switch(op.type){ case DiffOp::Delete: //op.type=DiffOp::NotDeleted; //*i=op; range.beginBoundary(ln2,col); range.endBoundary(ln,col); if(ln2-ln==0){ range2=diffSearchBoundaries(doc,ln,col,edView->insertFormat); range2.removeSelectedText(); } diffChangeOpType(range,DiffOp::NotDeleted); break; case DiffOp::Insert: range.endBoundary(ln,col); range.beginBoundary(ln2,col); if((ln2-ln==0)&&(col>0)){ range2=diffSearchBoundaries(doc,ln2,col-1,edView->deleteFormat); diffChangeOpType(range2,DiffOp::NotDeleted); } range.removeSelectedText(); diffList.erase(i); cursor.line().setCookie(QDocumentLine::DIFF_LIST_COOCKIE,QVariant::fromValue<DiffList>(diffList)); if(range.line().text().isEmpty()) range.eraseLine(); //if(removeLine) // cursor.deletePreviousChar(); break; case DiffOp::Replace: //op.type=DiffOp::NotReplaced; //*i=op; diffChangeOpType(range,DiffOp::NotReplaced); break; default: ; } } // end mine } } return; } // if fr.length>0 }
/* ChapelRange.chpl:140 */ static void _build_range2(int64_t bound, _ref_range_int64_t_boundedLow_F _retArg, int64_t _ln, c_string _fn) { range_int64_t_boundedLow_F wrap_call_tmp; wrap_call_tmp = range2(bound, bound, INT64(1), INT64(0), false, _ln, _fn); *(_retArg) = wrap_call_tmp; return; }
TEST_F(SimplifiedBackwardsTextIteratorTest, copyTextTo) { const char* bodyContent = "<a id=host><b id=one>one</b> not appeared <b id=two>two</b></a>"; const char* shadowContent = "three <content select=#two></content> <content select=#one></content> " "zero"; setBodyContent(bodyContent); setShadowContent(shadowContent, "host"); Element* host = document().getElementById("host"); const char* message = "|backIter%d| should have emitted '%s' in reverse order."; EphemeralRangeTemplate<EditingStrategy> range1( EphemeralRangeTemplate<EditingStrategy>::rangeOfContents(*host)); SimplifiedBackwardsTextIteratorAlgorithm<EditingStrategy> backIter1( range1.startPosition(), range1.endPosition()); BackwardsTextBuffer output1; backIter1.copyTextTo(&output1, 0, 2); EXPECT_EQ("wo", String(output1.data(), output1.size())) << String::format(message, 1, "wo").utf8().data(); backIter1.copyTextTo(&output1, 2, 1); EXPECT_EQ("two", String(output1.data(), output1.size())) << String::format(message, 1, "two").utf8().data(); backIter1.advance(); backIter1.copyTextTo(&output1, 0, 1); EXPECT_EQ("etwo", String(output1.data(), output1.size())) << String::format(message, 1, "etwo").utf8().data(); backIter1.copyTextTo(&output1, 1, 2); EXPECT_EQ("onetwo", String(output1.data(), output1.size())) << String::format(message, 1, "onetwo").utf8().data(); EphemeralRangeTemplate<EditingInFlatTreeStrategy> range2( EphemeralRangeTemplate<EditingInFlatTreeStrategy>::rangeOfContents( *host)); SimplifiedBackwardsTextIteratorAlgorithm<EditingInFlatTreeStrategy> backIter2( range2.startPosition(), range2.endPosition()); BackwardsTextBuffer output2; backIter2.copyTextTo(&output2, 0, 2); EXPECT_EQ("ro", String(output2.data(), output2.size())) << String::format(message, 2, "ro").utf8().data(); backIter2.copyTextTo(&output2, 2, 3); EXPECT_EQ(" zero", String(output2.data(), output2.size())) << String::format(message, 2, " zero").utf8().data(); backIter2.advance(); backIter2.copyTextTo(&output2, 0, 1); EXPECT_EQ("e zero", String(output2.data(), output2.size())) << String::format(message, 2, "e zero").utf8().data(); backIter2.copyTextTo(&output2, 1, 2); EXPECT_EQ("one zero", String(output2.data(), output2.size())) << String::format(message, 2, "one zero").utf8().data(); backIter2.advance(); backIter2.copyTextTo(&output2, 0, 1); EXPECT_EQ(" one zero", String(output2.data(), output2.size())) << String::format(message, 2, " one zero").utf8().data(); backIter2.advance(); backIter2.copyTextTo(&output2, 0, 2); EXPECT_EQ("wo one zero", String(output2.data(), output2.size())) << String::format(message, 2, "wo one zero").utf8().data(); backIter2.copyTextTo(&output2, 2, 1); EXPECT_EQ("two one zero", String(output2.data(), output2.size())) << String::format(message, 2, "two one zero").utf8().data(); backIter2.advance(); backIter2.copyTextTo(&output2, 0, 3); EXPECT_EQ("ee two one zero", String(output2.data(), output2.size())) << String::format(message, 2, "ee two one zero").utf8().data(); backIter2.copyTextTo(&output2, 3, 3); EXPECT_EQ("three two one zero", String(output2.data(), output2.size())) << String::format(message, 2, "three two one zero").utf8().data(); }