public void testPrimes(int n) { TestPrimes t = new TestPrimes(factory); long start = DateTime.Now.Ticks; ATermList l = t.getPrimes(n); long end = DateTime.Now.Ticks; Console.Out.WriteLine("primes(" + n + ") in " + (end - start) + " ms"); //Console.Out.WriteLine(" primes(" + n + ") = " + l); Console.Out.WriteLine("#primes(" + n + ") = " + l.getLength()); Console.Out.WriteLine(factory); }
public override bool equivalent(SharedObject obj) { if (base.equivalent(obj)) { ATermList peer = (ATermList)obj; if (peer.getLength() == length) { return(peer.getFirst().Equals(first) && peer.getNext().Equals(next)); } } return(false); }
/** * init is used internally by the PureFactory to initialize a prototype of * an ATermList without using the new operator all the time * */ public virtual void init(int hashCode, ATermList annos, ATerm first, ATermList next) { base.init(hashCode, annos); this.first = first; this.next = next; if (first == null && next == null) { this.length = 0; } else { this.length = 1 + next.getLength(); } }
public virtual ATermAppl makeApplList(AFun fun, ATermList list, ATermList annos) { ATerm[] arg_array; arg_array = new ATerm[list.getLength()]; int i = 0; while (!list.isEmpty()) { arg_array[i++] = list.getFirst(); list = list.getNext(); } return(makeAppl(fun, arg_array, annos)); }
/** * Filter multiples of n. */ private ATermList filterMultiples(int n, ATermList numbers) { int nr, len = numbers.getLength(); for(int i=0; i<len; i++) { ATermInt el = (ATermInt)numbers.elementAt(i); nr = el.getInt(); if(nr % n == 0) { len--; numbers = numbers.removeElementAt(i); } } return numbers; }
/** * Filter multiples of n. */ private ATermList filterMultiples(int n, ATermList numbers) { int nr, len = numbers.getLength(); for (int i = 0; i < len; i++) { ATermInt el = (ATermInt)numbers.elementAt(i); nr = el.getInt(); if (nr % n == 0) { len--; numbers = numbers.removeElementAt(i); } } return(numbers); }
public virtual void initHashCode(ATermList annos, ATerm first, ATermList next) { this.first = first; this.next = next; this.internSetAnnotations(annos); this.setHashCode(this.hashFunction()); //super.init(hashCode, annos); if (first == null && next == null) { this.length = 0; } else { this.length = 1 + next.getLength(); } }
public virtual ATermAppl makeApplList(AFun fun, ATermList list, ATermList annos) { ATerm[] arg_array; arg_array = new ATerm[list.getLength()]; int i = 0; while (!list.isEmpty()) { arg_array[i++] = list.getFirst(); list = list.getNext(); } return makeAppl(fun, arg_array, annos); }
public override ATerm make(ArrayList args) { PureFactory factory = getPureFactory(); ATermAppl appl; AFun fun; string name; appl = (ATermAppl)type; fun = appl.getAFun(); name = fun.getName(); if (!fun.isQuoted()) { if (fun.getArity() == 0) { if (name.Equals("term")) { ATerm t = (ATerm)args[0]; args.RemoveAt(0); return(t); } else if (name.Equals("list")) { ATermList l = (ATermList)args[0]; args.RemoveAt(0); return(l); } else if (name.Equals("bool")) { bool b = (bool)args[0]; args.RemoveAt(0); return(factory.makeAppl(factory.makeAFun(b.ToString(), 0, false))); } else if (name.Equals("int")) { int i = (int)args[0]; args.RemoveAt(0); return(factory.makeInt(i)); } else if (name.Equals("real")) { double d = (double)args[0]; args.RemoveAt(0); return(factory.makeReal(d)); } else if (name.Equals("placeholder")) { ATerm atype = (ATerm)args[0]; args.RemoveAt(0); return(factory.makePlaceholder(atype)); } else if (name.Equals("str")) { string str = (string)args[0]; args.RemoveAt(0); return(factory.makeAppl(factory.makeAFun(str, 0, true))); } else if (name.Equals("id")) { string str = (string)args[0]; args.RemoveAt(0); return(factory.makeAppl(factory.makeAFun(str, 0, false))); } else if (name.Equals("fun")) { string str = (string)args[0]; args.RemoveAt(0); return(factory.makeAppl(factory.makeAFun(str, 0, false))); } } if (name.Equals("appl")) { ATermList oldargs = appl.getArguments(); string newname = (string)args[0]; args.RemoveAt(0); ATermList newargs = (ATermList)oldargs.make(args); AFun newfun = factory.makeAFun(newname, newargs.getLength(), false); return(factory.makeApplList(newfun, newargs)); } } throw new Exception("illegal pattern: " + this); }