Ejemplo n.º 1
0
static bool findKey(Tree pl, Tree key, Tree& val)
{
  if(isNil(pl))
    return false;

  if(left(hd(pl)) == key)
  {
    val = right(hd(pl));
    return true;
  }

  if(isBefore(left(hd(pl)), key))
    return findKey(tl(pl), key, val);

  return false;
}
Ejemplo n.º 2
0
void
hyperplot(unsigned int N, unsigned int K, unsigned int n)
{
  std::default_random_engine re; // the default engine
  __gnu_cxx::hypergeometric_distribution<> hd(N, K, n);

  auto gen = std::bind(hd, re);

  auto num = hd.max() - hd.min() + 1;
  histogram<std::size_t> bin(num, hd.min(), hd.max() + 1);

  const std::size_t per = 1000;

  //for (std::size_t i = 0; i < 1000 * per; ++i)
  //  std::cout << gen() << '\n';

  for (std::size_t i = 0; i < 200 * per; ++i)
    bin << gen() + 0.5;

  for (std::size_t i = 1; i <= bin.size(); ++i)
  {
    std::cout << bin.value(i) << '\t';
    for (std::size_t j = 0; j < bin[i]; j += per)
      std::cout << '*';
    std::cout << '\n';
  }
}
Ejemplo n.º 3
0
static bool printlist (Tree l, FILE* out)
{
	if (isList(l)) {
		
		char sep = '(';
		
		do {
			fputc(sep, out); sep = ',';
			print(hd(l));
			l = tl(l);
		} while (isList(l));
		
		if (! isNil(l)) {
			fprintf(out, " . ");
			print(l, out);
		}
		
		fputc(')', out);
		return true;
		
	} else if (isNil(l)) {
		
		fprintf(out, "nil");
		return true;
		
	} else {
		
		return false;
	}
}
Ejemplo n.º 4
0
Archivo: dbdump.C Proyecto: Amit-DU/dht
// {{{ getexpire: Secondary key extractor for metadata
static int
getexpire (DB *sdb, const DBT *pkey, const DBT *pdata, DBT *skey)
{
  u_int32_t *expire = (u_int32_t *) malloc(sizeof(u_int32_t));
  // this flag should mean that berkeley db will free this memory when it's
  // done with it.
  skey->flags = DB_DBT_APPMALLOC;
  skey->data = expire;
  skey->size = sizeof (*expire);

  if (pkey->size != sha1::hashsize)
  {
    *expire = 0;
    return 0;
  }

  adb_metadata_t md;
  if (!buf2xdr (md, pdata->data, pdata->size)) {
    hexdump hd (pdata->data, pdata->size);
    warn << "getexpire: unable to unmarshal pdata.\n" << hd << "\n";
    return -1;
  }
  // Ensure big-endian for proper BDB sorting.
  *expire = htonl (md.expiration);
  return 0;
}
Ejemplo n.º 5
0
void CloudBox::loadPressureGridFromFile(std::string path){
    TiXmlDocument doc(path.c_str());
    if (!doc.LoadFile()) {std::cout << "Impossible to load " << path << std::endl; return;}

    TiXmlHandle hd(&doc);

    // We get the arts element
    TiXmlElement * arts = hd.FirstChildElement().Element();
    if (!arts){
        std::cerr << "Impossible to find the arts tag." << std::endl;
        return;
    }

    // We get the SingleScatteringData element
    TiXmlElement * vector = arts->FirstChildElement();
    if(!vector) {
        std::cerr << "Impossible to find the pressure vector." << std::endl;
        return;
    }

    vector->QueryIntAttribute("nelem", &m_pressureGridSize);
    if (m_pressureGrid) {std::cout << "delete of pressureGrid" << std::endl; delete[] m_pressureGrid;}
    m_pressureGrid = new Numeric[m_pressureGridSize];
    std::stringstream ss;
    ss << vector->GetText();

    for (int i = 0; i < m_pressureGridSize; ++i){
        ss >> m_pressureGrid[i];
    }

}
Ejemplo n.º 6
0
void CloudBox::loadAltitudeGridFromFile(std::string path){
    TiXmlDocument doc(path.c_str());
    if (!doc.LoadFile()) {std::cout << "Impossible to load " << path << std::endl; return;}

    TiXmlHandle hd(&doc);

    // We get the arts element
    TiXmlElement * arts = hd.FirstChildElement().Element();
    if (!arts){
        std::cerr << "Impossible to find the arts tag." << std::endl;
        return;
    }

    // We get the SingleScatteringData element
    TiXmlElement * vector = arts->FirstChildElement();
    if(!vector) {
        std::cerr << "Impossible to find the altitude vector." << std::endl;
        return;
    }

    int nelem;
    vector->QueryIntAttribute("npages", &nelem);
    if (nelem != m_pressureGridSize){std::cerr << "Altitude data not coherent with pressure data." << std::endl; return;}
    if (m_altitudeGrid) {delete[] m_altitudeGrid;}
    m_altitudeGrid = new Numeric[m_pressureGridSize];
    std::stringstream ss;
    ss << vector->GetText();

    for (int i = 0; i < m_pressureGridSize; ++i){
        ss >> m_altitudeGrid[i];
    }

    updateBoundariesLayerId();

}
Ejemplo n.º 7
0
static Void local drawClassRelations(HDC hDC)
{
  Class cls;
  for(cls=CLASSMIN; cls<classMax(); cls++) {
    List supers;
    for(supers=cclass(cls).supers; nonNull(supers); supers=tl(supers)) {
      Class parent = getHead(hd(supers));
      if (isClass(parent)) {
	if (parent == cls) {     /* child of itself - draw an arc */
	  Class source = findClassInNodes(cls);
	  Arc(hDC, Nodes[source].Pos.right-5,  Nodes[source].Pos.bottom-5,
		   Nodes[source].Pos.right+15, Nodes[source].Pos.bottom+20,
		   Nodes[source].Pos.right-5,  Nodes[source].Pos.bottom-5,
		   Nodes[source].Pos.right-4,  Nodes[source].Pos.bottom-4);
	} else { 	               /* Join the two classes with a line */
	  Class source = findClassInNodes(parent);
	  Class target = findClassInNodes(cls);

	  INT sx = Nodes[source].Pos.right + 4;
	  INT sy = Nodes[source].Pos.top
		   + (Nodes[source].Pos.bottom - Nodes[source].Pos.top)/2;
	  INT tx = Nodes[target].Pos.left  - 4;
	  INT ty = Nodes[target].Pos.top
		   + (Nodes[target].Pos.bottom - Nodes[target].Pos.top)/2;

	  MoveToEx(hDC, sx, sy,NULL);
	  LineTo(hDC, tx, ty);
	}
      }
    }
  }
}
Ejemplo n.º 8
0
STATIC int LBA_to_CHS(ULONG LBA_address, struct CHS *chs, const ddt * pddt)
{
  /* we need the defbpb values since those are taken from the
     BIOS, not from some random boot sector, except when
     we're dealing with a floppy */

  const bpb *pbpb = hd(pddt->ddt_descflags) ? &pddt->ddt_defbpb : &pddt->ddt_bpb;
  unsigned hs = pbpb->bpb_nsecs * pbpb->bpb_nheads;
  unsigned hsrem = (unsigned)(LBA_address % hs);

  LBA_address /= hs;

  if (LBA_address > 1023ul)
  {
#ifdef DEBUG
    printf("LBA-Transfer error : cylinder %lu > 1023\n", LBA_address);
#else
    put_string("LBA-Transfer error : cylinder > 1023\n");
#endif
    return 1;
  }

  chs->Cylinder = (UWORD)LBA_address;
  chs->Head = hsrem / pbpb->bpb_nsecs;
  chs->Sector =  hsrem % pbpb->bpb_nsecs + 1;
  return 0;
}
Ejemplo n.º 9
0
void VectorCompiler::compileMultiSignal (Tree L)
{
    //contextor recursivness(0);
    L = prepare(L);     // optimize, share and annotate expression

    for (int i = 0; i < fClass->inputs(); i++) {
        fClass->addZone3(subst("$1* input$0 = &input[$0][index];", T(i), xfloat()));
    }
    for (int i = 0; i < fClass->outputs(); i++) {
        fClass->addZone3(subst("$1* output$0 = &output[$0][index];", T(i), xfloat()));
    }

    fClass->addSharedDecl("fullcount");
    fClass->addSharedDecl("input");
    fClass->addSharedDecl("output");

    for (int i = 0; isList(L); L = tl(L), i++) {
        Tree sig = hd(L);
        fClass->openLoop("count");
        fClass->addExecCode(subst("output$0[i] = $2$1;", T(i), CS(sig), xcast()));
        fClass->closeLoop(sig);
    }

    generateUserInterfaceTree(prepareUserInterfaceTree(fUIRoot));
 	generateMacroInterfaceTree("", prepareUserInterfaceTree(fUIRoot));
    if (fDescription) {
        fDescription->ui(prepareUserInterfaceTree(fUIRoot));
    }
}
Ejemplo n.º 10
0
Tree buildBoxAbstr	(Tree largs, Tree body)
{
	if (isNil(largs)) {
		return body;
	} else {
		return buildBoxAbstr(tl(largs), boxAbstr(hd(largs), body));
	}
}
Ejemplo n.º 11
0
 // 'default' has been consumed, hd() is the identifier 'xml'
 Stmt* Parser::defaultXmlNamespaceStatement()
 {
     uint32_t pos = position();
     if(hd() != T_Identifier || identValue() != compiler->SYM_xml)
         goto failure;
     eat(T_Identifier);
     if(hd() != T_Namespace)
         goto failure;
     eat(T_Namespace);
     eat(T_Assign);
     setUsesDefaultXmlNamespace();
     return ALLOC(DefaultXmlNamespaceStmt, (pos, commaExpression(0)));
 failure:
     compiler->syntaxError(pos, SYNTAXERR_EXPECT_DXNS);
     /*NOTREACHED*/
     return NULL;
 }
Ejemplo n.º 12
0
 // FIXME: don't discard the qualifier in namespace definitions
 void Parser::namespaceDefinition(int flags, Qualifier* /*qual*/)
 {
     uint32_t pos = position();
     if (!(flags & (SFLAG_Function|SFLAG_Toplevel))) // no classes yet...
         compiler->syntaxError(pos, SYNTAXERR_KWD_NOT_ALLOWED, "namespace");
     eat(T_Identifier);
     Str * name = identifier();
     if (match(T_Assign)) {
         if (hd() == T_Identifier || hd() == T_StringLiteral)
             addNamespaceBinding(name, primaryExpression());
         else
             compiler->syntaxError(pos, SYNTAXERR_ILLEGAL_NAMESPACE);
     }
     else
         addNamespaceBinding(name, NULL);
     semicolon();
 }
Ejemplo n.º 13
0
		// FIXME: don't discard the qualifier in namespace definitions
		void Parser::namespaceDefinition(int flags, Qualifier* /*qual*/)
		{
			uint32_t pos = position();
			if (!(flags & (SFLAG_Function|SFLAG_Toplevel)))	// no classes yet...
				compiler->syntaxError(pos, "'namespace' definition not allowed here");
			eat(T_Identifier);
			Str * name = identifier();
			if (match(T_Assign)) {
				if (hd() == T_Identifier || hd() == T_StringLiteral)
					addNamespaceBinding(name, primaryExpression());
				else
					compiler->syntaxError(pos, "Illegal 'namespace' definition");
			}
			else
				addNamespaceBinding(name, NULL);
			semicolon();
		}
Ejemplo n.º 14
0
/**
 * Iterate generateMacroInterfaceTree on a list of user interface elements
 */
void Compiler::generateMacroInterfaceElements(const string& pathname, Tree elements)
{
  while(!isNil(elements))
  {
    generateMacroInterfaceTree(pathname, right(hd(elements)));
    elements = tl(elements);
  }
}
Ejemplo n.º 15
0
Tree buildBoxAppl 	(Tree fun, Tree revarglist)
{
	if (isNil(revarglist)) {
		return fun;
	} else {
		return  boxAppl(buildBoxAppl(fun, tl(revarglist)), hd(revarglist));
	}
}
Ejemplo n.º 16
0
/**
 * Iterate generateUserInterfaceTree on a list of user interface elements
 */
void Compiler::generateUserInterfaceElements(Tree elements)
{
  while(!isNil(elements))
  {
    generateUserInterfaceTree(right(hd(elements)));
    elements = tl(elements);
  }
}
Ejemplo n.º 17
0
Archivo: sum.cpp Proyecto: PEZO19/CEKLA
int sum(const list L) {       
    if (L == nil) return 0;    
    else {                    
        const int X = hd(L);   
        const list T = tl(L);  
        return X + sum(T);     
    }
}
Ejemplo n.º 18
0
void RegionList::insert_before_head(HeapRegion* r) {
  assert(well_formed(), "Inv");
  set_next(r, hd());
  _hd = r;
  _sz++;
  if (tl() == NULL) _tl = r;
  assert(well_formed(), "Inv");
}
Ejemplo n.º 19
0
// 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));
	}
} 
Ejemplo n.º 20
0
B assoc (A a, list<std::pair<A, B>> l) {
  if (empty (l))
    throw not_found ();
  std::pair<A, B> p=hd (l);
  if (p.first == a)
    return p.second;
  return assoc (a, tl (l));
}
Ejemplo n.º 21
0
// makeBoxAbstr(largs,body) => \(lnames).(body)
static Tree makeBoxAbstr	(Tree largs, Tree body)
{
    if (isNil(largs)) {
        return body;
    } else {
        return boxAbstr(hd(largs), makeBoxAbstr(tl(largs),body));
    }
}
Ejemplo n.º 22
0
 Seq<CaseClause*>* Parser::caseElements()
 {
     SeqBuilder<CaseClause*> cases(allocator);
     bool hasDefault = false;
     CaseClause* last = NULL;
     
     for (;;) {
         switch (hd ()) {
             case T_RightBrace:
                 return cases.get();
                 
             case T_Default: {
                 if (hd2() != T_Colon)
                     goto just_a_statement;  // default xml namespace
                 eat(T_Default);
                 eat(T_Colon);
                 if (hasDefault)
                     compiler->syntaxError(position(), SYNTAXERR_DUPLICATE_DEFAULT);
                 hasDefault = true;
                 cases.addAtEnd(last = ALLOC(CaseClause, (0, NULL)));
                 break;
             }
                 
             case T_Case: {
                 eat(T_Case);
                 uint32_t pos = position();
                 Expr* expr = commaExpression(0);
                 eat(T_Colon);
                 cases.addAtEnd(last = ALLOC(CaseClause, (pos, expr)));
             }
             /*FALLTHROUGH*/
             just_a_statement:
             default: {
                 if (last == NULL)
                     compiler->syntaxError(position(), SYNTAXERR_EXPECT_CASE_OR_DEFAULT);
                 AvmAssert(last->stmts == NULL);
                 SeqBuilder<Stmt*> stmts(allocator);
                 while (hd() != T_RightBrace && hd() != T_Case && hd() != T_Default)
                     stmts.addAtEnd(statement());
                 last->stmts = stmts.get();
                 break;
             }
         }
     }
 }
Ejemplo n.º 23
0
/**
 * 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;
}
Ejemplo n.º 24
0
/**
 * Evaluates each pattern of the list
 */
static Tree	evalPatternList(Tree patterns, Tree env)
{
	if (isNil(patterns)) {
		return gGlobal->nil;
	} else {
		return cons(evalPattern(hd(patterns), env), 
                    evalPatternList(tl(patterns), env));
	}
}
Ejemplo n.º 25
0
Archivo: list.cpp Proyecto: EBone/Faust
Tree list2set (Tree l)
{
	Tree s = gGlobal->nil;
	while (isList(l)) {
		s = addElement(hd(l),s);
		l = tl(l);
	}
	return s;
}
Ejemplo n.º 26
0
Archivo: list.cpp Proyecto: EBone/Faust
Tree nth (Tree l, int i)
{
	while (isList(l)) {
		if (i == 0)  return hd(l);
		l = tl(l);
		i--;
	}
	return gGlobal->nil;
}
Ejemplo n.º 27
0
STATIC WORD blk_Media(rqptr rp, ddt * pddt)
{
  UNREFERENCED_PARAMETER(rp);

  if (hd(pddt->ddt_descflags))
    return S_BUSY | S_DONE;     /* Hard Drive */
  else
    return S_DONE;              /* Floppy */
}
Ejemplo n.º 28
0
static inline int Initflags_val(value initflags)
{
	int result = 0;
	while(is_not_nil(initflags)){
		result |= initflags_table[Int_val(hd(initflags))];
		initflags = tl(initflags);
	}
	return result;
}
Ejemplo n.º 29
0
// defines each symbol si of lnames as => "si = RECURSIVEBODY : select(n,i);"
static Tree makeRecProjectionsList(int n, int i, Tree lnames, Tree ldef)
{
    if (i==n) {
        return ldef;
    } else {
        Tree sel = boxSeq(gGlobal->LETRECBODY, makeSelector(n,i));
        return cons(cons(hd(lnames), sel), makeRecProjectionsList(n, i+1, tl(lnames), ldef));
    }
}
Ejemplo n.º 30
0
// def2exp transforms a list of definition (name.expression) into a list of expressions
static Tree def2exp(Tree ldef)
{
    if (isNil(ldef)) {
        return gGlobal->nil;
    } else {
        Tree def = hd(ldef);
        return cons(tl(def), def2exp(tl(ldef)));
    }
}