Search in sources :

Example 1 with ReadType

use of suite.node.io.Rewrite_.ReadType in project suite by stupidsing.

the class Grapher method load.

public void load(DataInputStream dis) throws IOException {
    int size = dis.readInt();
    id = dis.readInt();
    for (int index = 0; index < size; index++) {
        ReadType type = ReadType.of(dis.readByte());
        Node terminal;
        Operator op;
        List<IntIntPair> children = new ArrayList<>();
        if (type == ReadType.TERM) {
            char ch = (char) dis.readByte();
            switch(ch) {
                case 'a':
                    terminal = Atom.of(dis.readUTF());
                    break;
                case 'i':
                    terminal = Int.of(dis.readInt());
                    break;
                case 'r':
                    terminal = new Reference();
                    break;
                case 's':
                    terminal = new Str(dis.readUTF());
                    break;
                default:
                    terminal = Fail.t("unknown type " + ch);
            }
        } else
            terminal = null;
        if (type == ReadType.TREE) {
            op = TermOp.find(dis.readUTF());
            children.add(IntIntPair.of(0, dis.readInt() + index));
            children.add(IntIntPair.of(0, dis.readInt() + index));
        } else
            op = null;
        if (type == ReadType.DICT || type == ReadType.TUPLE) {
            int size1 = dis.readInt();
            for (int i = 0; i < size1; i++) {
                int i0 = type != ReadType.DICT ? 0 : dis.readInt() + index;
                int i1 = dis.readInt() + index;
                children.add(IntIntPair.of(i0, i1));
            }
        }
        gns.add(new GN(type, terminal, op, children));
    }
}
Also used : Str(suite.node.Str) ReadType(suite.node.io.Rewrite_.ReadType) Reference(suite.node.Reference) Node(suite.node.Node) ArrayList(java.util.ArrayList) IntIntPair(suite.primitive.adt.pair.IntIntPair)

Example 2 with ReadType

use of suite.node.io.Rewrite_.ReadType in project suite by stupidsing.

the class Grapher method save.

public void save(DataOutputStream dos) throws IOException {
    int size = gns.size();
    dos.writeInt(size);
    dos.writeInt(id);
    for (int index = 0; index < size; index++) {
        GN gn = gns.get(index);
        ReadType type = gn.type;
        List<IntIntPair> children = gn.children;
        dos.writeByte(type.value);
        if (type == ReadType.TERM)
            new // 
            SwitchNode<Node>(// 
            gn.terminal).doIf(Atom.class, n -> {
                dos.writeByte((byte) 'a');
                dos.writeUTF(n.name);
            }).doIf(Int.class, n -> {
                dos.writeByte((byte) 'i');
                dos.writeInt(n.number);
            }).doIf(Reference.class, n -> {
                dos.writeByte((byte) 'r');
            }).doIf(Str.class, n -> {
                dos.writeByte((byte) 's');
                dos.writeUTF(n.value);
            }).nonNullResult();
        else if (type == ReadType.TREE) {
            dos.writeUTF(gn.op.getName());
            dos.writeInt(children.get(0).t1 - index);
            dos.writeInt(children.get(1).t1 - index);
        } else if (type == ReadType.DICT || type == ReadType.TUPLE) {
            dos.writeInt(children.size());
            for (IntIntPair child : children) {
                if (type == ReadType.DICT)
                    dos.writeInt(child.t0 - index);
                dos.writeInt(child.t1 - index);
            }
        }
    }
}
Also used : DataInputStream(java.io.DataInputStream) Read(suite.streamlet.Read) HashMap(java.util.HashMap) Deque(java.util.Deque) ArrayList(java.util.ArrayList) Node(suite.node.Node) HashSet(java.util.HashSet) ProverConstant(suite.lp.doer.ProverConstant) DataOutputStream(java.io.DataOutputStream) Map(java.util.Map) IdentityKey(suite.adt.IdentityKey) Binder(suite.lp.doer.Binder) Tuple(suite.node.Tuple) Dict(suite.node.Dict) Reference(suite.node.Reference) Trail(suite.lp.Trail) IntIntPair(suite.primitive.adt.pair.IntIntPair) Set(java.util.Set) IOException(java.io.IOException) NodeRead(suite.node.io.Rewrite_.NodeRead) NodeHead(suite.node.io.Rewrite_.NodeHead) IntObjMap(suite.primitive.adt.map.IntObjMap) Tree(suite.node.Tree) Objects(java.util.Objects) Pair(suite.adt.pair.Pair) List(java.util.List) Atom(suite.node.Atom) Entry(java.util.Map.Entry) As(suite.streamlet.As) ArrayDeque(java.util.ArrayDeque) Int(suite.node.Int) Fail(suite.util.Fail) Str(suite.node.Str) ReadType(suite.node.io.Rewrite_.ReadType) ReadType(suite.node.io.Rewrite_.ReadType) Reference(suite.node.Reference) Atom(suite.node.Atom) IntIntPair(suite.primitive.adt.pair.IntIntPair)

Aggregations

ArrayList (java.util.ArrayList)2 Node (suite.node.Node)2 Reference (suite.node.Reference)2 Str (suite.node.Str)2 ReadType (suite.node.io.Rewrite_.ReadType)2 IntIntPair (suite.primitive.adt.pair.IntIntPair)2 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 ArrayDeque (java.util.ArrayDeque)1 Deque (java.util.Deque)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 Set (java.util.Set)1 IdentityKey (suite.adt.IdentityKey)1 Pair (suite.adt.pair.Pair)1