Search in sources :

Example 1 with IntObjMap

use of suite.primitive.adt.map.IntObjMap 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;
}
Also used : IdentityKey(suite.adt.IdentityKey) HashMap(java.util.HashMap) Reference(suite.node.Reference) IntObjMap(suite.primitive.adt.map.IntObjMap) ArrayDeque(java.util.ArrayDeque) ArrayList(java.util.ArrayList) List(java.util.List) IntIntPair(suite.primitive.adt.pair.IntIntPair) HashSet(java.util.HashSet)

Example 2 with IntObjMap

use of suite.primitive.adt.map.IntObjMap in project suite by stupidsing.

the class IntOutlet method toListMap.

public <K> IntObjMap<IntsBuilder> toListMap(Int_Int valueFun) {
    IntObjMap<IntsBuilder> map = new IntObjMap<>();
    int c;
    while ((c = next()) != IntFunUtil.EMPTYVALUE) map.computeIfAbsent(c, k_ -> new IntsBuilder()).append(valueFun.apply(c));
    return map;
}
Also used : IntObjMap(suite.primitive.adt.map.IntObjMap) IntsBuilder(suite.primitive.Ints.IntsBuilder)

Aggregations

IntObjMap (suite.primitive.adt.map.IntObjMap)2 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 IdentityKey (suite.adt.IdentityKey)1 Reference (suite.node.Reference)1 IntsBuilder (suite.primitive.Ints.IntsBuilder)1 IntIntPair (suite.primitive.adt.pair.IntIntPair)1