Search in sources :

Example 11 with IntIntPair

use of suite.primitive.adt.pair.IntIntPair in project suite by stupidsing.

the class IntIntMap method forEach.

public void forEach(IntIntSink sink) {
    IntIntPair pair = IntIntPair.of((int) 0, (int) 0);
    IntIntSource source = source_();
    while (source.source2(pair)) sink.sink2(pair.t0, pair.t1);
}
Also used : IntIntSource(suite.primitive.IntIntSource) IntIntPair(suite.primitive.adt.pair.IntIntPair)

Example 12 with IntIntPair

use of suite.primitive.adt.pair.IntIntPair 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 13 with IntIntPair

use of suite.primitive.adt.pair.IntIntPair 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

IntIntPair (suite.primitive.adt.pair.IntIntPair)13 ArrayList (java.util.ArrayList)5 List (java.util.List)5 ArrayDeque (java.util.ArrayDeque)4 HashSet (java.util.HashSet)4 Reference (suite.node.Reference)4 IntIntSource (suite.primitive.IntIntSource)4 Deque (java.util.Deque)3 HashMap (java.util.HashMap)3 IdentityKey (suite.adt.IdentityKey)3 Pair (suite.adt.pair.Pair)3 IntObjMap (suite.primitive.adt.map.IntObjMap)3 Read (suite.streamlet.Read)3 Fail (suite.util.Fail)3 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 IOException (java.io.IOException)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Objects (java.util.Objects)2