Exemplo n.º 1
0
        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();
                }
            }
        }
Exemplo n.º 2
0
		public virtual void initHashCode(ATermList annos, int value) 
		{
			this.value = value;
			this.internSetAnnotations(annos);
			this.setHashCode(this.hashFunction());
			//super.init(hashCode, annos);
		}
Exemplo n.º 3
0
        public virtual ATerm setAnnotation(ATerm label, ATerm anno)
        {
            ATermList new_annos = annotations.dictPut(label, anno);
            ATerm     result    = setAnnotations(new_annos);

            return(result);
        }
Exemplo n.º 4
0
 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());
 }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
		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());
		}
Exemplo n.º 7
0
 public virtual void initHashCode(ATermList annos, int value)
 {
     this.value = value;
     this.internSetAnnotations(annos);
     this.setHashCode(this.hashFunction());
     //super.init(hashCode, annos);
 }
Exemplo n.º 8
0
 public virtual ATermInt makeInt(int value, ATermList annos)
 {
     lock (protoInt)
     {
         protoInt.initHashCode(annos, value);
         return((ATermInt)build(protoInt));
     }
 }
Exemplo n.º 9
0
 public virtual ATermAppl makeAppl(AFun fun, ATerm[] args, ATermList annos)
 {
     lock (protoAppl)
     {
         protoAppl.initHashCode(annos, fun, args);
         return((ATermAppl)build(protoAppl));
     }
 }
Exemplo n.º 10
0
 public virtual ATermList makeList(ATerm first, ATermList next, ATermList annos)
 {
     lock (protoList)
     {
         protoList.initHashCode(annos, first, next);
         return((ATermList)build(protoList));
     }
 }
Exemplo n.º 11
0
 public virtual ATermBlob makeBlob(byte[] data, ATermList annos)
 {
     lock (protoBlob)
     {
         protoBlob.init(hashBlob(annos, data), annos, data);
         return((ATermBlob)build(protoBlob));
     }
 }
Exemplo n.º 12
0
 public virtual ATermPlaceholder makePlaceholder(ATerm type, ATermList annos)
 {
     lock (protoPlaceholder)
     {
         protoPlaceholder.init(hashPlaceholder(annos, type), annos, type);
         return((ATermPlaceholder)build(protoPlaceholder));
     }
 }
Exemplo n.º 13
0
 public virtual ATermReal makeReal(double value, ATermList annos)
 {
     lock (protoReal)
     {
         protoReal.init(hashReal(annos, value), annos, value);
         return((ATermReal)build(protoReal));
     }
 }
Exemplo n.º 14
0
        /**
         * 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);
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        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];
            }
        }
Exemplo n.º 17
0
		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];
			}
		}
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
 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);
 }
Exemplo n.º 20
0
		/**
		 * 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);
		}
Exemplo n.º 21
0
        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));
        }
Exemplo n.º 22
0
        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);
        }
Exemplo n.º 23
0
        public virtual ATermList reverse()
        {
            ATermList cur     = this;
            ATermList reverse = this.getEmpty();

            while (!cur.isEmpty())
            {
                reverse = reverse.insert(cur.getFirst());
                cur     = cur.getNext();
            }
            return(reverse);
        }
Exemplo n.º 24
0
 public override void visitList(ATermList list)         // throws VisitFailure
 {
     while (!list.isEmpty())
     {
         visitChild(list.getFirst());
         list = list.getNext();
         if (!list.isEmpty())
         {
             stream.Write(',');
             position++;
         }
     }
 }
Exemplo n.º 25
0
        /**
         * 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));
        }
Exemplo n.º 26
0
		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);
		}
Exemplo n.º 27
0
        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);
        }
Exemplo n.º 28
0
        public virtual ATermList concat(ATermList rhs)
        {
            if (isEmpty())
            {
                return(rhs);
            }

            if (next.isEmpty())
            {
                return(rhs.insert(first));
            }

            return(next.concat(rhs).insert(first));
        }
Exemplo n.º 29
0
        /**
         * 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();
            }
        }
Exemplo n.º 30
0
		/**
		 * 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();
			}
		}
Exemplo n.º 31
0
        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));
        }
Exemplo n.º 32
0
        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);
                }
            }
        }
Exemplo n.º 33
0
        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));
        }
Exemplo n.º 34
0
        /**
         * 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);
        }
Exemplo n.º 35
0
        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());
        }
Exemplo n.º 36
0
        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));
        }
Exemplo n.º 37
0
		/**
		 * 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;
		}
Exemplo n.º 38
0
		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();
			}
		}
Exemplo n.º 39
0
		internal virtual ATermAppl make(AFun fun, ATerm[] i_args, ATermList annos) 
		{
			return getPureFactory().makeAppl(fun, i_args, annos);
		}
Exemplo n.º 40
0
		   public virtual void init(int hashCode, ATermList annos, ATerm type) 
		   {
			   base.init(hashCode, annos);
			   this.type = type;
		   }
Exemplo n.º 41
0
		   public override ATerm setAnnotations(ATermList annos) 
		   {
			   return getPureFactory().makePlaceholder(type, annos);
		   }
Exemplo n.º 42
0
		static private int hashBlob(ATermList annos, byte[] data) 
		{
			return SharedObjects.HashFunctions.doobs(new Object[] { annos, data });
		}
Exemplo n.º 43
0
		public virtual ATermPlaceholder makePlaceholder(ATerm type, ATermList annos) 
		{
			lock (protoPlaceholder) 
			{
				protoPlaceholder.init(hashPlaceholder(annos, type), annos, type);
				return (ATermPlaceholder) build(protoPlaceholder);
			}
		}
Exemplo n.º 44
0
		static private int hashPlaceholder(ATermList annos, ATerm type) 
		{
			return SharedObjects.HashFunctions.doobs(new Object[] { annos, type });
		}
Exemplo n.º 45
0
		public virtual ATermAppl makeApplList(AFun fun, ATermList list) 
		{
			return makeApplList(fun, list, empty);
		}
Exemplo n.º 46
0
		public virtual ATermAppl makeAppl(AFun fun, ATerm[] args, ATermList annos) 
		{
			lock (protoAppl) 
			{
				protoAppl.initHashCode(annos, fun, args);
				return (ATermAppl) build(protoAppl);
			}
		}
Exemplo n.º 47
0
		public virtual ATermList makeList(ATerm first, ATermList next, ATermList annos) 
		{
			lock (protoList) 
			{
				protoList.initHashCode(annos, first, next);
				return (ATermList) build(protoList);
			}
		}
Exemplo n.º 48
0
		public virtual ATermList concat(ATermList rhs) 
		{
			if (isEmpty()) 
			{
				return rhs;
			}

			if (next.isEmpty()) 
			{
				return rhs.insert(first);
			}

			return next.concat(rhs).insert(first);
		}
Exemplo n.º 49
0
		public virtual ATermReal makeReal(double value, ATermList annos) 
		{
			lock (protoReal) 
			{
				protoReal.init(hashReal(annos, value), annos, value);
				return (ATermReal) build(protoReal);
			}
		}
Exemplo n.º 50
0
		public virtual ATermList makeList(ATerm first, ATermList next) 
		{
			return makeList(first, next, empty);
		}
Exemplo n.º 51
0
		public virtual ATermInt makeInt(int value, ATermList annos) 
		{
			lock (protoInt) 
			{
				protoInt.initHashCode(annos, value);
				return (ATermInt) build(protoInt);
			}
		}
Exemplo n.º 52
0
		public override ATerm setAnnotations(ATermList annos) 
		{
			return getPureFactory().makeList(first, next, annos);
		}
Exemplo n.º 53
0
		public override ATerm setAnnotations(ATermList annos) 
		{
			return getPureFactory().makeBlob(data, annos);
		}
Exemplo n.º 54
0
		public virtual ATermBlob makeBlob(byte[] data, ATermList annos) 
		{
			lock (protoBlob) 
			{
				protoBlob.init(hashBlob(annos, data), annos, data);
				return (ATermBlob) build(protoBlob);
			}
		}
Exemplo n.º 55
0
		public virtual void init(int hashCode, ATermList annos, byte[] data) 
		{
			base.init(hashCode, annos);
			this.data = data;
		}
Exemplo n.º 56
0
		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");
		}
Exemplo n.º 57
0
		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);
		}
Exemplo n.º 58
0
		public override void visitList(ATermList list) // throws VisitFailure 
		{
			while (!list.isEmpty()) 
			{
				visitChild(list.getFirst());
				list = list.getNext();
				if (!list.isEmpty()) 
				{
					stream.Write(',');
					position++;
				}
			}
		}
Exemplo n.º 59
0
		static private int hashReal(ATermList annos, double value) 
		{
			return SharedObjects.HashFunctions.doobs(new Object[] { annos, value});
		}
Exemplo n.º 60
0
		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();
				}
			}
		}