use of suite.adt.IdentityKey in project suite by stupidsing.
the class LazyIbTreeExtentFilePersister method save_.
private Extent save_(List<Slot<T>> slots) {
IdentityKey<List<Slot<T>>> key = IdentityKey.of(slots);
Extent extent = slotsByExtent.inverse().get(key);
if (extent == null) {
List<Pair<T, Extent>> pairs = //
Read.from(//
slots).map(//
slot -> Pair.of(slot.pivot, save_(slot.readSlots()))).toList();
slotsByExtent.put(extent = saveSlot(nPages, new PersistSlot<>(pairs)), key);
nPages = extent.end;
}
return extent;
}
use of suite.adt.IdentityKey in project suite by stupidsing.
the class InstructionExtractor method extractInstructions.
private void extractInstructions(Node snippet, List<List<Node>> rsList) {
Deque<Node> deque = new ArrayDeque<>();
deque.add(snippet);
Tree tree;
Node value;
while (!deque.isEmpty()) if ((tree = Tree.decompose(deque.pop(), TermOp.AND___)) != null) {
IdentityKey<Node> key = IdentityKey.of(tree);
Integer ip = ipByLabelId.get(key);
if (ip == null) {
ipByLabelId.put(key, ip = rsList.size());
List<Node> rs = tupleToList(tree.getLeft());
if (rs.get(0) == FRAME)
if ((value = label(rs.get(1))) != null) {
rsList.add(List.of(Atom.of("FRAME-BEGIN")));
extractInstructions(value, rsList);
rsList.add(List.of(Atom.of("FRAME-END")));
} else
Fail.t("bad frame definition");
else {
rsList.add(rs);
for (Node op : List_.right(rs, 1)) if ((value = label(op)) != null)
deque.push(value);
deque.push(tree.getRight());
}
} else
rsList.add(List.of(Atom.of("JUMP"), Int.of(ip)));
}
}
use of suite.adt.IdentityKey in project suite by stupidsing.
the class Grapher method graph_.
private int graph_(Map<IdentityKey<Node>, Integer> ids, Node node) {
IdentityKey<Node> key = IdentityKey.of(node);
Integer id = ids.get(key);
if (id == null) {
ids.put(key, id = gns.size());
gns.add(null);
NodeRead nr = NodeRead.of(node);
List<IntIntPair> children = //
Read.from(//
nr.children).map(//
p -> IntIntPair.of(graph_(ids, p.t0), graph_(ids, p.t1))).toList();
gns.set(id, new GN(nr.type, nr.terminal, nr.op, children));
}
return id;
}
use of suite.adt.IdentityKey in project suite by stupidsing.
the class Grapher method bind.
public static boolean bind(Node n0, Node n1, Trail trail) {
Map<IdentityKey<Node>, Integer> mapn0 = new HashMap<>();
Map<IdentityKey<Node>, Integer> mapn1 = new HashMap<>();
Grapher g0 = new Grapher();
Grapher g1 = new Grapher();
g0.id = g0.graph_(mapn0, n0);
g1.id = g1.graph_(mapn1, n1);
IntObjMap<IdentityKey<Node>> mapi0 = new IntObjMap<>();
IntObjMap<IdentityKey<Node>> mapi1 = new IntObjMap<>();
for (Entry<IdentityKey<Node>, Integer> e : mapn0.entrySet()) mapi0.put(e.getValue(), e.getKey());
for (Entry<IdentityKey<Node>, Integer> e : mapn1.entrySet()) mapi1.put(e.getValue(), e.getKey());
Set<IntIntPair> set = new HashSet<>();
Deque<IntIntPair> deque = new ArrayDeque<>();
deque.add(IntIntPair.of(g0.id, g1.id));
IntIntPair pair;
while ((pair = deque.pollLast()) != null) if (set.add(pair)) {
GN gn0 = g0.gns.get(pair.t0);
GN gn1 = g1.gns.get(pair.t1);
if (//
gn0.type == ReadType.TERM && //
gn0.terminal instanceof Reference && Binder.bind(gn0.terminal, mapi1.get(pair.t1).key, trail))
;
else if (//
gn1.type == ReadType.TERM && //
gn1.terminal instanceof Reference && Binder.bind(gn1.terminal, mapi0.get(pair.t0).key, trail))
;
else if (gn0.type == gn1.type && Objects.equals(gn0.terminal, gn1.terminal) && gn0.op == gn1.op) {
List<IntIntPair> children0 = gn0.children;
List<IntIntPair> children1 = gn1.children;
int size0 = children0.size();
int size1 = children1.size();
if (size0 == size1)
for (int i = 0; i < size0; i++) {
IntIntPair p0 = children0.get(i);
IntIntPair p1 = children1.get(i);
deque.addLast(IntIntPair.of(p0.t0, p1.t0));
deque.addLast(IntIntPair.of(p0.t1, p1.t1));
}
else
return false;
} else
return false;
}
return true;
}
use of suite.adt.IdentityKey in project suite by stupidsing.
the class AutoObject method clone.
@Override
public AutoObject<T> clone() {
Map<IdentityKey<?>, AutoObject<?>> map = new HashMap<>();
class Clone {
private AutoObject<?> clone(AutoObject<?> t0) throws IllegalAccessException {
IdentityKey<?> key = IdentityKey.of(t0);
AutoObject<?> tx = map.get(key);
if (tx == null) {
map.put(key, tx = Object_.new_(t0.getClass()));
@SuppressWarnings("unchecked") AutoObject<T> t1 = (AutoObject<T>) tx;
for (Field field : t0.fields_()) {
Object v0 = field.get(t0);
Object v1 = v0 instanceof AutoObject ? clone((AutoObject<?>) v0) : v0;
field.set(t1, v1);
}
}
return tx;
}
}
return Rethrow.ex(() -> {
@SuppressWarnings("unchecked") AutoObject<T> object = (AutoObject<T>) new Clone().clone(this);
return object;
});
}
Aggregations