Search in sources :

Example 1 with IdentityKey

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;
}
Also used : SerializedFileFactory(suite.file.impl.SerializedFileFactory) PageFile(suite.file.PageFile) Read(suite.streamlet.Read) DataInput_(suite.util.DataInput_) DataOutput_(suite.util.DataOutput_) HashMap(java.util.HashMap) HashSet(java.util.HashSet) ExtentFile(suite.file.ExtentFile) Rethrow(suite.util.Rethrow) Map(java.util.Map) IdentityKey(suite.adt.IdentityKey) SerializedPageFile(suite.file.SerializedPageFile) FileFactory(suite.file.impl.FileFactory) Serializer(suite.util.Serialize.Serializer) Slot(suite.immutable.LazyIbTree.Slot) Set(java.util.Set) Bytes(suite.primitive.Bytes) IOException(java.io.IOException) HashBiMap(suite.adt.map.HashBiMap) To(suite.util.To) Serialize(suite.util.Serialize) Pair(suite.adt.pair.Pair) Friends.max(suite.util.Friends.max) List(java.util.List) BiMap(suite.adt.map.BiMap) Extent(suite.file.ExtentAllocator.Extent) Sink(suite.util.FunUtil.Sink) As(suite.streamlet.As) Comparator(java.util.Comparator) Extent(suite.file.ExtentAllocator.Extent) List(java.util.List) Pair(suite.adt.pair.Pair)

Example 2 with IdentityKey

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)));
    }
}
Also used : IdentityKey(suite.adt.IdentityKey) Node(suite.node.Node) Tree(suite.node.Tree) ArrayList(java.util.ArrayList) List(java.util.List) ArrayDeque(java.util.ArrayDeque)

Example 3 with IdentityKey

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;
}
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) NodeRead(suite.node.io.Rewrite_.NodeRead) Node(suite.node.Node) IntIntPair(suite.primitive.adt.pair.IntIntPair)

Example 4 with IdentityKey

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;
}
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 5 with IdentityKey

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;
    });
}
Also used : Field(java.lang.reflect.Field) IdentityKey(suite.adt.IdentityKey) HashMap(java.util.HashMap)

Aggregations

IdentityKey (suite.adt.IdentityKey)5 HashMap (java.util.HashMap)4 List (java.util.List)4 ArrayDeque (java.util.ArrayDeque)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 IOException (java.io.IOException)2 Map (java.util.Map)2 Set (java.util.Set)2 Pair (suite.adt.pair.Pair)2 Node (suite.node.Node)2 Reference (suite.node.Reference)2 Tree (suite.node.Tree)2 IntObjMap (suite.primitive.adt.map.IntObjMap)2 IntIntPair (suite.primitive.adt.pair.IntIntPair)2 As (suite.streamlet.As)2 Read (suite.streamlet.Read)2 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 Field (java.lang.reflect.Field)1