public static Set<MemoryComputeKey> getMemoryComputeKeys(final Traversal.Admin<?, ?> traversal) {
        final Set<MemoryComputeKey> keys = new HashSet<>();
        final TraversalSideEffects sideEffects =
                traversal.getSideEffects() instanceof MemoryTraversalSideEffects ?
                        ((MemoryTraversalSideEffects) traversal.getSideEffects()).sideEffects :
                        traversal.getSideEffects();
        sideEffects.keys().
                stream().
                forEach(key -> keys.add(MemoryComputeKey.of(key, sideEffects.getReducer(key), true, false)));
        return keys;
    }
@author Marko A. Rodriguez (http://markorodriguez.com)
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/MemoryTraversalSideEffects.java