/** * Like updateKey but allow multiple items with same key */ static Tree addKey(Tree pl, Tree key, Tree val) { if(isNil(pl)) return cons(cons(key, val), nil); if(isBefore(key, left(hd(pl)))) return cons(cons(key, val), pl); return cons(hd(pl), addKey(tl(pl), key, val)); }
Tree rconcat(Tree l, Tree q) { while(isList(l)) { q = cons(hd(l), q); l = tl(l); } return q; }
void exchange(tree_set_t& other, const Synchronized& sync) { if (this == &other) { return; } // ESSENTIAL: deadlock in such case m_arena.exchange(other.m_arena, sync); m_skeleton.exchange(other.m_skeleton, sync); lock_scope_t<self_type, Synchronized> tl(this); lock_scope_t<self_type, Synchronized> ol(&other); unfact::exchange(m_compare, other.m_compare); }
void drawX(Mat img, Rect rect, Scalar color, int thickness) { Point tl(rect.x, rect.y); Point tr(rect.x + rect.width, rect.y); Point bl(rect.x, rect.y + rect.height); Point br(rect.x + rect.width, rect.y + rect.height); line(img, tl, br, color, thickness); line(img, bl, tr, color, thickness); }
static Bool local isParentOf(Class parent, Class child) { List supers; for(supers=cclass(child).supers; nonNull(supers); supers=tl(supers)) { if (getHead(hd(supers)) == parent) { return TRUE; } } return FALSE; }
static Uint8 state_of_value(value l) { Uint8 state = 0; while(is_not_nil(l)){ if (Is_long(hd(l))) state |= 1 << Int_val(hd(l)); l = tl(l); } return state; }
void _ThreadSort(vector<int> *arr, int start, int end, int depth) { //Find middle of array int mid = (end + start) / 2; if(depth > _ThreadSortRecurDepth) { //Break array into four segments by finding secondary midpoints int midl = (mid + start) / 2; int midr = (mid + end) / 2; //Create thread to mergesort each of those four segments thread tl(_mergeSort, arr, start, midl); thread tlm (_mergeSort, arr, midl + 1, mid); thread trm (_mergeSort, arr, mid + 1, midr); thread tr(_mergeSort, arr, midr + 1, end); //Wait for each thread to finish tl.join(); tr.join(); tlm.join(); trm.join(); //merge left halves and right halves asynchronously thread mergeTl(merge, arr, start, midl, mid); thread mergeTr(merge, arr, mid + 1, midr, end); mergeTl.join(); mergeTr.join(); //finally merge left with right merge(arr, start, mid, end); } else { //Recursive threadsort on each half of the array. thread tl(_ThreadSort, arr, start, mid, depth + 1); thread tr(_ThreadSort, arr, mid + 1, end, depth + 1); tl.join(); tr.join(); merge(arr, start, mid, end); } }
bool Face::matches(Face &other, int threshold) { cv::Point tl(m_center.x - threshold, m_center.y - threshold); cv::Point br(m_center.x + threshold, m_center.y + threshold); cv::Point oc(other.center()); if (oc.x >= tl.x && oc.x <= br.x && oc.y >= tl.y && oc.y <= br.y) { return(true); } else { return(false); } }
// compares substrings of \a l and \a r bool FileSpec::FileSpecSort::operator() (const std::string& l, const std::string& r) const { // if there are directories, don't include them in the comparison std::string tl(l, offset + l.find_last_of(slash) + 1, length); std::string tr(r, offset + r.find_last_of(slash) + 1, length); if (sortBy == ascending) return tl < tr; else return tl > tr; }
// crée une chaine de dossiers correspondant à path et contenant in fine elem Tree makeSubFolderChain(Tree path, Tree elem) { if(isNil(path)) { return elem; } else { return putFolder(uiFolder(hd(path)), makeSubFolderChain(tl(path), elem)); } }
/** * @brief Get the directory of a user interface element. * * Convert the input reversed path tree into a string. * The name of the UI is stripped (the head of the path tree), * the rest of the tree is a list of pointed pairs, where the names * are contained by the tail of these pointed pairs. * Metadatas (begining by '[') are stripped. * * @param[in] pathname The path tree to convert. * @return <string> A directory-like string. */ string DocCompiler::getUIDir(Tree pathname) { // cerr << "Documentator : getUIDir : print(pathname, stdout) = "; print(pathname, stdout); cerr << endl; string s; Tree dir = reverse(tl(pathname)); while(!isNil(dir)) { string tmp = tree2str(tl(hd(dir))); if((tmp[0] != '[') && (!tmp.empty())) { s += tmp + '/'; } dir = tl(dir); } return s; }
static int init_flag_val(value flag_list) { int flag = 0; value l = flag_list; while (is_not_nil(l)){ flag |= Init_flag_val(hd(l)); l = tl(l); } return flag; }
Tree buildBoxAppl(Tree fun, Tree revarglist) { if(isNil(revarglist)) { return fun; } else { return boxAppl(buildBoxAppl(fun, tl(revarglist)), hd(revarglist)); } }
static bool boxlistOutputs(Tree boxlist, int* outputs) { int ins, outs; *outputs = 0; while (!isNil(boxlist) && getBoxType(hd(boxlist), &ins, &outs)) { *outputs += outs; boxlist = tl(boxlist); } return isNil(boxlist); }
Tree buildBoxAbstr(Tree largs, Tree body) { if(isNil(largs)) { return body; } else { return buildBoxAbstr(tl(largs), boxAbstr(hd(largs), body)); } }
uintptr_t* REG_POLY_FUN_HDR(cons_pair_of_strings, Region rl, Region rp, Region s1, Region s2, char* str1, char* str2, uintptr_t* list) { uintptr_t *lpair, *pair; allocPairML(rl, lpair); allocPairML(rp, pair); first(pair) = (uintptr_t) REG_POLY_CALL(convertStringToML, s1, str1); second(pair) = (uintptr_t) REG_POLY_CALL(convertStringToML, s2, str2); hd(lpair) = (uintptr_t)pair; tl(lpair) = (uintptr_t)list; return lpair; }
ostream& ppsig::printlist (ostream& fout, Tree largs) const { string sep = ""; fout << '('; while (!isNil(largs)) { fout << sep << ppsig(hd(largs), fEnv); sep = ", "; largs = tl(largs); } fout << ')'; return fout; }
Tree list2set(Tree l) { Tree s = nil; while(isList(l)) { s = addElement(hd(l), s); l = tl(l); } return s; }
static Tree rmap(tfun f, Tree l) { Tree r = nil; while(isList(l)) { r = cons(f(hd(l)), r); l = tl(l); } return r; }
Tree reverse(Tree l) { Tree r = nil; while(isList(l)) { r = cons(hd(l), r); l = tl(l); } return r; }
GoogleTranslate::GoogleTranslate(DictionaryModel *dict, QObject *parent) : JsonTranslationService(parent) , m_dict(dict) { m_sslConfiguration = QSslConfiguration::defaultConfiguration(); QList<QSslCertificate> cacerts(m_sslConfiguration.caCertificates()); cacerts << loadSslCertificates(QStringList() << QLatin1String("://cacertificates/geotrust.ca.pem") << QLatin1String("://cacertificates/equifax.ca.pem")); m_sslConfiguration.setCaCertificates(cacerts); // TODO: Download actual list from // https://translate.googleapis.com/translate_a/l?client=gtx&hl=en QFile f(QLatin1String("://langs/google.json")); if (f.open(QFile::Text | QFile::ReadOnly)) { QVariant data = parseJson(f.readAll()); f.close(); if (data.isValid()) { QVariantMapIterator sl(data.toMap().value("sl").toMap()); while (sl.hasNext()) { sl.next(); const QString code = sl.key(); const QString name = sl.value().toString(); Language lang(code, name); m_sourceLanguages << lang; m_langCodeToName.insert(code, name); } QVariantMapIterator tl(data.toMap().value("tl").toMap()); while (tl.hasNext()) { tl.next(); const QString code = tl.key(); const QString name = tl.value().toString(); Language lang(code, name); m_targetLanguages << lang; m_langCodeToName.insert(code, name); } } } qSort(m_sourceLanguages); qSort(m_targetLanguages); if (m_langCodeToName.contains("auto")) m_defaultLanguagePair.first = Language("auto", m_langCodeToName.value("auto")); else m_defaultLanguagePair.first = m_sourceLanguages.first(); if (m_langCodeToName.contains("en")) m_defaultLanguagePair.second = Language("en", m_langCodeToName.value("en")); else m_defaultLanguagePair.second = m_targetLanguages.first(); }
int len(Tree l) { int n = 0; while(isList(l)) { l = tl(l); n++; } return n; }
void ScalarCompiler::sharingAnalysis(Tree t) { fSharingKey = shprkey(t); if (isList(t)) { while (isList(t)) { sharingAnnotation(kSamp, hd(t)); t = tl(t); } } else { sharingAnnotation(kSamp, t); } }
static void printRule(ostream& fout, Tree rule) { Tree lhs = left(rule); Tree rhs = right(rule); char sep = '('; while (!isNil(lhs)) { fout << sep << boxpp(hd(lhs)); sep=','; lhs=tl(lhs); } fout << ") => " << boxpp(rhs) << "; "; }
void Animation::updateBBox(const Vec &size, const Vec &alignPoint) { Vec tl(alignPoint); Vec br(size); tl.mult(-1.0f); br.sub(alignPoint); Rect nr(tl, br); m_boundBox.merge(nr); }
// private QRectF QgsMapCanvasItem::toCanvasCoordinates( const QRectF& rect ) { QPointF tl( toCanvasCoordinates( rect.topLeft() ) ); QPointF bl( toCanvasCoordinates( rect.bottomLeft() ) ); QPointF br( toCanvasCoordinates( rect.bottomRight() ) ); QPointF tr( toCanvasCoordinates( rect.topRight() ) ); double xmin = std::min( tl.x(), std::min( bl.x(), std::min( br.x(), tr.x() ) ) ); double ymin = std::min( tl.y(), std::min( bl.y(), std::min( br.y(), tr.y() ) ) ); double xmax = std::max( tl.x(), std::max( bl.x(), std::max( br.x(), tr.x() ) ) ); double ymax = std::max( tl.y(), std::max( bl.y(), std::max( br.y(), tr.y() ) ) ); return QRectF( QPointF( xmin, ymin ), QPointF( xmax, ymax ) ); }
/** * Remove fake root folder if not needed (that is if the UI * is completely enclosed in one folder) */ Tree Compiler::prepareUserInterfaceTree(Tree t) { Tree root, elems; if(isUiFolder(t, root, elems) && isList(elems) && isNil(tl(elems))) { Tree folder = right(hd(elems)); return (isUiFolder(folder)) ? folder : t; } return t; }
size_t RegionList::length() { size_t len = 0; HeapRegion* cur = hd(); DEBUG_ONLY(HeapRegion* last = NULL); while (cur != NULL) { len++; DEBUG_ONLY(last = cur); cur = get_next(cur); } assert(last == tl(), "Invariant"); return len; }
void printSigTypeList (Tree l) { char sep = '('; do { putchar(sep); sep = ','; printSigType(hd(l)); l = tl(l); } while (isList(l)); putchar(')'); }
void RegionList::delete_after(HeapRegion* r) { assert(well_formed(), "Precondition"); HeapRegion* next = get_next(r); assert(r != NULL, "Precondition"); HeapRegion* next_tl = get_next(next); set_next(r, next_tl); dec_sz(); if (next == tl()) { assert(next_tl == NULL, "Inv"); _tl = r; } assert(well_formed(), "Inv"); }