Permalink
Browse files

Improved naming and organized a bit

  • Loading branch information...
1 parent 4476cd3 commit 58b642a6c80ee4caae15f0c3687719235f7d6bbc Darrick Wiebe committed Aug 27, 2012
Showing with 40 additions and 36 deletions.
  1. +29 −23 src/pacer/graph.clj
  2. +11 −13 src/pacer/step.clj
View
@@ -8,7 +8,7 @@
))
(:use [clojure.pprint :only [pprint]]
[clojure.string :only [join]]
- pacer.step))
+ [pacer.step :only [defstep]]))
(defprotocol PacerGraph
(create-vertex [graph])
@@ -30,24 +30,44 @@
(encode [graph value] ((:encode encoder) value))
(decode [graph value] ((:decode encoder) value)))
+
+
+(defstep IteratorPipe [source-type type name iterator]
+ pacer.step/BuildIterator
+ (iterator [s in] (iterator s in)))
+
+(defstep EdgeStep [source-type type name labels pipe-fn]
+ pacer.step/BuildPipe
+ (build-pipe [step in] (pipe-fn step in)))
+
+(defstep SimpleStep [source-type type name pipe-fn]
+ pacer.step/BuildPipe
+ (build-pipe [step in] (pipe-fn step in)))
+
+(defmacro edge-step [type name labels pipe]
+ `(EdgeStep. :vertex ~type (name+ ~name ~labels) ~labels
+ (fn pipe [step# in#] (new ~pipe (strs ~labels)))))
+
+(defmacro step [source-type type name pipe]
+ `(SimpleStep. ~source-type ~type ~name
+ (fn pipe [step# in#] (new ~pipe))))
+
+
+
(defn tg []
(Graph. "TinkerGraph"
(atom (com.tinkerpop.blueprints.impls.tg.TinkerGraph.))
(atom (pacer/simple-encoder))))
-(step-type GraphSourced [source-type type name iterator]
- IteratorStep
- (iterator [s in] (iterator s in)))
-
(defn v []
- (GraphSourced. :graph :vertex "V"
- (fn iterator [source]
+ (IteratorPipe. :graph :vertex "V"
+ (fn iterator [step source]
(.. @(:raw-graph source) getVertices iterator))))
(defn e []
- (GraphSourced. :graph :edge "E"
- (fn iterator [source]
+ (IteratorPipe. :graph :edge "E"
+ (fn iterator [step source]
(.. @(:raw-graph source) getEdges iterator))))
(defn- name+ [name labels]
@@ -58,13 +78,6 @@
(defn- strs [args]
(into-array String (map str args)))
-(step-type EdgeStep [source-type type name labels pipe-fn]
- PipeStep
- (build-pipe [step in] (pipe-fn step in)))
-
-(defmacro edge-step [type name labels pipe]
- `(EdgeStep. :vertex ~type (name+ ~name ~labels) ~labels
- (fn pipe [in#] (new ~pipe (strs ~labels)))))
(defn out-e [& labels]
(edge-step :edge "OutE" labels OutEdgesPipe))
@@ -84,13 +97,6 @@
(defn both [& labels]
(edge-step :vertex "Both" labels BothPipe))
-(step-type SimpleStep [source-type type name pipe-fn]
- PipeStep
- (build-pipe [step in] (pipe-fn step in)))
-
-(defmacro step [source-type type name pipe]
- `(SimpleStep. ~source-type ~type ~name
- (fn pipe [in#] (new ~pipe))))
(defn out-v []
(step :edge :vertex "OutV" OutVertexPipe))
View
@@ -9,29 +9,27 @@
(defn check-step [step in]
(when-let [rule (:source-type step)]
- (let [type (:type in :unspecified)
- check-fn (if (fn? rule)
- rule
- (fn [in] ((if (set? rule) rule (set [rule])) type)))]
- (when-not (check-fn in)
- (throw (Exception. (str "Step \"" step "\" expects type " rule " but got " type " from " in)))))))
+ (let [type (:type in :unspecified)
+ check-fn (if (fn? rule)
+ rule
+ (fn [in] ((if (set? rule) rule (set [rule])) type)))]
+ (when-not (check-fn in)
+ (throw (Exception. (str "Step \"" step "\" expects type " rule " but got " type " from " in)))))))
; Signature of check and pipe are the reverse of reducer fns...
-(defprotocol PacerStep
+(defprotocol Step
(check [step in]))
-(defprotocol IteratorStep
+(defprotocol BuildIterator
(iterator [step in]))
-(defprotocol PipeStep
+(defprotocol BuildPipe
(build-pipe [step in]))
-(declare check-step)
-
-(defmacro step-type [name args & forms]
+(defmacro defstep [name args & forms]
`(defrecord ~name ~args
Object
(toString [step#] (show-step step#))
- PacerStep
+ Step
(check [step# in#] (check-step step# in#))
~@forms))

0 comments on commit 58b642a

Please sign in to comment.