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);
}
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));
}
}
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);
}
}
}
}
Aggregations