public virtual ATermList getPrefix() { ATermList cur, next; ArrayList elems; if (isEmpty()) { return(this); } cur = this; elems = new ArrayList(); while (true) { next = cur.getNext(); if (next.isEmpty()) { cur = ((PureFactory)getFactory()).getEmpty(); for (int i = elems.Count - 1; i >= 0; i--) { cur = cur.insert((ATerm)elems[i]); } return(cur); } else { elems.Add(cur.getFirst()); cur = cur.getNext(); } } }
public virtual void initHashCode(ATermList annos, int value) { this.value = value; this.internSetAnnotations(annos); this.setHashCode(this.hashFunction()); //super.init(hashCode, annos); }
public virtual ATerm setAnnotation(ATerm label, ATerm anno) { ATermList new_annos = annotations.dictPut(label, anno); ATerm result = setAnnotations(new_annos); return(result); }
public virtual void initHashCode(ATermList annos, AFun fun, ATerm[] i_args) { this.fun = fun; this.args = i_args; this.internSetAnnotations(annos); this.setHashCode(this.hashFunction()); }
public virtual ATermList getSlice(int start, int end) { int i, size = end - start; ATermList result = ((PureFactory)getFactory()).getEmpty(); ATermList list; ArrayList buffer = new ArrayList(size); list = this; for (i = 0; i < start; i++) { list = list.getNext(); } for (i = 0; i < size; i++) { buffer.Add(list.getFirst()); list = list.getNext(); } for (--i; i >= 0; i--) { result = result.insert((ATerm)buffer[i]); } return(result); }
public virtual ATermInt makeInt(int value, ATermList annos) { lock (protoInt) { protoInt.initHashCode(annos, value); return((ATermInt)build(protoInt)); } }
public virtual ATermAppl makeAppl(AFun fun, ATerm[] args, ATermList annos) { lock (protoAppl) { protoAppl.initHashCode(annos, fun, args); return((ATermAppl)build(protoAppl)); } }
public virtual ATermList makeList(ATerm first, ATermList next, ATermList annos) { lock (protoList) { protoList.initHashCode(annos, first, next); return((ATermList)build(protoList)); } }
public virtual ATermBlob makeBlob(byte[] data, ATermList annos) { lock (protoBlob) { protoBlob.init(hashBlob(annos, data), annos, data); return((ATermBlob)build(protoBlob)); } }
public virtual ATermPlaceholder makePlaceholder(ATerm type, ATermList annos) { lock (protoPlaceholder) { protoPlaceholder.init(hashPlaceholder(annos, type), annos, type); return((ATermPlaceholder)build(protoPlaceholder)); } }
public virtual ATermReal makeReal(double value, ATermList annos) { lock (protoReal) { protoReal.init(hashReal(annos, value), annos, value); return((ATermReal)build(protoReal)); } }
/** * Generate a list of consecutive numbers. */ private ATermList generateNumbers(int max) { ATermList numbers = factory.makeList(); for (int i = max; i > 0; i--) { numbers = factory.makeList(factory.makeInt(i), numbers); } return(numbers); }
public virtual ATermList getArguments() { ATermList result = ((PureFactory)getFactory()).getEmpty(); for (int i = args.Length - 1; i >= 0; i--) { result = result.insert(args[i]); } return(result); }
internal virtual void init(int hashCode, ATermList annos, AFun fun, ATerm[] i_args) { base.init(hashCode, annos); this.fun = fun; this.args = new ATerm[fun.getArity()]; for (int i = 0; i < fun.getArity(); i++) { this.args[i] = i_args[i]; } }
internal virtual void init(int hashCode, ATermList annos, AFun fun, ATerm[] i_args) { base.init(hashCode, annos); this.fun = fun; this.args = new ATerm[fun.getArity()]; for(int i=0; i<fun.getArity(); i++) { this.args[i] = i_args[i]; } }
private ATermList parseATerms(ATermReader reader) // throws IOException { ATerm[] terms = parseATermsArray(reader); ATermList result = empty; for (int i = terms.Length - 1; i >= 0; i--) { result = makeList(terms[i], result); } return(result); }
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); }
/** * Filter non-primes */ private ATermList filterNonPrimes(ATermList numbers) { ATermList primes = factory.makeList(); numbers = numbers.getNext(); while(!numbers.isEmpty()) { ATermInt prime = (ATermInt)numbers.getFirst(); numbers = filterMultiples(prime.getInt(), numbers); primes = primes.append(prime); } return factory.makeList(factory.makeInt(1), primes); }
internal override bool match(ATerm pattern, ArrayList list) { if (pattern.getType() == ATermType.LIST) { ATermList l = (ATermList)pattern; if (l.isEmpty()) { return(this.isEmpty()); } if (l.getFirst().getType() == ATermType.PLACEHOLDER) { ATerm ph_type = ((ATermPlaceholder)l.getFirst()).getPlaceholder(); if (ph_type.getType() == ATermType.APPL) { ATermAppl appl = (ATermAppl)ph_type; if (appl.getName().Equals("list") && appl.getArguments().isEmpty()) { list.Add(this); return(true); } } } if (!isEmpty()) { ArrayList submatches = first.match(l.getFirst()); if (submatches == null) { return(false); } list.AddRange(submatches); submatches = next.match(l.getNext()); if (submatches == null) { return(false); } list.AddRange(submatches); return(true); } else { return(l.isEmpty()); } } return(base.match(pattern, list)); }
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 virtual ATermList reverse() { ATermList cur = this; ATermList reverse = this.getEmpty(); while (!cur.isEmpty()) { reverse = reverse.insert(cur.getFirst()); cur = cur.getNext(); } return(reverse); }
public override void visitList(ATermList list) // throws VisitFailure { while (!list.isEmpty()) { visitChild(list.getFirst()); list = list.getNext(); if (!list.isEmpty()) { stream.Write(','); position++; } } }
/** * Filter non-primes */ private ATermList filterNonPrimes(ATermList numbers) { ATermList primes = factory.makeList(); numbers = numbers.getNext(); while (!numbers.isEmpty()) { ATermInt prime = (ATermInt)numbers.getFirst(); numbers = filterMultiples(prime.getInt(), numbers); primes = primes.append(prime); } return(factory.makeList(factory.makeInt(1), primes)); }
public PureFactory(int termTableSize) : base(termTableSize) { protoList = new ATermListImpl(this); protoAppl = new ATermApplImpl(this); protoInt = new ATermIntImpl(this); protoReal = new ATermRealImpl(this); protoBlob = new ATermBlobImpl(this); protoPlaceholder = new ATermPlaceholderImpl(this); protoAFun = new AFunImpl(this); protoList.init(42, null, null, null); empty = (ATermList) build(protoList); ((ATermListImpl) empty).init(42, empty, null, null); }
public PureFactory(int termTableSize) : base(termTableSize) { protoList = new ATermListImpl(this); protoAppl = new ATermApplImpl(this); protoInt = new ATermIntImpl(this); protoReal = new ATermRealImpl(this); protoBlob = new ATermBlobImpl(this); protoPlaceholder = new ATermPlaceholderImpl(this); protoAFun = new AFunImpl(this); protoList.init(42, null, null, null); empty = (ATermList)build(protoList); ((ATermListImpl)empty).init(42, empty, null, null); }
public virtual ATermList concat(ATermList rhs) { if (isEmpty()) { return(rhs); } if (next.isEmpty()) { return(rhs.insert(first)); } return(next.concat(rhs).insert(first)); }
/** * 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)); }
public virtual void visitChild(ATerm child) // throws VisitFailure { if (table != null) { int abbrev; if (table.Contains(child)) { abbrev = (int)table[child]; emitAbbrev(abbrev); return; } } int start = position; if (child.getType() == ATermType.LIST) { stream.Write('['); position++; } visit(child); if (child.getType() == ATermType.LIST) { stream.Write(']'); position++; } ATermList annos = child.getAnnotations(); if (!annos.isEmpty()) { stream.Write('{'); position++; visit(annos); stream.Write('}'); position++; } if (table != null) { int length = position - start; if (length > PureFactory.abbrevSize(next_abbrev)) { int key = next_abbrev++; // Or should this be ++next_abbrev?? (merijn) table.Add(key, child); } } }
public virtual ATermList removeAll(ATerm el) { if (first == el) { return(next.removeAll(el)); } ATermList result = next.removeAll(el); if (result == next) { return(this); } return(result.insert((ATerm)first)); }
/** * 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 ATerm elementAt(int index) { if (0 > index || index > length) { throw new ArgumentException("illegal list index: " + index); } ATermList cur = this; for (int i = 0; i < index; i++) { cur = cur.getNext(); } return(cur.getFirst()); }
public virtual ATerm dictGet(ATerm key) { if (isEmpty()) { return(null); } ATermList pair = (ATermList)first; if (key.equals(pair.getFirst())) { return(pair.getNext().getFirst()); } return(next.dictGet(key)); }
/** * 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(); } }
internal virtual ATermAppl make(AFun fun, ATerm[] i_args, ATermList annos) { return getPureFactory().makeAppl(fun, i_args, annos); }
public virtual void init(int hashCode, ATermList annos, ATerm type) { base.init(hashCode, annos); this.type = type; }
public override ATerm setAnnotations(ATermList annos) { return getPureFactory().makePlaceholder(type, annos); }
static private int hashBlob(ATermList annos, byte[] data) { return SharedObjects.HashFunctions.doobs(new Object[] { annos, data }); }
public virtual ATermPlaceholder makePlaceholder(ATerm type, ATermList annos) { lock (protoPlaceholder) { protoPlaceholder.init(hashPlaceholder(annos, type), annos, type); return (ATermPlaceholder) build(protoPlaceholder); } }
static private int hashPlaceholder(ATermList annos, ATerm type) { return SharedObjects.HashFunctions.doobs(new Object[] { annos, type }); }
public virtual ATermAppl makeApplList(AFun fun, ATermList list) { return makeApplList(fun, list, empty); }
public virtual ATermAppl makeAppl(AFun fun, ATerm[] args, ATermList annos) { lock (protoAppl) { protoAppl.initHashCode(annos, fun, args); return (ATermAppl) build(protoAppl); } }
public virtual ATermList makeList(ATerm first, ATermList next, ATermList annos) { lock (protoList) { protoList.initHashCode(annos, first, next); return (ATermList) build(protoList); } }
public virtual ATermList concat(ATermList rhs) { if (isEmpty()) { return rhs; } if (next.isEmpty()) { return rhs.insert(first); } return next.concat(rhs).insert(first); }
public virtual ATermReal makeReal(double value, ATermList annos) { lock (protoReal) { protoReal.init(hashReal(annos, value), annos, value); return (ATermReal) build(protoReal); } }
public virtual ATermList makeList(ATerm first, ATermList next) { return makeList(first, next, empty); }
public virtual ATermInt makeInt(int value, ATermList annos) { lock (protoInt) { protoInt.initHashCode(annos, value); return (ATermInt) build(protoInt); } }
public override ATerm setAnnotations(ATermList annos) { return getPureFactory().makeList(first, next, annos); }
public override ATerm setAnnotations(ATermList annos) { return getPureFactory().makeBlob(data, annos); }
public virtual ATermBlob makeBlob(byte[] data, ATermList annos) { lock (protoBlob) { protoBlob.init(hashBlob(annos, data), annos, data); return (ATermBlob) build(protoBlob); } }
public virtual void init(int hashCode, ATermList annos, byte[] data) { base.init(hashCode, annos); this.data = data; }
public void testMakeList() { ATerm[] T = new ATerm[10]; ATermList[] Ts = new ATermList[10]; //Console.Out.WriteLine("testing ATermList class"); T[0] = factory.parse("[0,1,2,3,4,5,4,3,2,1]"); Ts[0] = (ATermList)T[0]; T[1] = factory.parse("[]"); Ts[1] = factory.makeList(); T[2] = factory.parse("[1,2,3]"); Ts[2] = (ATermList)T[2]; T[3] = factory.parse("[4,5,6]"); Ts[3] = (ATermList)T[3]; T[4] = factory.parse("[1,2,3,4,5,6]"); Ts[4] = (ATermList)T[4]; // T[5] = factory.parse("[1 , 2 , 3 , 4,5,6,7]"); T[5] = factory.parse("[1,2,3,4,5,6,7]"); Ts[5] = (ATermList)T[5]; //T[6] = factory.parse("f(abc{[label,val]})"); // test length test(Ts[0].getLength() == 10, "length-1"); // test search test(Ts[0].indexOf(factory.makeInt(2), 0) == 2, "indexOf-1"); test(Ts[0].indexOf(factory.makeInt(10), 0) == -1, "indexOf-2"); test(Ts[0].indexOf(factory.makeInt(0), 0) == 0, "indexOf-3"); test(Ts[0].indexOf(factory.makeInt(5), 0) == 5, "indexOf-4"); // test lastIndexOf test(Ts[0].lastIndexOf(factory.makeInt(1), -1) == 9, "lastIndexOf-1"); test(Ts[0].lastIndexOf(factory.makeInt(0), -1) == 0, "lastIndexOf-2"); test(Ts[0].lastIndexOf(factory.makeInt(10), -1) == -1, "lastIndexOf-3"); // test concat test(Ts[2].concat(Ts[3]).Equals(Ts[4]), "concat-1"); test(Ts[0].concat(Ts[1]).Equals(Ts[0]), "concat-2"); // test append test(Ts[4].append(factory.makeInt(7)).Equals(Ts[5]), "append-1"); // test insert Ts[7] = Ts[3].insert(factory.parse("3")); Ts[7] = Ts[7].insert(factory.parse("2")); Ts[7] = Ts[7].insert(factory.parse("1")); test(Ts[7].Equals(Ts[4]), "insert-1"); test(Ts[1].insert(factory.parse("1")).Equals(factory.parse("[1]")), "insert-2"); test(Ts[4].insertAt(factory.parse("7"), Ts[4].getLength()).Equals(Ts[5]), "insert-3"); // Test prefix/last test(Ts[5].getPrefix().Equals(Ts[4]), "prefix-1"); test(Ts[5].getLast().Equals(factory.parse("7")), "last-1"); Console.Out.WriteLine("pass: testMakeList"); }
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); }
static private int hashReal(ATermList annos, double value) { return SharedObjects.HashFunctions.doobs(new Object[] { annos, value}); }
public virtual ATermList getPrefix() { ATermList cur, next; ArrayList elems; if (isEmpty()) { return this; } cur = this; elems = new ArrayList(); while (true) { next = cur.getNext(); if (next.isEmpty()) { cur = ((PureFactory) getFactory()).getEmpty(); for (int i = elems.Count - 1; i >= 0; i--) { cur = cur.insert((ATerm) elems[i]); } return cur; } else { elems.Add(cur.getFirst()); cur = cur.getNext(); } } }